QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#32689 | #2567. Hidden Rook | YaoBIG# | AC ✓ | 454ms | 3644kb | C++20 | 3.1kb | 2022-05-22 23:26:48 | 2022-05-22 23:26:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int unsafeAsk(int y0, int y1, int x0, int x1) {
cout << "? " << y0 + 1 << ' ' << x0 + 1 << ' ' << y1 + 1 << ' ' << x1 + 1 << endl;
int res;
cin >> res;
return res;
}
pair<int, int> ask(int y0, int y1, int x0, int x1) {
int dy = y1 - y0 + 1;
int dx = x1 - x0 + 1;
assert(dx != dy);
assert(dy != 1 && dx != 1);
int res = unsafeAsk(y0, y1, x0, x1);
if (res == dy) return {0, 1};
else if (res == dx) return {1, 0};
else if (res > 0) return {1, 1};
else return {0, 0};
}
void answer(int y, int x) {
cout << "! " << y + 1 << ' ' << x + 1 << endl;
}
void update(int& y0, int& y1, int& x0, int& x1, int qy0, int qy1, int qx0, int qx1) {
auto ans = ask(qy0, qy1, qx0, qx1);
if (ans.first) {
y0 = max(y0, qy0);
y1 = min(y1, qy1);
} else {
if (y0 < qy0) y1 = qy0 - 1;
else y0 = qy1 + 1;
}
if (ans.second) {
x0 = max(x0, qx0);
x1 = min(x1, qx1);
} else {
if (x0 < qx0) x1 = qx0 - 1;
else x0 = qx1 + 1;
}
}
void solve() {
int h, w;
cin >> h >> w;
// Query rectangle has equal height and width: problem
// Query rectangle has width or height equal to 1: problem
// If height AND width <= 4:
// Special case these
// If height != width:
// Always ask either some prefix, or some suffix, both of length >= 2
// If height == width:
// Always ask either some prefix, some suffix, or some prefix or suffix missing the first position
int y0 = 0, y1 = h - 1;
int x0 = 0, x1 = w - 1;
if (h <= 4 && w <= 4) {
for (int j = 0; j < 2; ++j) {
int ym = (y0 + y1) / 2;
int cou = unsafeAsk(y0, ym, 0, w - 1);
if (cou == (ym - y0) + w) y1 = ym;
else y0 = ym + 1;
}
for (int j = 0; j < 2; ++j) {
int xm = (x0 + x1) / 2;
int cou = unsafeAsk(0, h - 1, x0, xm);
if (cou == (xm - x0) + h) x1 = xm;
else x0 = xm + 1;
}
} else {
while(y0 != y1 || x0 != x1) {
int ym = (y1 + y0) / 2;
int xm = (x1 + x0) / 2;
vector<pair<int, int>> qy_opts, qx_opts;
if (ym > 0) qy_opts.emplace_back(0, ym);
if (y0 > 0 && ym > 1) qy_opts.emplace_back(1, ym);
if (ym + 1 < h - 1) qy_opts.emplace_back(ym + 1, h - 1);
if (ym + 2 < h - 1 && y1 < h - 1) qy_opts.emplace_back(ym + 1, h - 2);
if (xm > 0) qx_opts.emplace_back(0, xm);
if (x0 > 0 && xm > 1) qx_opts.emplace_back(1, xm);
if (xm + 1 < w - 1) qx_opts.emplace_back(xm + 1, w - 1);
if (xm + 2 < w - 1 && x1 < w - 1) qx_opts.emplace_back(xm + 1, w - 2);
if (y0 == 0 && y1 == h - 1 && x0 == 0 && x1 == w - 1 && h == w) {
qy_opts.emplace_back(0, ym + 1);
}
bool found = 0;
for (auto qy : qy_opts) {
for (auto qx : qx_opts) {
if (qy.second - qy.first != qx.second - qx.first) {
update(y0, y1, x0, x1, qy.first, qy.second, qx.first, qx.second);
found = 1;
}
if (found) break;
}
if (found) break;
}
}
}
answer(y0, x0);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int ti = 0; ti < t; ++ti) solve();
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 3536kb
input:
2 6 6 6 5 7 7 5 3 5 6
output:
? 1 1 4 3 ? 1 3 2 6 ? 2 1 6 3 ! 2 3 ? 1 1 4 3 ? 1 1 2 4 ? 2 1 7 4 ! 1 4
result:
ok Good (2 test cases)
Test #2:
score: 0
Accepted
time: 3ms
memory: 3484kb
input:
3 15 15 7 14 6 20 3 15 8 13 10 11 15 15 14 4 15 13
output:
? 1 9 8 15 ? 1 5 4 15 ? 1 1 2 6 ? 2 1 15 7 ! 2 7 ? 1 1 2 8 ? 2 1 3 12 ? 1 1 2 10 ? 1 1 2 11 ! 2 12 ? 1 9 8 15 ? 1 1 4 12 ? 1 1 6 10 ? 1 1 5 9 ! 5 9
result:
ok Good (3 test cases)
Test #3:
score: 0
Accepted
time: 16ms
memory: 3604kb
input:
100 6 6 6 2 3 3 4 2 4 4 3 7 8 0 0 7 5 6 3 0 9 4 5 9 7 11 4 6 3 3 3 15 12 8 3 14 4 5 9 7 0 6 6 7 3 6 4 9 9 4 6 2 11 4 6 3 3 3 12 7 4 0 5 14 7 0 11 17 12 9 6 0 11 6 12 11 0 9 0 3 14 7 12 9 10 15 12 0 20 10 17 7 10 8 0 0 15 5 0 0 18 17 11 9 5 9 7 15 14 7 4 9 6 13 15 10 0 12 20 18 7 4 4 6 5 13 7 10 15 1...
output:
? 1 1 4 3 ? 1 3 2 6 ? 1 2 3 3 ! 4 3 ? 1 1 2 4 ? 3 1 3 4 ? 1 1 3 2 ? 1 1 3 1 ! 3 1 ? 5 1 7 4 ? 1 1 2 6 ? 1 1 3 7 ! 3 8 ? 4 1 5 3 ? 1 1 4 5 ! 5 6 ? 1 1 5 2 ? 1 2 7 4 ? 1 1 6 2 ! 6 2 ? 1 1 6 2 ? 1 2 9 4 ? 1 2 8 4 ? 1 2 7 4 ! 7 1 ? 1 1 8 6 ? 1 1 12 3 ? 1 1 10 5 ? 1 1 9 4 ! 9 5 ? 1 1 3 5 ? 1 1 2 3 ? 1 1 ...
result:
ok Good (100 test cases)
Test #4:
score: 0
Accepted
time: 7ms
memory: 3500kb
input:
50 9 8 0 7 8 4 11 0 3 11 10 9 11 6 11 2 7 13 8 4 6 2 9 4 15 8 0 3 3 8 9 4 6 0 11 12 10 0 10 4 11 14 0 0 22 12 14 14 0 11 21 19 8 3 5 0 0 6 7 6 5 5 4 12 6 3 3 0 6 4 4 4 5 9 15 0 7 0 19 12 7 9 0 5 13 14 12 4 14 5 12 11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5 4 15 ? 1 1 5 2 ? 1 1 ...
result:
ok Good (50 test cases)
Test #6:
score: 0
Accepted
time: 20ms
memory: 3644kb
input:
50 14 14 7 14 0 12 6 3 0 5 13 6 0 14 12 11 11 13 7 3 13 8 9 4 6 4 7 9 10 12 6 3 0 3 12 0 9 13 10 12 5 0 4 12 11 13 4 8 3 0 2 9 9 5 6 0 10 6 0 5 7 3 5 3 4 6 12 8 0 5 7 9 0 6 12 10 11 5 3 0 8 5 6 3 4 5 4 3 0 7 5 4 7 8 13 4 8 6 11 13 5 14 9 0 8 5 4 13 7 0 3 0 5 13 3 9 5 12 10 5 5 2 9 8 9 8 0 7 0 4 12 2...
output:
? 1 1 8 7 ? 1 1 4 11 ? 1 1 2 9 ? 1 1 3 10 ! 3 10 ? 1 1 3 2 ? 1 1 5 3 ! 6 3 ? 1 1 7 3 ? 1 1 10 5 ? 1 1 9 4 ? 1 1 8 4 ! 8 4 ? 1 1 6 7 ? 1 1 3 10 ? 1 1 5 9 ? 1 1 4 8 ! 4 9 ? 1 1 5 2 ? 1 2 3 3 ? 3 1 9 2 ? 2 1 9 2 ! 2 2 ? 1 1 5 6 ? 1 1 3 9 ? 1 1 4 8 ! 5 9 ? 1 1 2 6 ? 1 1 3 9 ? 1 1 3 11 ? 1 1 3 10 ! 3 11 ...
result:
ok Good (50 test cases)
Test #7:
score: 0
Accepted
time: 11ms
memory: 3540kb
input:
50 12 15 0 0 24 22 6 7 4 6 5 10 5 7 0 4 11 9 6 11 9 0 14 5 3 6 2 6 14 8 0 0 13 15 12 6 12 2 9 8 13 10 5 8 13 4 15 2 4 8 7 12 8 0 0 7 10 6 12 0 5 13 7 11 5 6 9 10 13 6 3 4 4 8 11 13 0 9 10 18 9 7 8 4 6 6 5 13 0 4 13 12 5 6 2 4 4 14 7 0 16 13 8 8 10 8 4 7 0 13 9 11 6 0 8 10 11 6 0 0 8 10 0 8 13 12 6 3...
output:
? 1 1 6 8 ? 1 1 9 12 ? 1 1 11 14 ? 1 1 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