Submission #1116612

#TimeUsernameProblemLanguageResultExecution timeMemory
1116612gustavo_dXylophone (JOI18_xylophone)C++17
100 / 100
201 ms956 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int a1[5001], a2[5001]; void solve(int N) { int n = N; int pos1=1; a1[pos1] = 1; a2[pos1] = 1; a1[pos1+1] = 1-query(pos1, pos1+1); a2[pos1+1] = query(pos1, pos1+1) + 1; for (int pt = pos1+2; pt<=n; pt++) { int q1 = query(pt-1, pt), q2 = query(pt-2, pt); int d1 = abs(a1[pt-1] - a1[pt-2]); int d = q1; if (a1[pt-2] < a1[pt-1]) { if (q2 == d + d1) a1[pt] = a1[pt-1] + d; else a1[pt] = a1[pt-1] - d; } else { if (q2 == d + d1) a1[pt] = a1[pt-1] - d; else a1[pt] = a1[pt-1] + d; } d1 = abs(a2[pt-1] - a2[pt-2]); if (a2[pt-2] < a2[pt-1]) { if (q2 == d + d1) a2[pt] = a2[pt-1] + d; else a2[pt] = a2[pt-1] - d; } else { if (q2 == d + d1) a2[pt] = a2[pt-1] - d; else a2[pt] = a2[pt-1] + d; } } int mn = 1e9; for (int i=1; i<=n; i++) mn = min(mn, a1[i]); for (int i=1; i<=n; i++) a1[i] -= mn-1; mn = 1e9; for (int i=1; i<=n; i++) mn = min(mn, a2[i]); for (int i=1; i<=n; i++) a2[i] -= mn-1; // int pos1=n; // for (; pos1>=1; pos1--) { // int value = query(pos1, n); // if (value == n-1) break; // } // a[pos1] = 1; // a[pos1+1] = query(pos1, pos1+1) + 1; // for (int pt = pos1+2; pt<=n; pt++) { // int d1 = abs(a[pt-1] - a[pt-2]); // int d = query(pt-1, pt); // if (a[pt-2] < a[pt-1]) { // if (query(pt-2, pt) == d + d1) a[pt] = a[pt-1] + d; // else a[pt] = a[pt-1] - d; // } else { // if (query(pt-2, pt) == d + d1) a[pt] = a[pt-1] - d; // else a[pt] = a[pt-1] + d; // } // } // for (int pt = pos1-1; pt>=1; pt--) { // int d1 = abs(a[pt+1] - a[pt+2]); // int d = query(pt, pt+1); // if (a[pt+2] < a[pt+1]) { // if (query(pt, pt+2) == d + d1) a[pt] = a[pt+1] + d; // else a[pt] = a[pt+1] - d; // } else { // if (query(pt, pt+2) == d + d1) a[pt] = a[pt+1] - d; // else a[pt] = a[pt+1] + d; // } // } bool a1_ac = true; bool found1 = false; for (int i=1; i<=n; i++) { if (a1[i] == 1) found1 = true; if (a1[i] == n and !found1) a1_ac = false; } for(int i = 1; i <= N; i++) { answer(i, a1_ac ? a1[i] : a2[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...