#include "treasure.h"
#include<iostream>
using namespace std;
int ptr = 0;
bool treasure[105][105];
int dp[105][105];
int tot = 0;
int cur = 0;
bool chk(int r1, int c1, int r2, int c2) {
if (r2 < r1 || c2 < c1) return false;
return true;
}
int sum(int r1, int c1, int r2, int c2) {
return ((r2 - r1 + 1) * (c2 - c1 + 1));
}
void solve(int r1, int c1, int r2, int c2, int all) {
if ((cur == tot) || !chk(r1, c1, r2, c2)) return;
int midR = (r1 + r2) / 2;
int midC = (c1 + c2) / 2;
int LUr1 = r1;
int LUc1 = c1;
int LUr2 = midR;
int LUc2 = midC;
int LDr1 = midR + 1;
int LDc1 = c1;
int LDr2 = r2;
int LDc2 = midC;
int RUr1 = r1;
int RUc1 = midC + 1;
int RUr2 = midR;
int RUc2 = c2;
int RDr1 = midR + 1;
int RDc1 = midC + 1;
int RDr2 = r2;
int RDc2 = c2;
int LU = 0;
int LD = 0;
int RU = 0;
int RD = 0;
int LUD = 0;
int RUD = 0;
int curSum = 0;
if (all == sum(r1, c1, r2, c2)) {
for (int i = r1; i <= r2; i++) {
for (int j = c1; j <= c2; j++) {
treasure[i][j] = true;
}
}
cur += all;
curSum += all;
return;
}
//2개 계산
if (chk(r1, c1, r2, midC)) {
if (cur == tot || curSum == all) return;
LUD = countTreasure(r1, c1, r2, midC);
if (LUD == sum(r1, c1, r2, midC)) {
for (int i = r1; i <= r2; i++) {
for (int j = c1; j <= midC; j++) {
treasure[i][j] = true;
}
}
cur += LUD;
curSum += LUD;
goto MID;
}
if (LUD == 0) goto MID;
}
if (chk(LUr1, LUc1, LUr2, LUc2)) {
if (cur == tot || curSum == all) return;
LU = countTreasure(LUr1, LUc1, LUr2, LUc2);
if (LU == sum(LUr1, LUc1, LUr2, LUc2)) {
for (int i = LUr1; i <= LUr2; i++) {
for (int j = LUc1; j <= LUc2; j++) {
treasure[i][j] = true;
}
}
cur += LU;
curSum += LU;
}
else {
if (LU) {
solve(LUr1, LUc1, LUr2, LUc2, LU);
curSum += LU;
}
}
}
if (chk(LDr1, LDc1, LDr2, LDc2)) {
if (cur == tot || curSum == all) return;
LD = LUD - LU;
if (LD == sum(LDr1, LDc1, LDr2, LDc2)) {
for (int i = LDr1; i <= LDr2; i++) {
for (int j = LDc1; j <= LDc2; j++) {
treasure[i][j] = true;
}
}
cur += LD;
curSum += LD;
}
else {
if (LD) {
solve(LDr1, LDc1, LDr2, LDc2, LD);
curSum += LD;
}
}
}
MID:
if (chk(r1, midC + 1, r2, c2)) {
if (cur == tot || curSum == all) return;
RUD = all - LUD;
if (RUD == sum(r1, midC + 1, r2, c2)) {
for (int i = r1; i <= r2; i++) {
for (int j = midC + 1; j <= c2; j++) {
treasure[i][j] = true;
}
}
cur += RUD;
curSum += RUD;
return;
}
if (RUD == 0) return;
}
if (chk(RUr1, RUc1, RUr2, RUc2)) {
if (cur == tot || curSum == all) return;
RU = countTreasure(RUr1, RUc1, RUr2, RUc2);
if (RU == sum(RUr1, RUc1, RUr2, RUc2)) {
for (int i = RUr1; i <= RUr2; i++) {
for (int j = RUc1; j <= RUc2; j++) {
treasure[i][j] = true;
}
}
cur += RU;
curSum += RU;
}
else {
if (RU) {
solve(RUr1, RUc1, RUr2, RUc2, RU);
curSum += RU;
}
}
}
if (chk(RDr1, RDc1, RDr2, RDc2)) {
if (cur == tot || curSum == all) return;
RD = RUD - RU;
if (RD == sum(RDr1, RDc1, RDr2, RDc2)) {
for (int i = RDr1; i <= RDr2; i++) {
for (int j = RDc1; j <= RDc2; j++) {
treasure[i][j] = true;
}
}
cur += RD;
curSum += RD;
}
else {
if (RD) {
solve(RDr1, RDc1, RDr2, RDc2, RD);
curSum += RD;
}
}
}
}
void findTreasure(int N) {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
dp[i][j] = -1;
}
}
tot = countTreasure(1, 1, N, N);
if (tot == 0) return;
solve(1, 1, N, N, tot);
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (treasure[i][j]) {
Report(i, j);
}
}
}
}
Compilation message
grader.c: In function 'int main()':
grader.c:63:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
my_assert(strlen(A[i]+1) == N, "each line of the map must contain N zeroes or ones (before loop)");
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
248 KB |
Output is partially correct - N = 5, K = 404, score = 8 |
2 |
Partially correct |
1 ms |
352 KB |
Output is partially correct - N = 10, K = 6723, score = 4 |
3 |
Correct |
1 ms |
424 KB |
Output is correct - N = 15, K = 17208, score = 10 |
4 |
Correct |
1 ms |
440 KB |
Output is correct - N = 16, K = 14778, score = 10 |
5 |
Partially correct |
2 ms |
568 KB |
Output is partially correct - N = 55, K = 6769445, score = 4 |
6 |
Partially correct |
2 ms |
568 KB |
Output is partially correct - N = 66, K = 14160522, score = 4 |
7 |
Correct |
2 ms |
640 KB |
Output is correct - N = 77, K = 5851394, score = 10 |
8 |
Correct |
2 ms |
640 KB |
Output is correct - N = 88, K = 7511492, score = 10 |
9 |
Partially correct |
2 ms |
640 KB |
Output is partially correct - N = 99, K = 74300312, score = 1 |
10 |
Partially correct |
2 ms |
640 KB |
Output is partially correct - N = 100, K = 78198743, score = 1 |