Submission #654434

#TimeUsernameProblemLanguageResultExecution timeMemory
654434SanguineChameleonXylophone (JOI18_xylophone)C++14
0 / 100
3 ms208 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; void solve(int n) { vector<int> a(n + 1); vector<int> b(n + 1); for (int i = 1; i <= n - 1; i++) { a[i] = query(i, i + 1); } for (int i = 1; i <= n - 2; i++) { b[i] = query(i, i + 2); } vector<bool> f(n + 1); vector<int> res(n + 1); for (int i = 1; i <= n; i++) { res[1] = i; for (int j = -1; j <= 1; j += 2) { fill(f.begin(), f.end(), false); f[res[1]] = true; res[2] = res[1] + a[1] * j; if (res[2] < 1 || res[2] > n || f[res[2]]) { continue; } f[res[2]] = true; bool ok = true; for (int k = 3; k <= n; k++) { bool g = false; for (int l = -1; l <= 1; l += 2) { res[k] = res[k - 1] + a[k - 1] * l; if (res[k] < 1 || res[k] > n || f[res[k]]) { continue; } if (max({res[k - 2], res[k - 1], res[k]}) - min({res[k - 2], res[k - 1], res[k]}) != b[k - 2]) { continue; } f[res[k]] = true; g = true; break; } if (!g) { ok = false; break; } } if (ok) { for (int i = 1; i <= n; i++) { answer(i, res[i]); } return; } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...