#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (int) (2 * 1e9)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 5111
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
//static int A[5000];
int ret[maxn];
bool used[maxn];
void solve(int N){
int l = 2, d = N, max_ind = -1;
while(l <= d){
int mid = (l + d) / 2;
int val = query(1, mid);
if(val == N - 1){
max_ind = mid;
d = mid - 1;
}
else
l = mid + 1;
}
ret[max_ind] = N;
used[N] = 1;
if(max_ind + 1 <= N){
int cur = query(max_ind, max_ind + 1);
ret[max_ind + 1] = N - cur;
used[N - cur] = 1;
}
if(max_ind - 1 >= 1){
int cur = query(max_ind - 1, max_ind);
ret[max_ind - 1] = N - cur;
used[N - cur] = 1;
}
for(int i = max_ind + 2; i <= N; i++){
int diff = query(i - 1, i);
int opt1 = ret[i - 1] + diff;
int opt2 = ret[i - 1] - diff;
if(opt1 < 1 || opt1 > N || used[opt1]){
ret[i] = opt2;
used[ret[i]] = 1;
continue;
}
if(opt2 < 1 || opt2 > N || used[opt2]){
ret[i] = opt1;
used[ret[i]] = 1;
continue;
}
int updown = query(i - 2, i);
if(max(ret[i - 2], max(ret[i - 1], opt1)) - min(ret[i - 2], min(ret[i - 1], opt1)) == updown){
ret[i] = opt1;
}
else
ret[i] = opt2;
used[ret[i]] = 1;
}
for(int i = max_ind - 2; i >= 1; i--){
int diff = query(i, i + 1);
int opt1 = ret[i + 1] + diff;
int opt2 = ret[i + 1] - diff;
if(opt1 < 1 || opt1 > N || used[opt1]){
ret[i] = opt2;
used[ret[i]] = 1;
continue;
}
if(opt2 < 1 || opt2 > N || used[opt2]){
ret[i] = opt1;
used[ret[i]] = 1;
continue;
}
int updown = query(i, i + 2);
if(max(ret[i + 2], max(ret[i + 1], opt1)) - min(ret[i + 2], min(ret[i + 1], opt1)) == updown){
ret[i] = opt1;
}
else
ret[i] = opt2;
used[ret[i]] = 1;
}
for(int i = 1; i <= N; i++){
answer(i, ret[i]);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
440 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
5 ms |
532 KB |
Output is correct |
7 |
Correct |
4 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
3 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
544 KB |
Output is correct |
12 |
Correct |
3 ms |
544 KB |
Output is correct |
13 |
Correct |
3 ms |
576 KB |
Output is correct |
14 |
Correct |
4 ms |
576 KB |
Output is correct |
15 |
Correct |
5 ms |
576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
440 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
5 ms |
532 KB |
Output is correct |
7 |
Correct |
4 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
3 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
544 KB |
Output is correct |
12 |
Correct |
3 ms |
544 KB |
Output is correct |
13 |
Correct |
3 ms |
576 KB |
Output is correct |
14 |
Correct |
4 ms |
576 KB |
Output is correct |
15 |
Correct |
5 ms |
576 KB |
Output is correct |
16 |
Correct |
7 ms |
576 KB |
Output is correct |
17 |
Correct |
10 ms |
576 KB |
Output is correct |
18 |
Correct |
12 ms |
576 KB |
Output is correct |
19 |
Correct |
16 ms |
588 KB |
Output is correct |
20 |
Correct |
13 ms |
588 KB |
Output is correct |
21 |
Correct |
7 ms |
588 KB |
Output is correct |
22 |
Correct |
12 ms |
588 KB |
Output is correct |
23 |
Correct |
7 ms |
588 KB |
Output is correct |
24 |
Correct |
11 ms |
588 KB |
Output is correct |
25 |
Correct |
10 ms |
588 KB |
Output is correct |
26 |
Correct |
9 ms |
588 KB |
Output is correct |
27 |
Correct |
15 ms |
588 KB |
Output is correct |
28 |
Correct |
17 ms |
588 KB |
Output is correct |
29 |
Correct |
15 ms |
588 KB |
Output is correct |
30 |
Correct |
15 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
440 KB |
Output is correct |
3 |
Correct |
2 ms |
440 KB |
Output is correct |
4 |
Correct |
3 ms |
440 KB |
Output is correct |
5 |
Correct |
3 ms |
448 KB |
Output is correct |
6 |
Correct |
5 ms |
532 KB |
Output is correct |
7 |
Correct |
4 ms |
532 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
544 KB |
Output is correct |
10 |
Correct |
3 ms |
544 KB |
Output is correct |
11 |
Correct |
4 ms |
544 KB |
Output is correct |
12 |
Correct |
3 ms |
544 KB |
Output is correct |
13 |
Correct |
3 ms |
576 KB |
Output is correct |
14 |
Correct |
4 ms |
576 KB |
Output is correct |
15 |
Correct |
5 ms |
576 KB |
Output is correct |
16 |
Correct |
7 ms |
576 KB |
Output is correct |
17 |
Correct |
10 ms |
576 KB |
Output is correct |
18 |
Correct |
12 ms |
576 KB |
Output is correct |
19 |
Correct |
16 ms |
588 KB |
Output is correct |
20 |
Correct |
13 ms |
588 KB |
Output is correct |
21 |
Correct |
7 ms |
588 KB |
Output is correct |
22 |
Correct |
12 ms |
588 KB |
Output is correct |
23 |
Correct |
7 ms |
588 KB |
Output is correct |
24 |
Correct |
11 ms |
588 KB |
Output is correct |
25 |
Correct |
10 ms |
588 KB |
Output is correct |
26 |
Correct |
9 ms |
588 KB |
Output is correct |
27 |
Correct |
15 ms |
588 KB |
Output is correct |
28 |
Correct |
17 ms |
588 KB |
Output is correct |
29 |
Correct |
15 ms |
588 KB |
Output is correct |
30 |
Correct |
15 ms |
588 KB |
Output is correct |
31 |
Correct |
28 ms |
600 KB |
Output is correct |
32 |
Correct |
52 ms |
600 KB |
Output is correct |
33 |
Correct |
63 ms |
600 KB |
Output is correct |
34 |
Correct |
63 ms |
600 KB |
Output is correct |
35 |
Correct |
55 ms |
716 KB |
Output is correct |
36 |
Correct |
43 ms |
720 KB |
Output is correct |
37 |
Correct |
27 ms |
720 KB |
Output is correct |
38 |
Correct |
67 ms |
720 KB |
Output is correct |
39 |
Correct |
34 ms |
720 KB |
Output is correct |
40 |
Correct |
59 ms |
720 KB |
Output is correct |
41 |
Correct |
74 ms |
720 KB |
Output is correct |
42 |
Correct |
60 ms |
720 KB |
Output is correct |
43 |
Correct |
50 ms |
720 KB |
Output is correct |
44 |
Correct |
41 ms |
720 KB |
Output is correct |
45 |
Correct |
59 ms |
720 KB |
Output is correct |
46 |
Correct |
30 ms |
720 KB |
Output is correct |
47 |
Correct |
62 ms |
720 KB |
Output is correct |
48 |
Correct |
60 ms |
720 KB |
Output is correct |
49 |
Correct |
91 ms |
720 KB |
Output is correct |
50 |
Correct |
30 ms |
720 KB |
Output is correct |
51 |
Correct |
63 ms |
720 KB |
Output is correct |
52 |
Correct |
56 ms |
720 KB |
Output is correct |
53 |
Correct |
28 ms |
720 KB |
Output is correct |
54 |
Correct |
55 ms |
720 KB |
Output is correct |
55 |
Correct |
53 ms |
720 KB |
Output is correct |
56 |
Correct |
34 ms |
720 KB |
Output is correct |
57 |
Correct |
52 ms |
720 KB |
Output is correct |
58 |
Correct |
51 ms |
720 KB |
Output is correct |
59 |
Correct |
62 ms |
720 KB |
Output is correct |
60 |
Correct |
55 ms |
720 KB |
Output is correct |