#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
static int A[MAXN],Q2[MAXN],Q3[MAXN],freq[MAXN],N,distinct;
static void add_num(int x){
if(freq[x] == 0) distinct++;
freq[x]++;
}
int coerencia(int X){
if(abs(A[X+1] - A[X]) != Q2[X]) return 0;
if(abs(A[X+2] - A[X+1]) != Q2[X+1]) return 0;
if(max(max(A[X],A[X+1]),A[X+2]) - min(min(A[X],A[X+1]),A[X+2]) != Q3[X]) return 0;
if(max(max(A[X],A[X+1]),A[X+2]) >= N) return 0;
if(min(min(A[X],A[X+1]),A[X+2]) < 0) return 0;
if(freq[A[X]] > 1 || freq[A[X+1]] > 1 || freq[A[X+2]] > 1) return 0;
return 1;
}
void avanca_direita(int X){
if(X < 0 || X >= N) return;
//printf("AD %d\n",X);
A[X] = (A[X-1] + Q2[X-1]);
if(!coerencia(X-2)){
A[X] = (A[X-1] - Q2[X-1]);
if(!coerencia(X-2)){
//printf("Falhou\n");
return;
}
else{
//printf("Foi2 %d\n",A[X]);
add_num(A[X]);
avanca_direita(X+1);
}
}
else{
//printf("Foi1 %d\n",A[X]);
add_num(A[X]);
avanca_direita(X+1);
}
}
void avanca_esquerda(int X){
if(X < 0 || X >= N) return;
A[X] = A[X+1] + Q2[X];
if(!coerencia(X)){
A[X] = A[X+1] - Q2[X];
if(!coerencia(X)){
return;
}
else{
add_num(A[X]);
avanca_esquerda(X-1);
}
}
else{
add_num(A[X]);
avanca_esquerda(X-1);
}
}
int testa(int pos){
//printf("POS %d\n", pos);
memset(A,0,sizeof(A));
memset(freq,0,sizeof(freq));
distinct = 0;
add_num(0);
A[pos] = 0;
if(pos - 1 >= 0){
A[pos-1] = 0 + Q2[pos-1];
add_num(A[pos-1]);
}
if(pos + 1 < N){
A[pos+1] = 0 + Q2[pos];
add_num(A[pos+1]);
}
avanca_direita(pos+2);
avanca_esquerda(pos-2);
if(distinct != N){
//printf("##########\n");
return 0;
}
for(int i = 0;i<N;i++){
//printf("%d ",A[i]);
answer(i+1,A[i]+1);
}
//printf("\n");
return 1;
}
void solve(int n) {
N = n;
for(int i = 0;i+1<N;i++) Q2[i] = query(i+1,i+2);
for(int i = 0;i+2<N;i++) Q3[i] = query(i+1,i+3);
//printf("#################\n");
//for(int i = 0;i+1<N;i++){
// printf("%d ",Q2[i]);
//}
//printf("\n");
//for(int i = 0;i+1<N;i++){
// printf("%d ",Q3[i]);
//}
//printf("\n");
//printf("###################\n");
for(int i = 0;i<N;i++){
if(testa(i)){
break;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
472 KB |
Output is correct |
3 |
Correct |
4 ms |
472 KB |
Output is correct |
4 |
Correct |
4 ms |
472 KB |
Output is correct |
5 |
Correct |
5 ms |
564 KB |
Output is correct |
6 |
Correct |
5 ms |
564 KB |
Output is correct |
7 |
Correct |
4 ms |
564 KB |
Output is correct |
8 |
Correct |
5 ms |
564 KB |
Output is correct |
9 |
Correct |
5 ms |
564 KB |
Output is correct |
10 |
Correct |
5 ms |
564 KB |
Output is correct |
11 |
Correct |
4 ms |
564 KB |
Output is correct |
12 |
Correct |
4 ms |
564 KB |
Output is correct |
13 |
Correct |
4 ms |
564 KB |
Output is correct |
14 |
Correct |
2 ms |
564 KB |
Output is correct |
15 |
Correct |
2 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
472 KB |
Output is correct |
3 |
Correct |
4 ms |
472 KB |
Output is correct |
4 |
Correct |
4 ms |
472 KB |
Output is correct |
5 |
Correct |
5 ms |
564 KB |
Output is correct |
6 |
Correct |
5 ms |
564 KB |
Output is correct |
7 |
Correct |
4 ms |
564 KB |
Output is correct |
8 |
Correct |
5 ms |
564 KB |
Output is correct |
9 |
Correct |
5 ms |
564 KB |
Output is correct |
10 |
Correct |
5 ms |
564 KB |
Output is correct |
11 |
Correct |
4 ms |
564 KB |
Output is correct |
12 |
Correct |
4 ms |
564 KB |
Output is correct |
13 |
Correct |
4 ms |
564 KB |
Output is correct |
14 |
Correct |
2 ms |
564 KB |
Output is correct |
15 |
Correct |
2 ms |
564 KB |
Output is correct |
16 |
Correct |
6 ms |
564 KB |
Output is correct |
17 |
Correct |
10 ms |
568 KB |
Output is correct |
18 |
Correct |
9 ms |
568 KB |
Output is correct |
19 |
Correct |
23 ms |
568 KB |
Output is correct |
20 |
Correct |
14 ms |
568 KB |
Output is correct |
21 |
Correct |
19 ms |
696 KB |
Output is correct |
22 |
Correct |
18 ms |
696 KB |
Output is correct |
23 |
Correct |
18 ms |
696 KB |
Output is correct |
24 |
Correct |
24 ms |
696 KB |
Output is correct |
25 |
Correct |
14 ms |
696 KB |
Output is correct |
26 |
Correct |
22 ms |
696 KB |
Output is correct |
27 |
Correct |
12 ms |
696 KB |
Output is correct |
28 |
Correct |
11 ms |
696 KB |
Output is correct |
29 |
Correct |
16 ms |
696 KB |
Output is correct |
30 |
Correct |
16 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
4 ms |
472 KB |
Output is correct |
3 |
Correct |
4 ms |
472 KB |
Output is correct |
4 |
Correct |
4 ms |
472 KB |
Output is correct |
5 |
Correct |
5 ms |
564 KB |
Output is correct |
6 |
Correct |
5 ms |
564 KB |
Output is correct |
7 |
Correct |
4 ms |
564 KB |
Output is correct |
8 |
Correct |
5 ms |
564 KB |
Output is correct |
9 |
Correct |
5 ms |
564 KB |
Output is correct |
10 |
Correct |
5 ms |
564 KB |
Output is correct |
11 |
Correct |
4 ms |
564 KB |
Output is correct |
12 |
Correct |
4 ms |
564 KB |
Output is correct |
13 |
Correct |
4 ms |
564 KB |
Output is correct |
14 |
Correct |
2 ms |
564 KB |
Output is correct |
15 |
Correct |
2 ms |
564 KB |
Output is correct |
16 |
Correct |
6 ms |
564 KB |
Output is correct |
17 |
Correct |
10 ms |
568 KB |
Output is correct |
18 |
Correct |
9 ms |
568 KB |
Output is correct |
19 |
Correct |
23 ms |
568 KB |
Output is correct |
20 |
Correct |
14 ms |
568 KB |
Output is correct |
21 |
Correct |
19 ms |
696 KB |
Output is correct |
22 |
Correct |
18 ms |
696 KB |
Output is correct |
23 |
Correct |
18 ms |
696 KB |
Output is correct |
24 |
Correct |
24 ms |
696 KB |
Output is correct |
25 |
Correct |
14 ms |
696 KB |
Output is correct |
26 |
Correct |
22 ms |
696 KB |
Output is correct |
27 |
Correct |
12 ms |
696 KB |
Output is correct |
28 |
Correct |
11 ms |
696 KB |
Output is correct |
29 |
Correct |
16 ms |
696 KB |
Output is correct |
30 |
Correct |
16 ms |
696 KB |
Output is correct |
31 |
Correct |
36 ms |
696 KB |
Output is correct |
32 |
Correct |
35 ms |
696 KB |
Output is correct |
33 |
Correct |
103 ms |
696 KB |
Output is correct |
34 |
Correct |
135 ms |
696 KB |
Output is correct |
35 |
Correct |
80 ms |
696 KB |
Output is correct |
36 |
Correct |
86 ms |
696 KB |
Output is correct |
37 |
Correct |
282 ms |
712 KB |
Output is correct |
38 |
Correct |
109 ms |
712 KB |
Output is correct |
39 |
Correct |
87 ms |
712 KB |
Output is correct |
40 |
Correct |
108 ms |
712 KB |
Output is correct |
41 |
Correct |
106 ms |
712 KB |
Output is correct |
42 |
Correct |
69 ms |
712 KB |
Output is correct |
43 |
Correct |
285 ms |
712 KB |
Output is correct |
44 |
Correct |
111 ms |
712 KB |
Output is correct |
45 |
Correct |
76 ms |
712 KB |
Output is correct |
46 |
Correct |
72 ms |
712 KB |
Output is correct |
47 |
Correct |
88 ms |
712 KB |
Output is correct |
48 |
Correct |
75 ms |
712 KB |
Output is correct |
49 |
Correct |
101 ms |
712 KB |
Output is correct |
50 |
Correct |
95 ms |
712 KB |
Output is correct |
51 |
Correct |
104 ms |
712 KB |
Output is correct |
52 |
Correct |
86 ms |
712 KB |
Output is correct |
53 |
Correct |
54 ms |
724 KB |
Output is correct |
54 |
Correct |
84 ms |
724 KB |
Output is correct |
55 |
Correct |
91 ms |
724 KB |
Output is correct |
56 |
Correct |
103 ms |
724 KB |
Output is correct |
57 |
Correct |
81 ms |
724 KB |
Output is correct |
58 |
Correct |
87 ms |
724 KB |
Output is correct |
59 |
Correct |
91 ms |
724 KB |
Output is correct |
60 |
Correct |
80 ms |
724 KB |
Output is correct |