#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#include "xylophone.h"
static int A[5000];
void solve(int N){
int n = N;
int i = 1, fin = n;
while(i < fin){
int m = (i + fin) / 2;
if (query(m, n) == n - 1){
i = m + 1;
}else fin = m;
}
i--;
int reference = i;
vector<int> a(n + 1);
int x = query(i, i + 1);
a[i] = 1;
a[i + 1] = x + 1;
i += 2;
int last = x;
for (; i <= n; i++){
int mn = min(a[i - 1], a[i - 2]);
int uno = query(i - 1, i);
int dos = query(i - 2, i);
if (dos > last){
if (dos == uno){
if (a[i - 1] == mn) a[i] = a[i - 1] + uno;
else a[i] = a[i - 1] - uno;
}else{
if (a[i - 2] == mn) a[i] = a[i - 2] + dos;
else a[i] = a[i - 2] - dos;
}
}else{
if (a[i - 1] == mn) a[i] = a[i - 1] + uno;
else a[i] = a[i - 1] - uno;
}
last = uno;
}
i = reference;
if (i > 1){
x = query(i - 1, i);
a[i - 1] = 1 + x;
last = x;
i -= 2;
for (; i >= 1; i--){
int mn = min(a[i + 1], a[i + 2]);
int uno = query(i, i + 1);
int dos = query(i, i + 2);
if (dos > last){
if (dos == uno){
if (a[i + 1] == mn) a[i] = a[i + 1] + uno;
else a[i] = a[i + 1] - uno;
}else{
if (a[i + 2] == mn) a[i] = a[i + 2] + dos;
else a[i] = a[i + 2] - dos;
}
}else{
if (a[i + 1] == mn) a[i] = a[i + 1] + uno;
else a[i] = a[i + 1] - uno;
}
last = uno;
}
}
for(int i = 1;i<=n;i++) answer(i, a[i]);
return;
}
Compilation message
xylophone.cpp:8:12: warning: 'A' defined but not used [-Wunused-variable]
8 | static int A[5000];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
4 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
4 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
7 ms |
508 KB |
Output is correct |
17 |
Correct |
16 ms |
336 KB |
Output is correct |
18 |
Correct |
23 ms |
336 KB |
Output is correct |
19 |
Correct |
30 ms |
336 KB |
Output is correct |
20 |
Correct |
30 ms |
336 KB |
Output is correct |
21 |
Correct |
31 ms |
336 KB |
Output is correct |
22 |
Correct |
35 ms |
336 KB |
Output is correct |
23 |
Correct |
25 ms |
336 KB |
Output is correct |
24 |
Correct |
30 ms |
336 KB |
Output is correct |
25 |
Correct |
29 ms |
504 KB |
Output is correct |
26 |
Correct |
28 ms |
336 KB |
Output is correct |
27 |
Correct |
26 ms |
336 KB |
Output is correct |
28 |
Correct |
33 ms |
336 KB |
Output is correct |
29 |
Correct |
25 ms |
336 KB |
Output is correct |
30 |
Correct |
22 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
4 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
336 KB |
Output is correct |
8 |
Correct |
4 ms |
336 KB |
Output is correct |
9 |
Correct |
3 ms |
336 KB |
Output is correct |
10 |
Correct |
3 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
336 KB |
Output is correct |
15 |
Correct |
3 ms |
336 KB |
Output is correct |
16 |
Correct |
7 ms |
508 KB |
Output is correct |
17 |
Correct |
16 ms |
336 KB |
Output is correct |
18 |
Correct |
23 ms |
336 KB |
Output is correct |
19 |
Correct |
30 ms |
336 KB |
Output is correct |
20 |
Correct |
30 ms |
336 KB |
Output is correct |
21 |
Correct |
31 ms |
336 KB |
Output is correct |
22 |
Correct |
35 ms |
336 KB |
Output is correct |
23 |
Correct |
25 ms |
336 KB |
Output is correct |
24 |
Correct |
30 ms |
336 KB |
Output is correct |
25 |
Correct |
29 ms |
504 KB |
Output is correct |
26 |
Correct |
28 ms |
336 KB |
Output is correct |
27 |
Correct |
26 ms |
336 KB |
Output is correct |
28 |
Correct |
33 ms |
336 KB |
Output is correct |
29 |
Correct |
25 ms |
336 KB |
Output is correct |
30 |
Correct |
22 ms |
336 KB |
Output is correct |
31 |
Correct |
69 ms |
336 KB |
Output is correct |
32 |
Correct |
116 ms |
444 KB |
Output is correct |
33 |
Correct |
154 ms |
336 KB |
Output is correct |
34 |
Incorrect |
183 ms |
336 KB |
Wrong Answer [2] |
35 |
Halted |
0 ms |
0 KB |
- |