This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |