Submission #915091

#TimeUsernameProblemLanguageResultExecution timeMemory
915091OAleksaXylophone (JOI18_xylophone)C++14
0 / 100
1 ms592 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 = 1, r = n, mx = -1; while (l <= r) { int mid = (l + r) / 2; if (query(1, mid) == n - 1) { mx = mid; r = mid - 1; } else l = mid + 1; } assert(mx != -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; } if (mx > 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); if (ans[i + 1] + x > n || vis[ans[i + 1] + x]) { ans[i] = ans[i + 1] - x; vis[ans[i + 1] - x] = 1; } else if (ans[i + 1] - x < 1 || vis[ans[i + 1] - x]) { ans[i] = ans[i + 1] + x; vis[ans[i + 1] + x] = 1; } else { int y = query(i, i + 2); if ((y != x && ans[i + 2] < ans[i + 1]) || (y == x && ans[i + 2] > ans[i + 1])) { ans[i] = ans[i + 1] + x; vis[ans[i + 1] + x] = 1; } else { ans[i] = ans[i + 1] - x; vis[ans[i + 1] - x] = 1; } } } for (int i = mx + 2;i <= n;i++) { int x = query(i - 1, i); if (ans[i - 1] + x > n || vis[ans[i - 1] + x]) { ans[i] = ans[i - 1] - x; // vis[ans[i - 1] - x] = 1; } else if (ans[i - 1] - x < 1 || vis[ans[i - 1] - x]) { ans[i] = ans[i - 1] + x; vis[ans[i - 1] + x] = 1; } else { int y = query(i - 2, i); if ((y != x && ans[i - 2] < ans[i - 1]) || (y == x && ans[i - 2] > ans[i - 1])) { ans[i] = ans[i - 1] + x; vis[ans[i - 1] + x] = 1; } else { ans[i] = ans[i - 1] - x; vis[ans[i - 1] - x] = 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...