Submission #894607

#TimeUsernameProblemLanguageResultExecution timeMemory
894607lunaTuXylophone (JOI18_xylophone)C++17
100 / 100
64 ms760 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define all(x) x.begin(), x.end() #include "xylophone.h" typedef long long ll; using namespace std; bool solve2(int n, vector<pair<int, int>>& g) { map<int, int> d; vector<int> a(n + 1); a[1] = 0; a[2] = g[2].ss; d[0] = 1; d[a[2]] = 2; for (int i = 3; i <= n; i++) { int x = g[i].ff, y = g[i].ss; int r = abs(a[i - 2] - a[i - 1]); if (a[i - 2] < a[i - 1]) { if (x != r && x != y) a[i] = a[i - 2] + x; else a[i] = a[i - 1] - y; } else { if (x != r && x != y) a[i] = a[i - 2] - x; else a[i] = a[i - 1] + y; } if (d[a[i]]) return 0; d[a[i]] = i; } if ((*d.begin()).ss > (*d.rbegin()).ss) return 0; int i = 1; for (auto [x, y] : d) { answer(y, i); i++; } return 1; } void solve(int N) { vector<pair<int, int>> g(N + 1); g[2].ss = query(1, 2); for (int i = 3; i <= N; i++) { g[i].ff = query(i - 2, i); g[i].ss = query(i - 1, i); } if (solve2(N, g)) return; g[2].ss *= -1; if (solve2(N, g)) return; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...