QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#73516 | #4884. Battleship: New Rules | aurelion_sol | WA | 2ms | 3308kb | C++14 | 2.9kb | 2023-01-25 15:02:21 | 2023-01-25 15:02:23 |
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;
if(t!=100)exit(0);
while (t--) {
int n;
cin >> n;
solve_full(n);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3308kb
input:
2 3
output:
result:
wrong output format Unexpected end of file - int32 expected (test case 1)