Submission #1154781

#TimeUsernameProblemLanguageResultExecution timeMemory
1154781nguynXylophone (JOI18_xylophone)C++20
Compilation error
0 ms0 KiB
int vis[5005]; int a[5005]; int nn; bool valid(int x) { return (x >= 1 && x <= nn && !vis[x]); } void solve(int n) { nn = n; int l = 1; int r = n; int id = 0; while(l <= r) { int mid = (l + r) / 2; if (query(1, mid) == n - 1) { r = mid - 1; id = mid; } else { l = mid + 1; } } a[id] = n; a[id + 1] = n - query(id, id + 1); a[id - 1] = n - query(id - 1, id); vis[n] = 1; vis[a[id + 1]] = 1; vis[a[id - 1]] = 1; for (int i = id + 2; i <= n; i++) { int t = query(i - 1, i); int t1 = a[i - 1] - t; int t2 = a[i - 1] + t; if (valid(t1) && valid(t2)) { t = query(i - 2, i); if (t == abs(a[i - 2] - a[i - 1])) { if (a[i - 2] < a[i - 1]) { a[i] = t1; } else { a[i] = t2; } } if (a[i - 2] + t == t2) { a[i] = t2; } if (a[i - 2] - t == t1) { a[i] = t1; } } else if (valid(t1)) { a[i] = t1; } else { a[i] = t2; } vis[a[i]] = 1; } for (int i = id - 2; i >= 1; i--) { int t = query(i, i + 1); int t1 = a[i + 1] - t; int t2 = a[i + 1] + t; if (valid(t1) && valid(t2)) { t = query(i, i + 2); if (t == abs(a[i + 2] - a[i + 1])) { if (a[i + 2] - a[i + 1] > 0) a[i] = t2; else a[i] = t1; } if (a[i + 2] + t == t2) { a[i] = t2; } if (a[i + 2] - t == t1) { a[i] = t1; } } else if (valid(t1)) { a[i] = t1; } else { a[i] = t2; } vis[a[i]] = 1; } for (int i = 1; i <= n; i++) { // assert(a[i] > 0 && a[i] <= n); // cout << a[i] << ' '; answer(i, a[i]); } }

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:15:21: error: 'query' was not declared in this scope
   15 |                 if (query(1, mid) == n - 1) {
      |                     ^~~~~
xylophone.cpp:24:25: error: 'query' was not declared in this scope
   24 |         a[id + 1] = n - query(id, id + 1);
      |                         ^~~~~
xylophone.cpp:35:34: error: 'abs' was not declared in this scope
   35 |                         if (t == abs(a[i - 2] - a[i - 1])) {
      |                                  ^~~
xylophone.cpp:64:34: error: 'abs' was not declared in this scope
   64 |                         if (t == abs(a[i + 2] - a[i + 1])) {
      |                                  ^~~
xylophone.cpp:87:17: error: 'answer' was not declared in this scope
   87 |                 answer(i, a[i]);
      |                 ^~~~~~