Submission #505234

#TimeUsernameProblemLanguageResultExecution timeMemory
505234colossal_pepeXylophone (JOI18_xylophone)C++17
0 / 100
1 ms328 KiB
#include <iostream> using namespace std; int n, a[5005]; int query(int s, int t); void answer(int i, int x); int find1Pos() { int p = 1; int r = n; while (p < r) { int m = (p + r + 1) / 2; if (query(m, n) == n - 1) p = m; else r = m - 1; } return p; } int getVal(int cur, int p, int pp) { int d = query(min(cur, p), max(cur, p)); if (a[p] + d > n) { return a[p] - d; } else if (a[p] - d < 1) { return a[p] + d; } else { int y = query(min(cur, pp), max(cur, pp)); if (a[p] > a[pp]) { if (y == a[p] - a[pp] + d) { a[cur] = a[p] + d; } else { a[cur] = a[p] - d; } } else { if (y == a[pp] - a[p] + d) { a[cur] = a[p] - d; } else { a[cur] = a[p] + d; } } } } void solve(int N) { n = N; int k = find1Pos(); a[k] = 1; for (int i = k - 1; i >= 1; i--) { a[i] = getVal(i, i + 1, i + 2); } for (int i = k + 1; i <= n; i++) { a[i] = getVal(i, i - 1, i - 2); } for (int i = 1; i <= n; i++) { answer(i, a[i]); } }

Compilation message (stderr)

xylophone.cpp: In function 'int getVal(int, int, int)':
xylophone.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
   44 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...