#include "treasure.h"
#include <queue>
#include <utility>
#include <vector>
using namespace std;
void findTreasure (int N) {
int dir = 0;
int cnt = countTreasure(1, 1, N, N);
if (cnt == 0) {
return;
}
queue<vector<int>> q;
q.push({ 1, 1, N, N });
while (cnt) {
vector<int> tmp;
tmp = q.front();
if (tmp[1] == tmp[3] && tmp[0] == tmp[2]) {
cnt--;
Report(tmp[0], tmp[1]);
}
q.pop();
if (dir && tmp[1] != tmp[3]) {
int mid = (tmp[1] + tmp[3]) / 2;
if (countTreasure(tmp[0], mid + 1, tmp[2], tmp[3])) {
q.push({ tmp[0], mid + 1, tmp[2], tmp[3] });
}
if (countTreasure(tmp[0], tmp[1], tmp[2], mid)) {
q.push({ tmp[0], tmp[1], tmp[2], mid });
}
dir = 0;
}
else if(!dir && tmp[0] != tmp[2]) {
int mid = (tmp[0] + tmp[2]) / 2;
if (countTreasure(mid + 1, tmp[1], tmp[2], tmp[3])) {
q.push({ mid + 1, tmp[1], tmp[2], tmp[3] });
}
if (countTreasure(mid + 1, tmp[1], tmp[2], tmp[3])) {
q.push({ tmp[0], tmp[1], mid, tmp[3] });
}
dir = 1;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
364 KB |
Execution killed with signal 11 |
2 |
Incorrect |
0 ms |
364 KB |
Error - no treasure at (r, c) : r = 4, c = 10 |
3 |
Incorrect |
0 ms |
364 KB |
Error - you cannot call countTreasure() after calling Report() |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
5 |
Incorrect |
1 ms |
364 KB |
Error - you cannot call countTreasure() after calling Report() |
6 |
Incorrect |
1 ms |
364 KB |
Error - you cannot call countTreasure() after calling Report() |
7 |
Incorrect |
1 ms |
364 KB |
Error - you cannot call countTreasure() after calling Report() |
8 |
Incorrect |
1 ms |
364 KB |
Error - you cannot call countTreasure() after calling Report() |
9 |
Incorrect |
1 ms |
364 KB |
Error - you cannot call countTreasure() after calling Report() |
10 |
Incorrect |
1 ms |
364 KB |
Error - you cannot call countTreasure() after calling Report() |