#include<bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include "xylophone.h"
using namespace std;
static const int N_MAX = 5000;
static const int Q_MAX = 10100;
static int N;
static int A[N_MAX];
static bool used[N_MAX];
static int query_c;
static int answer_c;
void solve(int N) {
vector<int> v(N+1, 0);
int l = 2, r = N;
int rez = -1;
if(query(1, N-1)!=N-1) rez = N;
else{
while(l<=r){
int mid = (l+r)/2;
if(query(1, mid)!=N-1){
l = mid+1;
} else{
rez = mid;
r = mid-1;
}
}
}
answer(rez, N);
v[rez] = N;
if(rez!=1){
int x = N-query(rez-1, rez);
answer(rez-1, x);
v[rez-1] = x;
}
if(rez!=N){
int x = N-query(rez, rez+1);
answer(rez+1, x);
v[rez+1] = x;
}
for(int i = rez-2;i>=1;i--){
int d1 = query(i, i+1);
if(d1>v[i+1]){
v[i] = v[i+1]+d1;
answer(i, v[i]);
continue;
}
if(v[i+1]+d1>=N){
v[i] = v[i+1]-d1;
answer(i, v[i]);
continue;
}
int d2 = query(i, i+2);
int ans = 0;
if(v[i+1]>v[i+2]){
if(d1+v[i+1]-v[i+2]==d2) ans = v[i+1]+d1;
else ans = v[i+1]-d1;
} else{
if(d1+v[i+2]-v[i+1]==d2) ans = v[i+1]-d1;
else ans = v[i+1]+d1;
}
answer(i, ans);
v[i] = ans;
}
for(int i = rez+2;i<=N;i++){
int d1 = query(i-1, i);
if(d1>v[i-1]){
v[i] = v[i-1]+d1;
answer(i, v[i]);
continue;
}
if(v[i-1]+d1>=N){
v[i] = v[i-1]-d1;
answer(i, v[i]);
continue;
}
int d2 = query(i-2, i);
int ans = 0;
if(v[i-1]>v[i-2]){
if(d1+v[i-1]-v[i-2]==d2) ans = v[i-1]+d1;
else ans = v[i-1]-d1;
} else{
if(d1+v[i-2]-v[i-1]==d2) ans = v[i-1]-d1;
else ans = v[i-1]+d1;
}
answer(i, ans);
v[i] = ans;
}
}
Compilation message
xylophone.cpp:14:12: warning: 'answer_c' defined but not used [-Wunused-variable]
14 | static int answer_c;
| ^~~~~~~~
xylophone.cpp:13:12: warning: 'query_c' defined but not used [-Wunused-variable]
13 | static int query_c;
| ^~~~~~~
xylophone.cpp:12:13: warning: 'used' defined but not used [-Wunused-variable]
12 | static bool used[N_MAX];
| ^~~~
xylophone.cpp:11:12: warning: 'A' defined but not used [-Wunused-variable]
11 | static int A[N_MAX];
| ^
xylophone.cpp:10:12: warning: 'N' defined but not used [-Wunused-variable]
10 | static int N;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 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 |
596 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 |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 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 |
596 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 |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
21 |
Correct |
8 ms |
344 KB |
Output is correct |
22 |
Correct |
7 ms |
344 KB |
Output is correct |
23 |
Correct |
11 ms |
344 KB |
Output is correct |
24 |
Correct |
6 ms |
344 KB |
Output is correct |
25 |
Correct |
7 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 |
7 ms |
344 KB |
Output is correct |
29 |
Correct |
7 ms |
344 KB |
Output is correct |
30 |
Correct |
7 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 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 |
596 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 |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
6 ms |
344 KB |
Output is correct |
18 |
Correct |
6 ms |
344 KB |
Output is correct |
19 |
Correct |
7 ms |
344 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
21 |
Correct |
8 ms |
344 KB |
Output is correct |
22 |
Correct |
7 ms |
344 KB |
Output is correct |
23 |
Correct |
11 ms |
344 KB |
Output is correct |
24 |
Correct |
6 ms |
344 KB |
Output is correct |
25 |
Correct |
7 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 |
7 ms |
344 KB |
Output is correct |
29 |
Correct |
7 ms |
344 KB |
Output is correct |
30 |
Correct |
7 ms |
344 KB |
Output is correct |
31 |
Correct |
16 ms |
344 KB |
Output is correct |
32 |
Correct |
24 ms |
344 KB |
Output is correct |
33 |
Correct |
39 ms |
344 KB |
Output is correct |
34 |
Correct |
37 ms |
344 KB |
Output is correct |
35 |
Correct |
43 ms |
344 KB |
Output is correct |
36 |
Correct |
55 ms |
344 KB |
Output is correct |
37 |
Correct |
35 ms |
344 KB |
Output is correct |
38 |
Correct |
37 ms |
344 KB |
Output is correct |
39 |
Correct |
55 ms |
344 KB |
Output is correct |
40 |
Correct |
50 ms |
344 KB |
Output is correct |
41 |
Correct |
28 ms |
344 KB |
Output is correct |
42 |
Correct |
61 ms |
344 KB |
Output is correct |
43 |
Correct |
38 ms |
344 KB |
Output is correct |
44 |
Correct |
46 ms |
344 KB |
Output is correct |
45 |
Correct |
63 ms |
344 KB |
Output is correct |
46 |
Correct |
58 ms |
344 KB |
Output is correct |
47 |
Correct |
57 ms |
344 KB |
Output is correct |
48 |
Correct |
52 ms |
340 KB |
Output is correct |
49 |
Correct |
52 ms |
344 KB |
Output is correct |
50 |
Correct |
46 ms |
344 KB |
Output is correct |
51 |
Correct |
48 ms |
344 KB |
Output is correct |
52 |
Correct |
39 ms |
344 KB |
Output is correct |
53 |
Correct |
45 ms |
344 KB |
Output is correct |
54 |
Correct |
53 ms |
344 KB |
Output is correct |
55 |
Correct |
34 ms |
344 KB |
Output is correct |
56 |
Correct |
50 ms |
344 KB |
Output is correct |
57 |
Correct |
41 ms |
344 KB |
Output is correct |
58 |
Correct |
47 ms |
344 KB |
Output is correct |
59 |
Correct |
41 ms |
344 KB |
Output is correct |
60 |
Correct |
42 ms |
344 KB |
Output is correct |