QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#73514 | #4884. Battleship: New Rules | aurelion_sol | WA | 21ms | 3340kb | C++14 | 2.9kb | 2023-01-25 15:00:32 | 2023-01-25 15:00:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void answer(int x, int y) {
if (x >= 0 || y >= 0) {
x++, y++;
}
cout << "! " << x << " " << y << endl;
int ans;
cin >> ans;
if (ans != 1) {
exit(0);
}
}
vector<vector<int>> cache;
int ask(int x, int y) {
if (x >= (int)cache.size() || y >= (int)cache.size() || x < 0 || y < 0) {
return 0;
}
cout << "? " << x + 1 << " " << y + 1 << endl;
int ans;
cin >> ans;
if (ans == -1) {
exit(0);
}
cache[x][y] = ans;
return ans;
}
vector<vector<bool>> used;
void color4(int x, int y) {
for (int dx = 0; dx < 2; dx++) {
for (int dy = 0; dy < 2; dy++) {
used[x + dx][y + dy] = true;
}
}
}
bool upd(int x, int y) {
bool res = true;
for (int dx = 0; dx < 2; dx++) {
for (int dy = 0; dy < 2; dy++) {
if (ask(x - dx, y - dy) == 1) {
color4(x - dx, y - dy);
res = false;
}
}
}
return res;
}
pair<int, int> func(int x1, int y1, int x2, int y2) {
if (x2 - x1 == 1 && y2 - y1 == 1) {
return make_pair(x1, y1);
}
tuple<int, int, int, int> r1, r2;
if (x2 - x1 >= y2 - y1) {
int mid = (x1 + x2) / 2;
for (int i = y1; i < y2; i++) {
if (upd(mid, i)) {
return make_pair(mid, i);
}
}
r1 = make_tuple(x1, y1, mid, y2);
r2 = make_tuple(mid + 1, y1, x2, y2);
} else {
int mid = (y1 + y2) / 2;
for (int i = x1; i < x2; i++) {
if (upd(i, mid)) {
return make_pair(i, mid);
}
}
r1 = make_tuple(x1, y1, x2, mid);
r2 = make_tuple(x1, mid + 1, x2, y2);
}
int s1 = 0;
for (int i = get<0>(r1); i < get<2>(r1); i++) {
for (int j = get<1>(r1); j < get<3>(r1); j++) {
if (!used[i][j]) {
s1++;
}
}
}
if (s1 % 2 == 1) {
return func(get<0>(r1), get<1>(r1), get<2>(r1), get<3>(r1));
} else {
return func(get<0>(r2), get<1>(r2), get<2>(r2), get<3>(r2));
}
}
void solve(int n) {
used.clear();
used.reserve(n + 1);
for (int i = 0; i < n + 1; i++) {
used.emplace_back(vector<bool>(n + 1, false));
}
pair<int, int> t = func(0, 0, n + 1, n + 1);
answer(t.first - 1, t.second - 1);
}
void solve_full(int n) {
if (n % 2 == 1) {
answer(-1, -1);
return;
}
cache.clear();
cache.reserve(n);
for (int i = 0; i < n; i++) {
cache.emplace_back(vector<int>(n, -1));
}
solve(n);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if(n>10)exit(0);
solve_full(n);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 3340kb
input:
2 3 1 4 1 0 0 1 0 0 0 0 0 0 1
output:
! -1 -1 ? 3 1 ? 2 1 ? 3 2 ? 3 1 ? 2 2 ? 2 1 ? 3 3 ? 3 2 ? 2 3 ? 2 2 ! 2 2
result:
ok max_C=2.50, avg_C=1.25 (2 test cases)
Test #2:
score: 0
Accepted
time: 21ms
memory: 3340kb
input:
100 4 1 0 0 1 0 0 0 0 0 0 1 4 1 0 0 1 0 0 0 0 0 0 1 4 0 1 0 0 0 1 0 0 0 0 1 4 0 1 0 0 0 1 0 0 0 0 1 4 1 0 0 1 0 0 0 0 0 0 1 4 1 0 0 1 0 0 0 0 0 0 1 4 1 0 0 1 0 0 0 0 0 0 1 4 0 1 0 0 0 1 0 0 0 0 1 4 0 1 0 0 0 1 0 0 0 0 1 4 0 1 0 0 0 1 0 0 0 0 1 4 0 1 0 0 0 1 0 0 0 0 1 4 1 0 0 1 0 0 0 0 0 0 1 4 0 1 0 ...
output:
? 3 1 ? 2 1 ? 3 2 ? 3 1 ? 2 2 ? 2 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