Submission #915130

#TimeUsernameProblemLanguageResultExecution timeMemory
915130OAleksaXylophone (JOI18_xylophone)C++14
100 / 100
33 ms1212 KiB
#include "xylophone.h" #include<bits/stdc++.h> using namespace std; const int MAXN = 5069; int ans[MAXN], vis[MAXN]; void solve(int N) { int n = N; int l = 2, r = n, mx = 2; while (l <= r) { int mid = (l + r) / 2; if (query(1, mid) == n - 1) { mx = mid; r = mid - 1; } else l = mid + 1; } ans[mx] = n; vis[n] = 1; if (mx < n) { int x = query(mx, mx + 1); ans[mx + 1] = n - x; vis[n - x] = 1; } int x = query(mx - 1, mx); ans[mx - 1] = n - x; vis[n - x] = 1; for (int i = mx - 2;i >= 1;i--) { int x = query(i, i + 1); int v1 = ans[i + 1] - x; int v2 = ans[i + 1] + x; if (v1 < 1 || vis[v1]) ans[i] = v2; else if (v2 > n || vis[v2]) ans[i] = v1; else { int y = query(i, i + 2); if (y == abs(ans[i + 2] - ans[i + 1]) || y == x) { if (ans[i + 2] > ans[i + 1]) ans[i] = v2; else ans[i] = v1; } else { if (ans[i + 2] > ans[i + 1]) ans[i] = v1; else ans[i] = v2; } } vis[ans[i]] = 1; } for (int i = mx + 2;i <= n;i++) { int x = query(i - 1, i); int v1 = ans[i - 1] - x; int v2 = ans[i - 1] + x; if (v1 < 1 || vis[v1]) ans[i] = v2; else if (v2 > n || vis[v2]) ans[i] = v1; else { int y = query(i - 2, i); if (y == abs(ans[i - 2] - ans[i - 1]) || y == x) { if (ans[i - 2] > ans[i - 1]) ans[i] = v2; else ans[i] = v1; } else { if (ans[i - 2] > ans[i - 1]) ans[i] = v1; else ans[i] = v2; } } vis[ans[i]] = 1; } for(int i = 1; i <= n; i++) { answer(i, ans[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...