#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]=A[1]+x[2];
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]=A[1]-x[2];
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]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
448 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
448 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
11 ms |
456 KB |
Output is correct |
19 |
Correct |
11 ms |
452 KB |
Output is correct |
20 |
Correct |
8 ms |
344 KB |
Output is correct |
21 |
Correct |
16 ms |
344 KB |
Output is correct |
22 |
Correct |
11 ms |
344 KB |
Output is correct |
23 |
Correct |
8 ms |
344 KB |
Output is correct |
24 |
Correct |
10 ms |
456 KB |
Output is correct |
25 |
Correct |
9 ms |
600 KB |
Output is correct |
26 |
Correct |
6 ms |
344 KB |
Output is correct |
27 |
Correct |
7 ms |
344 KB |
Output is correct |
28 |
Correct |
12 ms |
600 KB |
Output is correct |
29 |
Correct |
8 ms |
344 KB |
Output is correct |
30 |
Correct |
6 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
344 KB |
Output is correct |
5 |
Correct |
2 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
448 KB |
Output is correct |
12 |
Correct |
2 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
11 ms |
456 KB |
Output is correct |
19 |
Correct |
11 ms |
452 KB |
Output is correct |
20 |
Correct |
8 ms |
344 KB |
Output is correct |
21 |
Correct |
16 ms |
344 KB |
Output is correct |
22 |
Correct |
11 ms |
344 KB |
Output is correct |
23 |
Correct |
8 ms |
344 KB |
Output is correct |
24 |
Correct |
10 ms |
456 KB |
Output is correct |
25 |
Correct |
9 ms |
600 KB |
Output is correct |
26 |
Correct |
6 ms |
344 KB |
Output is correct |
27 |
Correct |
7 ms |
344 KB |
Output is correct |
28 |
Correct |
12 ms |
600 KB |
Output is correct |
29 |
Correct |
8 ms |
344 KB |
Output is correct |
30 |
Correct |
6 ms |
464 KB |
Output is correct |
31 |
Correct |
27 ms |
600 KB |
Output is correct |
32 |
Correct |
39 ms |
344 KB |
Output is correct |
33 |
Correct |
48 ms |
696 KB |
Output is correct |
34 |
Correct |
57 ms |
344 KB |
Output is correct |
35 |
Correct |
51 ms |
700 KB |
Output is correct |
36 |
Correct |
45 ms |
604 KB |
Output is correct |
37 |
Correct |
39 ms |
344 KB |
Output is correct |
38 |
Correct |
34 ms |
632 KB |
Output is correct |
39 |
Correct |
45 ms |
708 KB |
Output is correct |
40 |
Correct |
69 ms |
704 KB |
Output is correct |
41 |
Correct |
51 ms |
708 KB |
Output is correct |
42 |
Correct |
48 ms |
688 KB |
Output is correct |
43 |
Correct |
47 ms |
712 KB |
Output is correct |
44 |
Correct |
62 ms |
716 KB |
Output is correct |
45 |
Correct |
49 ms |
1124 KB |
Output is correct |
46 |
Correct |
37 ms |
592 KB |
Output is correct |
47 |
Correct |
41 ms |
704 KB |
Output is correct |
48 |
Correct |
38 ms |
960 KB |
Output is correct |
49 |
Correct |
40 ms |
460 KB |
Output is correct |
50 |
Correct |
62 ms |
344 KB |
Output is correct |
51 |
Correct |
53 ms |
452 KB |
Output is correct |
52 |
Correct |
44 ms |
592 KB |
Output is correct |
53 |
Correct |
56 ms |
600 KB |
Output is correct |
54 |
Correct |
44 ms |
600 KB |
Output is correct |
55 |
Correct |
36 ms |
592 KB |
Output is correct |
56 |
Correct |
40 ms |
340 KB |
Output is correct |
57 |
Correct |
63 ms |
848 KB |
Output is correct |
58 |
Correct |
40 ms |
452 KB |
Output is correct |
59 |
Correct |
43 ms |
704 KB |
Output is correct |
60 |
Correct |
45 ms |
712 KB |
Output is correct |