#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int a[5005];
void solve(int N) {
int n=N;
int value = query(1, N);
map<pair<int,int>,int> mp;
for(int i=1;i<n;i++){
int t=query(i,i+1);
mp[{i,i+1}]=t;
}
for(int i=1;i<n-1;i++){
int t=query(i,i+2);
if(mp[{i,i+1}]+mp[{i+1,i+2}]==t){
mp[{i,i+2}]=1;
}
}
int p1=1,p2=N;
while(p2>=p1){
int v=query(p1,p2);
if(v!=value){
p2++;
break;
}
p2--;
}
while(p1<=p2){
int v=query(p1,p2);
if(v!=value){
p1--;
break;
}
p1++;
}
a[p1]=1;
a[p2]=n;
for(int i=p1-1;i>=1;i--){
int t=mp[{i,i+1}];
if(i==p1-1){
a[i]=1+t;
}
else{
if(mp[{i,i+2}]){
if(a[i+1]>a[i+2]){
a[i]=a[i+1]+t;
}
else{
a[i]=a[i+1]-t;
}
}
else{
if(a[i+1]>a[i+2]){
a[i]=a[i+1]-t;
}
else{
a[i]=a[i+1]+t;
}
}
}
}
if(p1!=p2-1){
for(int i=p1+1;i<p2;i++){
int t=mp[{i-1,i}];
if(i==p1+1){
a[i]=1+t;
}
else{
if(mp[{i-2,i}]){
if(a[i-2]>a[i-1]){
a[i]=a[i-1]-t;
}
else{
a[i]=a[i-1]+t;
}
}
else{
if(a[i-2]>a[i-1]){
a[i]=a[i-1]+t;
}
else{
a[i]=a[i-1]-t;
}
}
}
}
}
for(int i=p2+1;i<=n;i++){
int t=mp[{i-1,i}];
if(i==p2+1){
a[i]=n-t;
}
else{
if(mp[{i-2,i}]){
if(a[i-2]>a[i-1]){
a[i]=a[i-1]-t;
}
else{
a[i]=a[i-1]+t;
}
}
else{
if(a[i-2]>a[i-1]){
a[i]=a[i-1]+t;
}
else{
a[i]=a[i-1]-t;
}
}
}
}
for(int i=1;i<=n;i++){
answer(i,a[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
408 KB |
Output is correct |
16 |
Correct |
4 ms |
416 KB |
Output is correct |
17 |
Correct |
15 ms |
356 KB |
Output is correct |
18 |
Correct |
10 ms |
324 KB |
Output is correct |
19 |
Correct |
27 ms |
508 KB |
Output is correct |
20 |
Correct |
12 ms |
560 KB |
Output is correct |
21 |
Correct |
30 ms |
376 KB |
Output is correct |
22 |
Correct |
14 ms |
412 KB |
Output is correct |
23 |
Correct |
18 ms |
432 KB |
Output is correct |
24 |
Correct |
30 ms |
424 KB |
Output is correct |
25 |
Correct |
33 ms |
504 KB |
Output is correct |
26 |
Correct |
30 ms |
428 KB |
Output is correct |
27 |
Correct |
19 ms |
424 KB |
Output is correct |
28 |
Correct |
20 ms |
376 KB |
Output is correct |
29 |
Correct |
17 ms |
504 KB |
Output is correct |
30 |
Correct |
26 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
4 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
408 KB |
Output is correct |
16 |
Correct |
4 ms |
416 KB |
Output is correct |
17 |
Correct |
15 ms |
356 KB |
Output is correct |
18 |
Correct |
10 ms |
324 KB |
Output is correct |
19 |
Correct |
27 ms |
508 KB |
Output is correct |
20 |
Correct |
12 ms |
560 KB |
Output is correct |
21 |
Correct |
30 ms |
376 KB |
Output is correct |
22 |
Correct |
14 ms |
412 KB |
Output is correct |
23 |
Correct |
18 ms |
432 KB |
Output is correct |
24 |
Correct |
30 ms |
424 KB |
Output is correct |
25 |
Correct |
33 ms |
504 KB |
Output is correct |
26 |
Correct |
30 ms |
428 KB |
Output is correct |
27 |
Correct |
19 ms |
424 KB |
Output is correct |
28 |
Correct |
20 ms |
376 KB |
Output is correct |
29 |
Correct |
17 ms |
504 KB |
Output is correct |
30 |
Correct |
26 ms |
504 KB |
Output is correct |
31 |
Correct |
69 ms |
552 KB |
Output is correct |
32 |
Correct |
56 ms |
632 KB |
Output is correct |
33 |
Incorrect |
76 ms |
760 KB |
Wrong Answer [2] |
34 |
Halted |
0 ms |
0 KB |
- |