#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
int a[5005];
void solve(int n){
int l=1,r=n,mn=1;
while(l<=r){
int mid=(l+r)/2;
int val=query(mid,n);
if(val==n-1){
mn=mid;
l=mid+1;
}else r=mid-1;
}
//cerr<<"mn : "<<mn<<endl;
a[mn]=1;
if(mn<n) a[mn+1]=query(mn,mn+1)+1;
//cerr<<"a[mn+1]: "<<a[mn+1]<<endl;
for(int i=mn+2; i<=n; i++){
int v=query(i-2,i);
int l=query(i-1,i);
if(v==max(a[i-1],a[i-2])-min(a[i-1],a[i-2])){
if(a[i-1]>a[i-2]) a[i]=a[i-1]-l;
else a[i]=a[i-1]+l;
}else{
int ifmin=a[i-1]-l;
int ifmax=a[i-1]+l;
if(ifmin>0 and max({a[i-2],a[i-1]})-ifmin==v) a[i]=ifmin;
else a[i]=ifmax;
}
}
if(mn>1) a[mn-1]=query(mn-1,mn)+1;
for(int i=mn-2; i>=1; i--){
int v=query(i,i+2);
int l=query(i,i+1);
if(v==max(a[i+1],a[i+2])-min(a[i+1],a[i+2])){
if(a[i+1]>a[i+2]) a[i]=a[i+1]-l;
else a[i]=a[i+1]+l;
}else{
int ifmin=a[i+1]-l;
int ifmax=a[i+1]+l;
if(max({a[i+2],a[i+1]})-ifmin==v) a[i]=ifmin;
else a[i]=ifmax;
}
}
for(int i=1; i<=n; i++) answer(i,a[i]);
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 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 |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
9 ms |
440 KB |
Output is correct |
19 |
Correct |
14 ms |
600 KB |
Output is correct |
20 |
Correct |
13 ms |
436 KB |
Output is correct |
21 |
Correct |
13 ms |
444 KB |
Output is correct |
22 |
Correct |
12 ms |
444 KB |
Output is correct |
23 |
Correct |
13 ms |
440 KB |
Output is correct |
24 |
Correct |
13 ms |
420 KB |
Output is correct |
25 |
Correct |
13 ms |
344 KB |
Output is correct |
26 |
Correct |
10 ms |
600 KB |
Output is correct |
27 |
Correct |
14 ms |
344 KB |
Output is correct |
28 |
Correct |
13 ms |
596 KB |
Output is correct |
29 |
Correct |
12 ms |
600 KB |
Output is correct |
30 |
Correct |
9 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
344 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 |
3 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
9 ms |
440 KB |
Output is correct |
19 |
Correct |
14 ms |
600 KB |
Output is correct |
20 |
Correct |
13 ms |
436 KB |
Output is correct |
21 |
Correct |
13 ms |
444 KB |
Output is correct |
22 |
Correct |
12 ms |
444 KB |
Output is correct |
23 |
Correct |
13 ms |
440 KB |
Output is correct |
24 |
Correct |
13 ms |
420 KB |
Output is correct |
25 |
Correct |
13 ms |
344 KB |
Output is correct |
26 |
Correct |
10 ms |
600 KB |
Output is correct |
27 |
Correct |
14 ms |
344 KB |
Output is correct |
28 |
Correct |
13 ms |
596 KB |
Output is correct |
29 |
Correct |
12 ms |
600 KB |
Output is correct |
30 |
Correct |
9 ms |
348 KB |
Output is correct |
31 |
Correct |
33 ms |
600 KB |
Output is correct |
32 |
Correct |
30 ms |
444 KB |
Output is correct |
33 |
Correct |
52 ms |
428 KB |
Output is correct |
34 |
Incorrect |
50 ms |
444 KB |
Wrong Answer [2] |
35 |
Halted |
0 ms |
0 KB |
- |