#include "xylophone.h"
#include <iostream>
using namespace std;
int a[5010], _ok[20000];
int *ok = _ok+10000;
void Answer(int x, int v){
answer(x,v); a[x]=v; ok[v]=1;
}
void solve(int n) {
int l = 1, r = n-1;
while(l<r){
int mid = (l+r+1)/2;
if(query(mid,n)==n-1) l=mid;
else r=mid-1;
}
for(int i = -2*n; i <= 2*n; i++) ok[i]=(i<1 or i>n);
Answer(l,1);
if(l!=1) Answer(l-1,query(l-1,l)+1);
Answer(l+1,query(l,l+1)+1);
for(int i = l-2; i>=1; i--){
int dif = query(i,i+1);
int x1 = a[i+1]-dif,x2 = a[i+1]+dif;
if(ok[x1]) swap(x1,x2);
if(ok[x2]) Answer(i,x1);
else{
int dif2 = query(i,i+2);
if(abs(x1-a[i+2])==dif2) Answer(i,x1);
else Answer(i,x2);
}
}
for(int i = l+2; i<=n; i++){
int dif = query(i-1,i);
int x1 = a[i-1]-dif;
int x2 = a[i-1]+dif;
if(ok[x1]) swap(x1,x2);
if(ok[x2]) Answer(i,x1);
else{
int dif2 = query(i-2,i);
if(abs(x1-a[i-2])==dif2) Answer(i,x1);
else Answer(i,x2);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
1 ms |
208 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |