Submission #1114458

#TimeUsernameProblemLanguageResultExecution timeMemory
1114458sunboiXylophone (JOI18_xylophone)C++17
47 / 100
183 ms508 KiB
#include <cstdio> #include <cstdlib> #include <iostream> #include <vector> using namespace std; #include "xylophone.h" static int A[5000]; void solve(int N){ int n = N; int i = 1, fin = n; while(i < fin){ int m = (i + fin) / 2; if (query(m, n) == n - 1){ i = m + 1; }else fin = m; } i--; int reference = i; vector<int> a(n + 1); int x = query(i, i + 1); a[i] = 1; a[i + 1] = x + 1; i += 2; int last = x; for (; i <= n; i++){ int mn = min(a[i - 1], a[i - 2]); int uno = query(i - 1, i); int dos = query(i - 2, i); if (dos > last){ if (dos == uno){ if (a[i - 1] == mn) a[i] = a[i - 1] + uno; else a[i] = a[i - 1] - uno; }else{ if (a[i - 2] == mn) a[i] = a[i - 2] + dos; else a[i] = a[i - 2] - dos; } }else{ if (a[i - 1] == mn) a[i] = a[i - 1] + uno; else a[i] = a[i - 1] - uno; } last = uno; } i = reference; if (i > 1){ x = query(i - 1, i); a[i - 1] = 1 + x; last = x; i -= 2; for (; i >= 1; i--){ int mn = min(a[i + 1], a[i + 2]); int uno = query(i, i + 1); int dos = query(i, i + 2); if (dos > last){ if (dos == uno){ if (a[i + 1] == mn) a[i] = a[i + 1] + uno; else a[i] = a[i + 1] - uno; }else{ if (a[i + 2] == mn) a[i] = a[i + 2] + dos; else a[i] = a[i + 2] - dos; } }else{ if (a[i + 1] == mn) a[i] = a[i + 1] + uno; else a[i] = a[i + 1] - uno; } last = uno; } } for(int i = 1;i<=n;i++) answer(i, a[i]); return; }

Compilation message (stderr)

xylophone.cpp:8:12: warning: 'A' defined but not used [-Wunused-variable]
    8 | static int A[5000];
      |            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...