Submission #1129121

#TimeUsernameProblemLanguageResultExecution timeMemory
1129121not_amirXylophone (JOI18_xylophone)C++20
100 / 100
39 ms436 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; static int A[5000]; void solve(int N) { vector<int> val(N); for (int i = 1; i < N; i++) { val[i] = query(i, i + 1); } vector<bool> dir(N); for (int i = 1; i < N - 1; i++) { int x = query(i, i + 2); if (val[i] + val[i + 1] == x) dir[i + 1] = dir[i]; else dir[i + 1] = !dir[i]; } vector<int> sum(N); int minv = 0, idxmin = 0; int maxv = 0, idxmax = 0; for (int i = 1; i < N; i++) { if (dir[i]) sum[i] = sum[i - 1] + val[i]; else sum[i] = sum[i - 1] - val[i]; if (sum[i] < minv) minv = sum[i], idxmin = i; if (sum[i] > maxv) maxv = sum[i], idxmax = i; } if (idxmin > idxmax) { minv = -maxv; for (int i = 0; i < N; i++) sum[i] *= -1; } for (int i = 0; i < N; i++) answer(i + 1, sum[i] - minv + 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...