#include "xylophone.h"
int diff2[5555], diff3[5555], ans[5555];
bool please_do_it(int idx, int N){
ans[idx] = N;
if( idx != 1 )
ans[idx-1] = N - diff2[idx-1];
if( idx != N )
ans[idx+1] = N - diff2[idx];
for( int i = idx-2; i >= 1; i -- ){
int val1 = diff2[i];
int val2 = diff3[i];
if( ans[i+1] < ans[i+2] ){
if( ans[i+2]-ans[i+1] > val1 and val2 == ans[i+2] - ans[i+1]){
ans[i] = ans[i+1] + val1;
}
else if( val2 > val1 ){
ans[i] = ans[i+1] - val1;
}
else{
ans[i] = ans[i+1] + val1;
}
}else{
if( ans[i+1]-ans[i+2] > val1 and val2 == ans[i+1] - ans[i+2]){
ans[i] = ans[i+1] - val1;
}
else if( val2 > val1 ){
ans[i] = ans[i+1] + val1;
}
else{
ans[i] = ans[i+1] - val1;
}
}
}
for( int i = idx+2; i <= N; i ++ ){
int val1 = diff2[i-1];
int val2 = diff3[i-2];
if( ans[i-2] > ans[i-1] ){
if( ans[i-2] - ans[i-1] > val1 and val2 == ans[i-2] - ans[i-1]){
ans[i] = ans[i-1] + val1;
}
else if( val2 > val1 ){
ans[i] = ans[i-1] - val1;
}else{
ans[i] = ans[i-1] + val1;
}
}else{
if( ans[i-1]-ans[i-2] > val1 and val2 == ans[i-1] - ans[i-2] ){
ans[i] = ans[i-1] - val1;
}
else if( val2 > val1 ){
ans[i] = ans[i-1] + val1;
}else{
ans[i] = ans[i-1] - val1;
}
}
}
int cnt[5555] = {}, one = false;
for( int i = 1; i <= N; i ++ ){
cnt[ans[i]] ++;
if( cnt[ans[i]]>1 || ans[i] > N || ans[i] < 1){
return false;
}
if( ans[i] == 1 )one = true;
if( ans[i] == N && !one )return false;
}
return true;
}
void solve(int N) {
for( int i = 1; i <= N-1; i ++ ){
diff2[i] = query(i, i+1);
}
for( int i = 1; i <= N-2; i ++ ){
diff3[i] = query(i, i + 2 );
}
for( int i = 1; i <= N; i ++ ){
if( please_do_it(i, N) ){
/*
for( int i = 1; i <= N; i ++ ){
printf("%d ", ans[i]);
}printf("\n");
*/
for( int i = 1; i <= N; i ++ ){
answer(i, ans[i]);
}
return;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
7 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
256 KB |
Output is correct |
6 |
Correct |
6 ms |
256 KB |
Output is correct |
7 |
Correct |
7 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
256 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
7 ms |
256 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
8 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
7 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
256 KB |
Output is correct |
6 |
Correct |
6 ms |
256 KB |
Output is correct |
7 |
Correct |
7 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
256 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
7 ms |
256 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
8 ms |
256 KB |
Output is correct |
16 |
Correct |
10 ms |
384 KB |
Output is correct |
17 |
Correct |
16 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
376 KB |
Output is correct |
19 |
Correct |
25 ms |
376 KB |
Output is correct |
20 |
Correct |
28 ms |
376 KB |
Output is correct |
21 |
Correct |
28 ms |
364 KB |
Output is correct |
22 |
Correct |
25 ms |
376 KB |
Output is correct |
23 |
Correct |
28 ms |
376 KB |
Output is correct |
24 |
Correct |
28 ms |
384 KB |
Output is correct |
25 |
Correct |
21 ms |
384 KB |
Output is correct |
26 |
Correct |
31 ms |
376 KB |
Output is correct |
27 |
Correct |
17 ms |
368 KB |
Output is correct |
28 |
Correct |
27 ms |
480 KB |
Output is correct |
29 |
Correct |
32 ms |
376 KB |
Output is correct |
30 |
Correct |
26 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
7 ms |
256 KB |
Output is correct |
5 |
Correct |
7 ms |
256 KB |
Output is correct |
6 |
Correct |
6 ms |
256 KB |
Output is correct |
7 |
Correct |
7 ms |
384 KB |
Output is correct |
8 |
Correct |
7 ms |
256 KB |
Output is correct |
9 |
Correct |
7 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
7 ms |
256 KB |
Output is correct |
13 |
Correct |
7 ms |
256 KB |
Output is correct |
14 |
Correct |
7 ms |
384 KB |
Output is correct |
15 |
Correct |
8 ms |
256 KB |
Output is correct |
16 |
Correct |
10 ms |
384 KB |
Output is correct |
17 |
Correct |
16 ms |
376 KB |
Output is correct |
18 |
Correct |
21 ms |
376 KB |
Output is correct |
19 |
Correct |
25 ms |
376 KB |
Output is correct |
20 |
Correct |
28 ms |
376 KB |
Output is correct |
21 |
Correct |
28 ms |
364 KB |
Output is correct |
22 |
Correct |
25 ms |
376 KB |
Output is correct |
23 |
Correct |
28 ms |
376 KB |
Output is correct |
24 |
Correct |
28 ms |
384 KB |
Output is correct |
25 |
Correct |
21 ms |
384 KB |
Output is correct |
26 |
Correct |
31 ms |
376 KB |
Output is correct |
27 |
Correct |
17 ms |
368 KB |
Output is correct |
28 |
Correct |
27 ms |
480 KB |
Output is correct |
29 |
Correct |
32 ms |
376 KB |
Output is correct |
30 |
Correct |
26 ms |
376 KB |
Output is correct |
31 |
Correct |
75 ms |
384 KB |
Output is correct |
32 |
Runtime error |
78 ms |
484 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
33 |
Halted |
0 ms |
0 KB |
- |