#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
static int A[5001];
int x[5001],y[5001],i,mn,ok[5001];
void solve(int N) {
A[1]=1;
for(i=2;i<=N;i++) x[i]=query(i-1,i);
for(i=3;i<=N;i++) y[i]=query(i-2,i);
A[2]=x[2]+1;
for(i=3;i<=N;i++){
if(x[i-1]==y[i]){
if(A[i-1]>A[i-2]) A[i]=A[i-1]-x[i];
else A[i]=A[i-1]+x[i];
}
else{
if(y[i]!=x[i]){
if(A[i-1]>A[i-2]) A[i]=A[i-1]+x[i];
else A[i]=A[i-1]-x[i];
}
else{
if(A[i-2]>A[i-1]) A[i]=A[i-1]+x[i];
else A[i]=A[i-1]-x[i];
}
}
}
mn=10000;
for(i=1;i<=N;i++){
mn=min(A[i],mn);
}
mn=1-mn;
for(i=1;i<=N;i++) A[i]+=mn;
bool unen=1;
for(i=1;i<=N;i++){
if(A[i]<1 || A[i]>N) unen=0;
if(ok[A[i]]!=0) unen=0;
ok[A[i]]=i;
}
if(ok[1]>ok[N]) unen=0;
if(unen){
for(i=1;i<=N;i++) answer(i,A[i]);
return;
}
A[1]=1;
A[2]=x[2]-1;
for(i=3;i<=N;i++){
if(x[i-1]==y[i]){
if(A[i-1]>A[i-2]) A[i]=A[i-1]-x[i];
else A[i]=A[i-1]+x[i];
}
else{
if(y[i]!=x[i]){
if(A[i-1]>A[i-2]) A[i]=A[i-1]+x[i];
else A[i]=A[i-1]-x[i];
}
else{
if(A[i-2]>A[i-1]) A[i]=A[i-1]+x[i];
else A[i]=A[i-1]-x[i];
}
}
}
mn=10000;
for(i=1;i<=N;i++){
mn=min(A[i],mn);
}
mn=1-mn;
for(i=1;i<=N;i++) A[i]+=mn;
for(i=1;i<=N;i++) answer(i,A[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [7] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [7] |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Incorrect |
1 ms |
344 KB |
Wrong Answer [7] |
14 |
Halted |
0 ms |
0 KB |
- |