#include "treasure.h"
#include <queue>
#include <utility>
#include <vector>
#include <iostream>
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 });
vector<pair<int, int>> result;
while (cnt) {
vector<int> tmp;
tmp = q.front();
if (tmp[1] == tmp[3] && tmp[0] == tmp[2]) {
cnt--;
result.push_back(make_pair(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;
}
}
for (int i = 0; i < result.size(); i++) {
Report(result[i].first, result[i].second);
}
}
Compilation message
treasure.cpp: In function 'void findTreasure(int)':
treasure.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < result.size(); i++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 11 |
2 |
Incorrect |
1 ms |
364 KB |
Error - check the range of the parameters of countTreasure() : r1 = 4161291, c1 = 0, r2 = 5, c2 = 5 |
3 |
Incorrect |
1 ms |
364 KB |
Error - check the range of the parameters of countTreasure() : r1 = 4161181, c1 = 0, r2 = 8, c2 = 11 |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
5 |
Incorrect |
1 ms |
364 KB |
Error - check the range of the parameters of countTreasure() : r1 = 8326688, c1 = 28, r2 = 25, c2 = 54 |
6 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 11 |
7 |
Incorrect |
1 ms |
364 KB |
Error - check the range of the parameters of countTreasure() : r1 = 8323777, c1 = 0, r2 = 8326080, c2 = 0 |
8 |
Incorrect |
1 ms |
364 KB |
Error - check the range of the parameters of countTreasure() : r1 = 8326368, c1 = 24, r2 = 44, c2 = 46 |
9 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 |
10 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 |