# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
39400 | ykmyou | Treasure (different grader from official contest) (CEOI13_treasure2) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "stdafx.h"
#include "treasure.h"
int cand[8] = {1, 2, 4, 8, 16, 32, 64, 128 };
int chk[129][129], nrow[129], ncol[129];
int isTresure[129][129];
int size;
void dnc(int r, int c, int nr, int nc) {
if (nr < 1 || nc < 1) return;
int num = 0;
if (nrow[r] > 0 || ncol[c] > 0)
num = countTreasure(r, c, r + nr - 1, c + nc - 1);
if (num == nr * nc) {
for (int i = r; i < r + nr; i++) {
for (int j = c; j < c + nc; j++) {
isTresure[i][j] = 1;
chk[i][j] = 1;
}
}
return;
}
if (nr < nc) {
dnc(r, c, nr, nc / 2);
dnc(r, c + nc / 2, nr, nc / 2);
}
else {
dnc(r, c, nr / 2, nc);
dnc(r + nr / 2, c, nr / 2, nc);
}
}
int getSize(int n){
for (int i = 0; i < 7; i++) {
if (cand[i] < n && n <= cand[i + 1]) {
return cand[i + 1];
}
}
return n;
}
void init(int n) {
size = getSize(n);
for (int i = 1; i <= size; i++) {
ncol[i] = nrow[i] = 0;
if (n < i) continue;
ncol[i] = countTreasure(i, 1, i, n);
nrow[i] = countTreasure(1, i, n, i);;
}
}
void findTreasure (int N) {
init(N);
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (nrow[i] == 0 && ncol[j] == 0)
continue;
if (chk[i][j]) continue;
chk[i][j] = 1;
int rs = getSize(N - i + 1);
int cs = getSize(N - j + 1);
int s = rs < cs ? rs : cs;
dnc(i, j, s, s);
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (isTresure[i][j]) Report(i, j);
}
}
}