Submission #127480

#TimeUsernameProblemLanguageResultExecution timeMemory
127480Markomafko972Xylophone (JOI18_xylophone)C++14
0 / 100
4 ms504 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; void solve(int n) { int t[5002]; memset(t, 0, sizeof t); int q[5002][5]; memset(q, 0, sizeof q); q[0][2] = query(1, 2); t[2] = q[0][2]; int e = min(t[1], t[2]); for (int i = 3; i <= n; i ++) { q[0][i] = query(i-1, i); q[1][i] = query(i-2, i); if (t[i-2] < t[i-1]) { if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] - q[0][i]; else t[i] = t[i-1] + q[0][i]; } else { if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] + q[0][i]; else t[i] = t[i-1] - q[0][i]; } e = min(e, t[i]); } int bio[5002]; for (int i = 1; i <= n; i ++) { t[i] -= e-1; bio[t[i]] = 1; } int da = 1; for (int i = 1; i <= n; i ++) { if (bio[i] == 0) { da = 0; break; } } if (da && t[1] < t[n]) { for (int i = 1; i <= n; i ++) { answer(i, t[i]); } return; } memset(t, 0, sizeof t); t[2] = -q[0][2]; e = min(t[1], t[2]); for (int i = 3; i <= n; i ++) { if (t[i-2] < t[i-1]) { if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] - q[0][i]; else t[i] = t[i-1] + q[0][i]; } else { if (q[0][i] == q[1][i] || q[0][i-1] == q[1][i]) t[i] = t[i-1] + q[0][i]; else t[i] = t[i-1] - q[0][i]; } e = min(e, t[i]); } memset(bio, 0, sizeof bio); for (int i = 1; i <= n; i ++) { t[i] -= e-1; bio[t[i]] = 1; } da = 1; /*for (int i = 1; i <= n; i ++) { if (bio[i] == 0) { da = 0; break; } }*/ if (da) { for (int i = 1; i <= n; i ++) { answer(i, t[i]); } return; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...