#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
/*void answer(int a,int b){
cout << b << ' ';
}
const int MAXN=5000;
int p[MAXN+1];
int query(int s,int e){
int Min=p[s],Max=p[s];
for(int i=s;i<=e;i++){
Min=min(Min,p[i]);
Max=max(Max,p[i]);
}
return (Max-Min);
}*/
void solve(int n){
if(n==1){
answer(1,1);
}
else if(n==2){
answer(1,1);
answer(2,2);
}
else{
int diff2[n+1];
int diff1[n+1];
for(int i=3;i<=n;i++){
diff1[i]=query(i-1,i);
diff2[i]=query(i-2,i);
}
int a[n+1];
int dist=query(1,2);
bool inva=true;
for(int m=-1;m<=1;m+=2){
a[1]=10000;
a[2]=a[1]+m*dist;
int Min=min(a[1],a[2]);
for(int i=3;i<=n;i++){
if(diff2[i]==diff1[i]+abs(a[i-2]-a[i-1])){
if(a[i-2]>a[i-1]){
a[i]=a[i-1]-diff1[i];
}
else{
a[i]=a[i-1]+diff1[i];
}
}
else if(diff2[i]==max(diff1[i],abs(a[i-2]-a[i-1]))){
if(a[i-2]>a[i-1]){
a[i]=a[i-1]+diff1[i];
}
else{
a[i]=a[i-1]-diff1[i];
}
}
else{
inva=false;
break;
}
Min=min(Min,a[i]);
}
if(!inva){
continue;
}
Min--;
bool mark[n+1]={false};
bool flag=true;
for(int i=1;i<=n;i++){
a[i]-=Min;
if(a[i]>n||a[i]<1||mark[a[i]]){
flag=false;
break;
}
if(a[i]==n&&!mark[1]){
flag=false;
break;
}
mark[a[i]]=true;
}
if(flag){
for(int i=1;i<=n;i++){
answer(i,a[i]);
}
break;
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 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 |
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 |
0 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 |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 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 |
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 |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
9 ms |
344 KB |
Output is correct |
20 |
Correct |
8 ms |
344 KB |
Output is correct |
21 |
Correct |
9 ms |
444 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
13 ms |
444 KB |
Output is correct |
24 |
Correct |
10 ms |
440 KB |
Output is correct |
25 |
Correct |
12 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
9 ms |
344 KB |
Output is correct |
28 |
Correct |
9 ms |
344 KB |
Output is correct |
29 |
Correct |
10 ms |
444 KB |
Output is correct |
30 |
Correct |
11 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
2 ms |
344 KB |
Output is correct |
8 |
Correct |
2 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 |
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 |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
9 ms |
344 KB |
Output is correct |
20 |
Correct |
8 ms |
344 KB |
Output is correct |
21 |
Correct |
9 ms |
444 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
13 ms |
444 KB |
Output is correct |
24 |
Correct |
10 ms |
440 KB |
Output is correct |
25 |
Correct |
12 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
344 KB |
Output is correct |
27 |
Correct |
9 ms |
344 KB |
Output is correct |
28 |
Correct |
9 ms |
344 KB |
Output is correct |
29 |
Correct |
10 ms |
444 KB |
Output is correct |
30 |
Correct |
11 ms |
344 KB |
Output is correct |
31 |
Correct |
13 ms |
344 KB |
Output is correct |
32 |
Correct |
40 ms |
436 KB |
Output is correct |
33 |
Correct |
55 ms |
444 KB |
Output is correct |
34 |
Correct |
45 ms |
464 KB |
Output is correct |
35 |
Correct |
58 ms |
592 KB |
Output is correct |
36 |
Correct |
38 ms |
444 KB |
Output is correct |
37 |
Correct |
51 ms |
592 KB |
Output is correct |
38 |
Correct |
60 ms |
344 KB |
Output is correct |
39 |
Correct |
46 ms |
444 KB |
Output is correct |
40 |
Correct |
58 ms |
592 KB |
Output is correct |
41 |
Correct |
42 ms |
592 KB |
Output is correct |
42 |
Correct |
51 ms |
452 KB |
Output is correct |
43 |
Correct |
67 ms |
448 KB |
Output is correct |
44 |
Correct |
57 ms |
592 KB |
Output is correct |
45 |
Correct |
46 ms |
444 KB |
Output is correct |
46 |
Correct |
52 ms |
448 KB |
Output is correct |
47 |
Correct |
57 ms |
452 KB |
Output is correct |
48 |
Correct |
55 ms |
460 KB |
Output is correct |
49 |
Correct |
52 ms |
344 KB |
Output is correct |
50 |
Correct |
53 ms |
464 KB |
Output is correct |
51 |
Correct |
61 ms |
592 KB |
Output is correct |
52 |
Correct |
55 ms |
448 KB |
Output is correct |
53 |
Correct |
46 ms |
452 KB |
Output is correct |
54 |
Correct |
56 ms |
592 KB |
Output is correct |
55 |
Correct |
44 ms |
452 KB |
Output is correct |
56 |
Correct |
49 ms |
468 KB |
Output is correct |
57 |
Correct |
53 ms |
448 KB |
Output is correct |
58 |
Correct |
58 ms |
344 KB |
Output is correct |
59 |
Correct |
53 ms |
344 KB |
Output is correct |
60 |
Correct |
55 ms |
452 KB |
Output is correct |