# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122019 | 2019-06-27T11:36:10 Z | eriksuenderhauf | Xylophone (JOI18_xylophone) | C++11 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "xylophone.h" using namespace std; const int MAXN = 1e4 + 5; int qry[MAXN][2]; int a[MAXN]; set<int> tmp; bool finish = 0; void detect_pitch(int n) { int mi = 0, fl = 0; for (int i = 0; i < n; i++) mi = min(mi, a[i]); for (int i = 0; i < n; i++) { a[i] -= mi; if (a[i] == n - 1 && !fl) return; if (a[i] == 0) fl = 1; } for (int i = 0; i < n; i++) answer(i, a[i]); finish = 1; } void solve(int n) { for (int i = 0; i + 1 < n; i++) qry[i][0] = ask(i, i + 1); for (int i = 0; i + 2 < n; i++) qry[i][1] = ask(i, i + 2); a[1] = qry[0][0]; tmp.insert(0); tmp.insert(a[1]); for (int i = 2; i < n; i++) { if (qry[i - 2][0] == qry[i - 2][1]) { int fl = 1; if (a[i - 1] > a[i - 2]) fl = -1; a[i] = a[i - 1] + fl * qry[i - 1][0]; } else if (qry[i - 2][0] + qry[i - 1][0] == qry[i - 2][1]) { int fl = 1; if (a[i - 1] < a[i - 2]) fl = -1; a[i] = a[i - 1] + fl * qry[i - 1][0]; } else { int fl = 1; if (a[i - 1] > a[i - 2]) fl = -1; a[i] = a[i - 1] + fl * qry[i - 1][0]; } tmp.insert(a[i]); } if ((int)tmp.size() == n) detect_pitch(n); if (finish) return; for (int i = 0; i < n; i++) a[i] = 0; tmp.clear(); a[1] = -qry[0][0]; tmp.insert(0); tmp.insert(a[1]); for (int i = 2; i < n; i++) { if (qry[i - 2][0] == qry[i - 2][1]) { int fl = 1; if (a[i - 1] > a[i - 2]) fl = -1; a[i] = a[i - 1] + fl * qry[i - 1][0]; } else if (qry[i - 2][0] + qry[i - 1][0] == qry[i - 2][1]) { int fl = 1; if (a[i - 1] < a[i - 2]) fl = -1; a[i] = a[i - 1] + fl * qry[i - 1][0]; } else { int fl = 1; if (a[i - 1] > a[i - 2]) fl = -1; a[i] = a[i - 1] + fl * qry[i - 1][0]; } tmp.insert(a[i]); } if ((int)tmp.size() == n) detect_pitch(n); }