UBS-Server / routes /kazuma.py
m-abdur2024's picture
Upload 40 files
0d3476b verified
raw
history blame
No virus
2.02 kB
import json
import logging
from flask import request, jsonify
from routes import app
logger = logging.getLogger(__name__)
@app.route('/efficient-hunter-kazuma', methods=['POST'])
def efficient_hunter_kazuma():
data = request.get_json()
logging.info("Data received for evaluation: {}".format(data))
results = []
for test_case in data:
monsters = test_case.get("monsters", [])
n = len(monsters)
dp_no_circle = [0] * (n + 2) # State when Kazuma has no circle prepared
dp_have_circle = [0] * (n + 2) # State when Kazuma has a circle prepared
# Iterate from the end to the beginning
for t in range(n - 1, -1, -1):
# State when Kazuma has no circle prepared
# Option 1: Skip and move to the next time frame without a circle
option1 = dp_no_circle[t + 1]
# Option 2: Prepare a circle now, pay the protection cost, and move to the next time frame with a circle
option2 = -monsters[t] + dp_have_circle[t + 1]
dp_no_circle[t] = max(option1, option2)
# State when Kazuma has a circle prepared
# Option 1: Attack now, earn gold from monsters at time t, and move to the next time frame after recovery without a circle
if t + 2 < len(dp_no_circle):
option1 = monsters[t] + dp_no_circle[t + 2]
else:
option1 = monsters[t]
# Option 2: Wait (move to rear), stay in the same state with a circle prepared
option2 = dp_have_circle[t + 1]
dp_have_circle[t] = max(option1, option2)
logging.debug(
f"Time {t}: dp_no_circle[{t}] = {dp_no_circle[t]}, dp_have_circle[{t}] = {dp_have_circle[t]}"
)
max_efficiency = dp_no_circle[0]
results.append({"efficiency": max_efficiency})
logging.info("Computed efficiency: {}".format(max_efficiency))
return jsonify(results)