提交时间:2026-02-05 15:42:40

运行 ID: 84006

#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int M, S, T; cin >> M >> S >> T; // dp[m] 表示当前剩余魔法值 m 时的最大移动距离 vector<int> dp(M + 1, -1); dp[M] = 0; // 初始状态:时间0,魔法M,距离0 int max_distance = 0; bool escaped = false; int result_time = T; for (int t = 1; t <= T; ++t) { vector<int> new_dp(M + 1, -1); for (int m = 0; m <= M; ++m) { if (dp[m] == -1) continue; // 当前状态不可达 // 跑步 if (new_dp[m] < dp[m] + 17) { new_dp[m] = dp[m] + 17; } // 闪烁(如果魔法足够) if (m >= 10) { if (new_dp[m - 10] < dp[m] + 60) { new_dp[m - 10] = dp[m] + 60; } } // 休息(魔法恢复) int new_m = min(m + 4, M); if (new_dp[new_m] < dp[m]) { new_dp[new_m] = dp[m]; } } dp = move(new_dp); // 更新状态 // 检查当前时间是否能逃离 int current_max = 0; for (int m = 0; m <= M; ++m) { if (dp[m] > current_max) { current_max = dp[m]; } } if (current_max >= S) { escaped = true; result_time = t; break; } if (current_max > max_distance) { max_distance = current_max; } } if (escaped) { cout << "Yes" << endl; cout << result_time << endl; } else { cout << "No" << endl; cout << max_distance << endl; } return 0; }