Submission #720554

#TimeUsernameProblemLanguageResultExecution timeMemory
720554hoainiemXylophone (JOI18_xylophone)C++14
0 / 100
1 ms336 KiB
#include "xylophone.h" #include <bits/stdc++.h> using namespace std; int n, root, a[5008], dis[5008][5008]; void solve(int N) { n = N; for (int i = 1; i < n; i++) a[i] = query(i, i + 1); for (int i = 1, j = 1; i + 2 <= n; i++){ int tmp = query(i, i + 2); if (tmp != a[i] + a[i + 1]) j *= -1; a[i + 1] *= j; } for (int i = 1; i <= n; i++){ int cnt = 0; for (int j = i + 1; j <= n; j++){ dis[i][j] = dis[i][j - 1] + a[j - 1]; if (dis[i][j] > 0) cnt++; } for (int j = i - 1; j > 0; j--){ dis[i][j] = dis[i][j + 1] - a[j]; if (dis[i][j] > 0) cnt++; } if (!cnt || cnt + 1 == n){ root = i; break; } } for (int i = 1; i <= n; i++) answer(i, abs(dis[root][i]) + 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...