Submission #522902

#TimeUsernameProblemLanguageResultExecution timeMemory
522902CPSCXylophone (JOI18_xylophone)C++14
47 / 100
92 ms320 KiB
#include "xylophone.h" # include <bits/stdc++.h> #define f first #define s second #define pb push_back using namespace std; const int NN = 5005; int le,ri,mid,ans,a[NN],val[NN],vl1,n; void solve(int N) { n = N; le = 2; ri = n; while (le <= ri) { mid = (le + ri) / 2; if (query(1,mid) == n - 1) { ri = mid - 1; ans = mid; } else le = mid + 1; } a[ans] = n; for (int i = ans + 1; i <= n; i++) { if (i == ans + 1) { val[i - 1] = query(i-1,i); a[i] = a[ans] - val[i - 1]; continue; } val[i - 1] = query(i - 1, i); vl1 = query(i - 2, i); if (val[i - 2] + val[i - 1] == vl1) { a[i] = (a[i - 2] > a[i - 1] ? (a[i - 1] - val[i - 1]) : (a[i - 1] + val[i - 1])); } else a[i] = (a[i - 2] > a[i - 1] ? (a[i - 1] + val[i - 1]) : (a[i - 1] - val[i - 1])); } for (int i = ans - 1; i >= 1; i--) { if (i == ans - 1) { val[i] = query(i, i + 1); a[i] = a[ans] - val[i]; continue; } val[i] = query(i, i + 1); vl1 = query(i, i + 2); if (vl1 == val[i] + val[i + 1]) { a[i] = (a[i + 2] > a[i + 1] ? (a[i + 1] - val[i]) : (a[i + 1] + val[i])); } else a[i] = (a[i + 2] > a[i + 1] ? (a[i + 1] + val[i]) : (a[i + 1] - val[i])); } for (int i = 1; i <= n; i++) { answer(i,a[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...