#include "bits/stdc++.h"
#include "xylophone.h"
// #include "grader.cpp"
using namespace std;
void solve(int n) {
int cnt = 1;
int k = (query (1, n)), l, r;
for(int i = 2; i <= n; i++) {
cnt++;
if(query(i, n) != k) {
l = i-1;
break;
}
}
for(int i = n-1; i > l; i--) {
cnt++;
if(query(l, i) != k) {
r = i+1;
break;
}
}
vector <int> ans1(n+1, 0);
ans1[l] = 1;
if(l > 1) ans1[l-1] = ans1[l] + query(l-1, l), cnt++;
for(int i = l-2; i > 0; i--) {
int x = ans1[i+1], y = ans1[i+2];
k = query(i, i+2);
cnt += 2;
int k1 = query(i, i+1);
if(x > y) {
if(k == (x + k1 - y)) ans1[i] = x + k1;
else ans1[i] = x - k1;
}
else {
if(k == (y - (x - k1))) ans1[i] = x - k1;
else ans1[i] = x + k1;
}
}
cnt++;
ans1[l+1] = ans1[l] + query(l, l+1);
for(int i = l+2; i <= n; i++) {
int x = ans1[i-1], y = ans1[i-2];
cnt += 2;
k = query(i-2, i);
int k1 = query(i-1, i);
if(x > y) {
if(k == (x + k1 - y)) ans1[i] = x + k1;
else ans1[i] = x - k1;
}
else {
if(k == (y - (x - k1))) ans1[i] = x - k1;
else ans1[i] = x + k1;
}
}
assert(cnt <= 10000);
for(int i = 1; i <= n; i++) {
answer(i, ans1[i]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |