#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
int v[5005];
int calc(int a, int b, int x, int y){
if(abs(a-b) != y && x != y){
if(a > b)return b-x;
return b+x;
}else{
if(a > b)return b+x;
return b-x;
}
}
void solve(int n) {
int l = 1, r = n;
while(l!= r){
int mid = (l+r+1)/2;
if(query(mid,n) == n-1)l = mid;
else r = mid-1;
}
v[l] = 1;
v[l+1] = 1+query(l,l+1);
for(int i = l+2; i <= n; i++){
int x = query(i-1,i);
if(abs(v[i-2]-v[i-1]) > n/2){
if(v[i-2] > v[i-1])v[i] = v[i-1]+x;
else v[i] = v[i-1]-x;
}else v[i] = calc(v[i-2],v[i-1], x, query(i-2,i));
}
if(l != 1){
v[l-1] = 1+query(l-1,l);
for(int i = l-2; i >= 1; i--){
int x = query(i,i+1);
if(abs(v[i+2]-v[i+1]) > n/2){
if(v[i+2] > v[i+1])v[i] = v[i+1]+x;
else v[i] = v[i+1]-x;
}else v[i] = calc(v[i+2], v[i+1], query(i,i+1), query(i,i+2));
}
}
for(int i = 1; i <= n; i++)
answer(i,v[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
2 ms |
336 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
2 ms |
336 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
2 ms |
336 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |