#include "treasure.h"
bool visit[101][101];
void check(int a, int b, int c, int d) {
for (int i = a; i <= c; i++) {
for (int j = b; j <= d; j++) {
visit[i][j] = 1;
}
}
}
void go(int a, int b, int N, int C) {
int M = N % 2 == 0 ? N / 2 : (N / 2) + 1;
if (M == 1) {
if (countTreasure(a, b, a, b) == 1) {
visit[a][b] = 1;
C--;
if (C == 0)return;
}
if (countTreasure(a + 1, b, a + 1, b) == 1) {
visit[a + 1][b] = 1;
C--;
if (C == 0)return;
}
if (countTreasure(a, b + 1, a, b + 1) == 1) {
visit[a][b + 1] = 1;
C--;
if (C == 0)return;
}
if (countTreasure(a + 1, b + 1, a + 1, b + 1) == 1) {
visit[a + 1][b + 1] = 1;
C--;
if (C == 0)return;
}
return;
}
if (N % 2 == 0) {
int cnt = countTreasure(a, b, a + M - 1, b + M - 1);
if (cnt == M * M) check(a, b, a + M - 1, b + M - 1);
else if(cnt != 0)go(a, b, M,cnt);
cnt = countTreasure(a + M, b, a + (2 * M) - 1, b + M - 1);
if (cnt == M * M) check(a + M, b, a + (2 * M) - 1, b + M - 1);
else if (cnt != 0)go(a + M, b, M, cnt);
cnt = countTreasure(a, b + M, a + M - 1, b + (2 * M) - 1);
if (cnt == M * M) check(a, b + M, a + M - 1, b + (2 * M) - 1);
else if (cnt != 0)go(a, b + M, M, cnt);
cnt = countTreasure(a + M, b + M, a + (2 * M) - 1, b + (2 * M) - 1);
if (cnt == M * M) check(a + M, b + M, a + (2 * M) - 1, b + (2 * M) - 1);
else if (cnt != 0)go(a + M, b + M, M, cnt);
}
else {
int cnt = countTreasure(a, b, a + M - 1, b + M - 1);
if (cnt == M * M) check(a, b, a + M - 1, b + M - 1);
else if (cnt != 0)go(a, b, M, cnt);
cnt = countTreasure(a + M - 1, b, a + (2 * M) - 2, b + M - 1);
if (cnt == M * M) check(a + M - 1, b, a + (2 * M) - 2, b + M - 1);
else if (cnt != 0)go(a + M - 1, b, M, cnt);
cnt = countTreasure(a, b + M - 1, a + M - 1, b + (2 * M) - 2);
if (cnt == M * M) check(a, b + M - 1, a + M - 1, b + (2 * M) - 2);
else if (cnt != 0)go(a, b + M - 1, M, cnt);
cnt = countTreasure(a + M - 1, b + M - 1, a + (2 * M) - 2, b + (2 * M) - 2);
if (cnt == M * M) check(a + M - 1, b + M - 1, a + (2 * M) - 2, b + (2 * M) - 2);
else if (cnt != 0)go(a + M - 1, b + M - 1, M, cnt);
}
}
void findTreasure(int N) {
int cnt = countTreasure(1, 1, N, N);
if (cnt == 0) return;
else if (cnt == N * N) {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
Report(i, j);
}
}
}
else {
go(1, 1, N,cnt);
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (visit[i][j] == 1) Report(i, j);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct - N = 5, K = 1671, score = 0 |
2 |
Incorrect |
2 ms |
384 KB |
Output isn't correct - N = 10, K = 24885, score = 0 |
3 |
Partially correct |
2 ms |
256 KB |
Output is partially correct - N = 15, K = 26389, score = 8 |
4 |
Correct |
3 ms |
384 KB |
Output is correct - N = 16, K = 26269, score = 10 |
5 |
Incorrect |
2 ms |
384 KB |
Output isn't correct - N = 55, K = 12567765, score = 0 |
6 |
Incorrect |
3 ms |
384 KB |
Output isn't correct - N = 66, K = 74943553, score = 0 |
7 |
Partially correct |
3 ms |
384 KB |
Output is partially correct - N = 77, K = 20063662, score = 4 |
8 |
Correct |
3 ms |
640 KB |
Output is correct - N = 88, K = 20362957, score = 10 |
9 |
Incorrect |
2 ms |
384 KB |
Output isn't correct - N = 99, K = 166399318, score = 0 |
10 |
Incorrect |
3 ms |
384 KB |
Output isn't correct - N = 100, K = 168129333, score = 0 |