Submission #244884

#TimeUsernameProblemLanguageResultExecution timeMemory
244884rama_pangCollecting Stamps 3 (JOI20_ho_t3)C++14
25 / 100
2057 ms147928 KiB
#include <bits/stdc++.h> using namespace std; using lint = long long; const int MAXN = 205; int N, L; int X[MAXN], T[MAXN]; lint dist[MAXN][MAXN][2][MAXN]; struct State { int left; int right; int pos_right; int stamps; State() {} State(int l, int r, int p, int s) : left(l), right(r), pos_right(p), stamps(s) {} bool operator < (const State &o) const { return stamps < o.stamps; } }; int Distance(int a, int b) { if (a > b) swap(a, b); return min(X[b] - X[a], X[a] + L - X[b]); } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); memset(dist, -1, sizeof(dist)); cin >> N >> L; for (int i = 1; i <= N; i++) { cin >> X[i]; } X[N + 1] = L; for (int i = 1; i <= N; i++) { cin >> T[i]; } priority_queue<pair<lint, State>, vector<pair<lint, State>>, greater<pair<lint, State>>> pq; pq.emplace(0, State(0, N + 1, 0, 0)); dist[0][N + 1][0][0] = 0; int ans = 0; while (!pq.empty()) { int left = pq.top().second.left; int right = pq.top().second.right; int pos_right = pq.top().second.pos_right; int stamps = pq.top().second.stamps; lint dt = pq.top().first; pq.pop(); ans = max(ans, stamps); if (left > right || dist[left][right][pos_right][stamps] != dt) { continue; } int cur = pos_right ? right : left; if (left + 1 < right) { lint &nxt = dist[left + 1][right][0][stamps + (dt + Distance(left + 1, cur) <= T[left + 1])]; if (nxt == -1 || nxt > dt + Distance(left + 1, cur)) { nxt = dt + Distance(left + 1, cur); pq.emplace(nxt, State(left + 1, right, 0, stamps + (dt + Distance(left + 1, cur) <= T[left + 1]))); } } if (left < right - 1) { lint &nxt = dist[left][right - 1][1][stamps + (dt + Distance(right - 1, cur) <= T[right - 1])]; if (nxt == -1 || nxt > dt + Distance(right - 1, cur)) { nxt = dt + Distance(right - 1, cur); pq.emplace(nxt, State(left, right - 1, 1, stamps + (dt + Distance(right - 1, cur) <= T[right - 1]))); } } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...