Submission #860874

#TimeUsernameProblemLanguageResultExecution timeMemory
860874vjudge1Xylophone (JOI18_xylophone)C++98
47 / 100
67 ms98364 KiB
#include "xylophone.h" using namespace std; #define pb push_back #define mp make_pair #define mt make_tuple #define all(A) A.begin(), A.end() #define rall(A) A.rbegin(), A.rend() using ll = long long; using ld = long double; const int N = 5005; const int M = 405; const int SQRT = 500; const int LOG = 20; const int INF = 1e9; const int MOD = 1e9+7; const ld EPS = 1e-9; const int BASE = 9973; int memo[N + 1][N + 1]; int ask(int l, int r) { if (memo[l][r] == -1) memo[l][r] = query(l, r); return memo[l][r]; } void solve(int n) { int l = 1, r = n; while (r - l > 1) { int mid = (l + r) / 2; if (query(mid, n) == n - 1)l = mid; else r = mid; } for(int i = 1;i<=n;i++){ for(int j = 1;j<=n;j++){ memo[i][j] = -1; } } int A[n+1]; A[l] = 1; A[l + 1] = 1 + ask(l, l + 1); if (l > 1) A[l - 1] = 1 + ask(l - 1, l); for (int i = l + 2;i<=n;i++) { int x = ask(i - 1, i); if (A[i - 1] - x < 1) { A[i] = A[i - 1] + x; continue; } if (A[i - 1] + x > n) { A[i] = A[i - 1] - x; continue; } if (A[i - 2] < A[i - 1]) { if (ask(i - 2, i) == ask(i - 2, i - 1))A[i] = A[i - 1] - ask(i - 1, i); else if (ask(i - 2, i) == ask(i - 1, i))A[i] = A[i - 1] - ask(i - 1, i); else A[i] = A[i - 1] + ask(i - 1, i); } else { if (ask(i - 2, i) == ask(i - 2, i - 1))A[i] = A[i - 1] + ask(i - 1, i); else if (ask(i - 2, i) == ask(i - 1, i))A[i] = A[i - 1] + ask(i - 1, i); else A[i] = A[i - 1] - ask(i - 1, i); } } for (int i = l - 2;i>=1;i--) { int x = ask(i, i + 1); if (A[i + 1] - x < 1) { A[i] = A[i + 1] + x; continue; } if (A[i + 1] + x > n) { A[i] = A[i + 1] - x; continue; } if (A[i + 2] < A[i + 1]) { if (ask(i, i + 2) == ask(i + 1, i + 2))A[i] = A[i + 1] - ask(i, i + 1); else if (ask(i, i + 2) == ask(i, i + 1))A[i] = A[i + 1] - ask(i, i + 1); else A[i] = A[i + 1] + ask(i, i + 1); } else { if (ask(i, i + 2) == ask(i + 1, i + 2))A[i] = A[i + 1] + ask(i, i + 1); else if (ask(i, i + 2) == ask(i, i + 1))A[i] = A[i + 1] + ask(i, i + 1); else A[i] = A[i + 1] - ask(i, i + 1); } } 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...