#include "dowsing.h"
#include <stdio.h>
void FindTreasure(int N) {
int find = 0;
int findX[10];
int findY[10];
int targetX = 0;
int targetY = 0;
int half = (N) / 2 + 1;
for(int i = half; i <= N; i++) {
// printf("%d %d\n", i, i - half + 1);
int r = Detect(i, i - half + 1);
if(r) {
findX[find] = i;
findY[find] = i - half + 1;
find++;
}
r = Detect(i - half + 1, i);
if(r) {
findX[find] = i - half + 1;;
findY[find] = i;
find++;
}
}
// printf("%d \n", find);
if(find == 0) {
int r = 0;
for(int i = 0; i < half - 2; i++) {
r = Detect(i+1, i+1);
if(r) {
targetX = i+1;
targetY = i+1;
break;
}
}
if(N % 2 && r == 0) {
r = Detect(half-1, half-1);
if(r) {
targetX = half-1;
targetY = half-1;
}
}
if( r == 0) {
if(N % 2) {
targetX = half;
targetY = half;
} else {
targetX = half-1;
targetY = half-1;
}
}
r = Detect(targetX+1, targetY);
if(r) {
Report(targetY >= half ? targetY - half + 1 : half + targetY - 1, targetY);
} else {
Report(targetX, targetX >= half ? targetX - half + 1 : half + targetX - 1);
}
return;
} else if ( find == 1 ) {
if(findX[0] == 1 || findX[0] == N) {
Report(N + 1 - findX[0], findY[0]);
} else {
Report(findX[0], N + 1 - findY[0]);
}
} else if ( find == 2 ) {
if( findX[0] != 1 && findX[0] != N) {
int r = Detect(findX[0]+1, findY[0]);
r |= Detect(findX[0]-1, findY[0]);
if(r == 0) {
Report(findX[0], findY[1]);
} else {
Report(findX[1], findY[0]);
}
} else {
int r = Detect(findX[0], findY[0]+1);
r |= Detect(findX[0], findY[0]-1);
if(r == 0) {
Report(findX[1], findY[0]);
} else {
Report(findX[0], findY[1]);
}
}
return;
} else if ( find == 3 ) {
if(findX[0] == findX[2]) {
Report(findX[0], findY[1]);
} else {
Report(findX[1], findY[0]);
}
return;
} else if ( find == 4 ) {
Report(half, half);
return;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Correct : C = 4 |
2 |
Correct |
0 ms |
364 KB |
Correct : C = 4 |
3 |
Correct |
1 ms |
364 KB |
Correct : C = 150 |
4 |
Correct |
1 ms |
364 KB |
Correct : C = 150 |
5 |
Correct |
2 ms |
364 KB |
Correct : C = 150 |
6 |
Correct |
2 ms |
364 KB |
Correct : C = 150 |
7 |
Correct |
2 ms |
356 KB |
Correct : C = 150 |
8 |
Correct |
1 ms |
364 KB |
Correct : C = 150 |
9 |
Correct |
1 ms |
364 KB |
Correct : C = 150 |
10 |
Correct |
1 ms |
364 KB |
Correct : C = 102 |
11 |
Correct |
1 ms |
364 KB |
Correct : C = 102 |
12 |
Correct |
1 ms |
364 KB |
Correct : C = 102 |