Submission #141061

#TimeUsernameProblemLanguageResultExecution timeMemory
141061meatrowXylophone (JOI18_xylophone)C++17
100 / 100
87 ms680 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") //#pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> #include "xylophone.h" using namespace std; using ll = long long; using ld = long double; const int N = 5001; map<int, int> used; int a[N]; void solve(int n) { int l = 1, r = n; while (l + 1 < r) { int mid = (l + r) / 2; int t = query(1, mid); if (t == n - 1) { r = mid; } else { l = mid; } } a[r] = n; for (int i = r + 1; i <= n; i++) { used[a[i - 1]] = 1; int t = query(i - 1, i); if (a[i - 1] + t > n || used.count(a[i - 1] + t)) { a[i] = a[i - 1] - t; continue; } if (a[i - 1] - t < 1 || used.count(a[i - 1] - t)) { a[i] = a[i - 1] + t; continue; } int u = query(i - 2, i); if (u == abs(a[i - 2] - a[i - 1])) { if (a[i - 2] < a[i - 1]) { a[i] = a[i - 1] - t; } else { a[i] = a[i - 1] + t; } continue; } if (u != t) { int cand = a[i - 2] + u; if (cand == a[i - 1] - t || cand == a[i - 1] + t) { a[i] = cand; } else { a[i] = cand - 2 * u; } continue; } if (a[i - 2] < a[i - 1]) { a[i] = a[i - 1] - t; } else { a[i] = a[i - 1] + t; } } for (int i = r - 1; i >= 1; i--) { used[a[i + 1]] = 1; int t = query(i, i + 1); if (a[i + 1] + t > n || used.count(a[i + 1] + t)) { a[i] = a[i + 1] - t; continue; } if (a[i + 1] - t < 1 || used.count(a[i + 1] - t)) { a[i] = a[i + 1] + t; continue; } int u = query(i, i + 2); if (u == abs(a[i + 2] - a[i + 1])) { if (a[i + 2] < a[i + 1]) { a[i] = a[i + 1] - t; } else { a[i] = a[i + 1] + t; } continue; } if (u != t) { int cand = a[i + 2] + u; if (cand == a[i + 1] - t || cand == a[i + 1] + t) { a[i] = cand; } else { a[i] = cand - 2 * u; } continue; } if (a[i + 2] < a[i + 1]) { a[i] = a[i + 1] - t; } else { a[i] = a[i + 1] + t; } } for (int i = 1; i <= n; i++) { answer(i, a[i]); } } /*int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...