#include "xylophone.h"
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int a[5010];
bool found[5010];
int place_1, place_n;
int bin_search_n(int l, int r){
if(l==r) return l;
if(l+1==r){
int x = query(1, r);
if(x==n-1) return r;
else return l;
}
int mid = (l+r)/2;
int x = query(1, mid);
if(x<n-1) return bin_search_n(mid+1, r);
else return bin_search_n(l, mid);
}
int bin_search_1(int l, int r){
if(l==r) return l;
if(l+1==r){
int x = query(r, n);
if(x==n-1) return r;
else return l;
}
int mid = (l+r)/2;
int x = query(mid, n);
if(x<n-1) return bin_search_1(l, mid-1);
else return bin_search_1(mid, r);
}
void solve(int N) {
n = N;
memset(found, false, sizeof found);
//place_n = bin_search_n(1, n); a[place_n] = n; found[n] = true;
place_1 = bin_search_1(1, n); a[place_1] = 1; found[1] = true;
for(int i=place_1-1;i>0;i--){
int x = query(i, i+1);
int mx = a[i+1]+x, mn = a[i+1]-x;
if(mx>n||found[mx]){
a[i] = mn;
found[mn] = true;
}else if(mn<1||found[mn]){
a[i] = mx;
found[mx] = true;
}else{
int y = query(i, i+2);
if(a[i+2]>a[i+1]){
if(y==a[i+2]-mn){
a[i] = mn;
found[mn] = true;
}else{
a[i] = mx;
found[mx] = true;
}
}else{
if(y==mx-a[i+2]){
a[i] = mx;
found[mx] = true;
}else{
a[i] = mn;
found[mn] = true;
}
}
}
}
for(int i=place_1+1;i<=n;i++){
//if(i==place_n) continue;
int x = query(i-1, i);
int mx = a[i-1]+x, mn = a[i-1]-x;
//printf("a[i-1]: %d, mn: %d, mx: %d\n", a[i-1], mn, mx);
if(mx>n||found[mx]){
a[i] = mn;
found[mn] = true;
}else if(mn<1||found[mn]){
a[i] = mx;
found[mx] = true;
}else{
int y = query(i-2, i);
if(a[i-2]>a[i-1]){
if(y==a[i-2]-mn){
a[i] = mn;
found[mn] = true;
}else{
a[i] = mx;
found[mx] = true;
}
}else{
if(y==mx-a[i-2]){
a[i] = mx;
found[mx] = true;
}else{
a[i] = mn;
found[mn] = true;
}
}
}
}
for(int i=1;i<=n;i++){
//printf("%d ", a[i]);
answer(i, a[i]);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
308 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
432 KB |
Output is correct |
5 |
Correct |
3 ms |
432 KB |
Output is correct |
6 |
Correct |
3 ms |
432 KB |
Output is correct |
7 |
Correct |
4 ms |
432 KB |
Output is correct |
8 |
Correct |
3 ms |
432 KB |
Output is correct |
9 |
Correct |
3 ms |
472 KB |
Output is correct |
10 |
Correct |
3 ms |
472 KB |
Output is correct |
11 |
Correct |
6 ms |
548 KB |
Output is correct |
12 |
Correct |
2 ms |
548 KB |
Output is correct |
13 |
Correct |
3 ms |
556 KB |
Output is correct |
14 |
Correct |
4 ms |
556 KB |
Output is correct |
15 |
Correct |
3 ms |
556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
308 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
432 KB |
Output is correct |
5 |
Correct |
3 ms |
432 KB |
Output is correct |
6 |
Correct |
3 ms |
432 KB |
Output is correct |
7 |
Correct |
4 ms |
432 KB |
Output is correct |
8 |
Correct |
3 ms |
432 KB |
Output is correct |
9 |
Correct |
3 ms |
472 KB |
Output is correct |
10 |
Correct |
3 ms |
472 KB |
Output is correct |
11 |
Correct |
6 ms |
548 KB |
Output is correct |
12 |
Correct |
2 ms |
548 KB |
Output is correct |
13 |
Correct |
3 ms |
556 KB |
Output is correct |
14 |
Correct |
4 ms |
556 KB |
Output is correct |
15 |
Correct |
3 ms |
556 KB |
Output is correct |
16 |
Correct |
4 ms |
556 KB |
Output is correct |
17 |
Correct |
8 ms |
556 KB |
Output is correct |
18 |
Correct |
12 ms |
556 KB |
Output is correct |
19 |
Correct |
7 ms |
680 KB |
Output is correct |
20 |
Correct |
20 ms |
680 KB |
Output is correct |
21 |
Correct |
16 ms |
680 KB |
Output is correct |
22 |
Correct |
12 ms |
680 KB |
Output is correct |
23 |
Correct |
13 ms |
680 KB |
Output is correct |
24 |
Correct |
15 ms |
680 KB |
Output is correct |
25 |
Correct |
9 ms |
680 KB |
Output is correct |
26 |
Correct |
23 ms |
680 KB |
Output is correct |
27 |
Correct |
7 ms |
680 KB |
Output is correct |
28 |
Correct |
7 ms |
680 KB |
Output is correct |
29 |
Correct |
14 ms |
680 KB |
Output is correct |
30 |
Correct |
11 ms |
680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
308 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
432 KB |
Output is correct |
5 |
Correct |
3 ms |
432 KB |
Output is correct |
6 |
Correct |
3 ms |
432 KB |
Output is correct |
7 |
Correct |
4 ms |
432 KB |
Output is correct |
8 |
Correct |
3 ms |
432 KB |
Output is correct |
9 |
Correct |
3 ms |
472 KB |
Output is correct |
10 |
Correct |
3 ms |
472 KB |
Output is correct |
11 |
Correct |
6 ms |
548 KB |
Output is correct |
12 |
Correct |
2 ms |
548 KB |
Output is correct |
13 |
Correct |
3 ms |
556 KB |
Output is correct |
14 |
Correct |
4 ms |
556 KB |
Output is correct |
15 |
Correct |
3 ms |
556 KB |
Output is correct |
16 |
Correct |
4 ms |
556 KB |
Output is correct |
17 |
Correct |
8 ms |
556 KB |
Output is correct |
18 |
Correct |
12 ms |
556 KB |
Output is correct |
19 |
Correct |
7 ms |
680 KB |
Output is correct |
20 |
Correct |
20 ms |
680 KB |
Output is correct |
21 |
Correct |
16 ms |
680 KB |
Output is correct |
22 |
Correct |
12 ms |
680 KB |
Output is correct |
23 |
Correct |
13 ms |
680 KB |
Output is correct |
24 |
Correct |
15 ms |
680 KB |
Output is correct |
25 |
Correct |
9 ms |
680 KB |
Output is correct |
26 |
Correct |
23 ms |
680 KB |
Output is correct |
27 |
Correct |
7 ms |
680 KB |
Output is correct |
28 |
Correct |
7 ms |
680 KB |
Output is correct |
29 |
Correct |
14 ms |
680 KB |
Output is correct |
30 |
Correct |
11 ms |
680 KB |
Output is correct |
31 |
Correct |
31 ms |
680 KB |
Output is correct |
32 |
Correct |
40 ms |
680 KB |
Output is correct |
33 |
Correct |
63 ms |
680 KB |
Output is correct |
34 |
Correct |
50 ms |
680 KB |
Output is correct |
35 |
Correct |
26 ms |
680 KB |
Output is correct |
36 |
Correct |
47 ms |
680 KB |
Output is correct |
37 |
Correct |
33 ms |
680 KB |
Output is correct |
38 |
Correct |
38 ms |
680 KB |
Output is correct |
39 |
Correct |
30 ms |
680 KB |
Output is correct |
40 |
Correct |
56 ms |
680 KB |
Output is correct |
41 |
Correct |
41 ms |
680 KB |
Output is correct |
42 |
Correct |
48 ms |
680 KB |
Output is correct |
43 |
Correct |
56 ms |
680 KB |
Output is correct |
44 |
Correct |
49 ms |
680 KB |
Output is correct |
45 |
Correct |
62 ms |
680 KB |
Output is correct |
46 |
Correct |
66 ms |
688 KB |
Output is correct |
47 |
Correct |
82 ms |
688 KB |
Output is correct |
48 |
Correct |
46 ms |
688 KB |
Output is correct |
49 |
Correct |
54 ms |
688 KB |
Output is correct |
50 |
Correct |
53 ms |
688 KB |
Output is correct |
51 |
Correct |
72 ms |
688 KB |
Output is correct |
52 |
Correct |
82 ms |
688 KB |
Output is correct |
53 |
Correct |
72 ms |
688 KB |
Output is correct |
54 |
Correct |
34 ms |
688 KB |
Output is correct |
55 |
Correct |
74 ms |
688 KB |
Output is correct |
56 |
Correct |
80 ms |
688 KB |
Output is correct |
57 |
Correct |
82 ms |
688 KB |
Output is correct |
58 |
Correct |
69 ms |
688 KB |
Output is correct |
59 |
Correct |
67 ms |
688 KB |
Output is correct |
60 |
Correct |
46 ms |
704 KB |
Output is correct |