QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117448 | #4884. Battleship: New Rules | hos_lyric | RE | 8ms | 3792kb | C++14 | 3.7kb | 2023-07-01 11:01:25 | 2023-07-01 11:01:28 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
int N;
int cache[1010][1010];
int A(int x, int y) {
assert(1 <= x); assert(x <= N);
assert(1 <= y); assert(y <= N);
int &ret = cache[x][y];
if (!~ret) {
printf("? %d %d\n", x, y);
fflush(stdout);
scanf("%d", &ret);
if (!(ret == 0 || ret == 1)) {
exit(0);
}
}
return ret;
}
void Answer(int x, int y) {
printf("! %d %d\n", x, y);
fflush(stdout);
int verdict;
scanf("%d", &verdict);
if (verdict != 1) {
exit(0);
}
}
int main() {
int numCases;
scanf("%d", &numCases);
for (; numCases--; ) {
scanf("%d", &N);
for (int x = 0; x <= N + 1; ++x) for (int y = 0; y <= N + 1; ++y) {
cache[x][y] = -1;
}
if (N % 2 != 0) {
Answer(-1, -1);
} else {
int x0 = 1, x1 = N + 1;
int y0 = 1, y1 = N + 1;
for (; x0 <= x1 && y0 <= y1; ) {
const bool cutX = (x1 - x0 >= y1 - y0);
const int mid = cutX ? ((x0 + x1) / 2) : ((y0 + y1) / 2);
const int w0 = cutX ? y0 : x0;
const int w1 = cutX ? y1 : x1;
auto at = [&](int z, int w) -> int {
return cutX ? A(mid - 1 + z, w) : A(w, mid - 1 + z);
};
auto asked = [&](int z, int w) -> bool {
return cutX ? (~cache[mid - 1 + z][w]) : (~cache[w][mid - 1 + z]);
};
for (int z = 0; z < 2; ++z) for (int w = w0; w < w1; ++w) {
at(z, w);
}
for (int z = -1; z < 2; ++z) for (int w = w0 - 1; w < w1; ++w) {
if ([&]() -> bool {
for (int dz = 0; dz < 2; ++dz) for (int dw = 0; dw < 2; ++dw) {
if (!asked(z + dz, w + dw)) {
return false;
}
}
for (int dz = 0; dz < 2; ++dz) for (int dw = 0; dw < 2; ++dw) {
if (at(z + dz, w + dw)) {
return false;
}
}
return true;
}()) {
cutX ? Answer(mid - 1 + z, w) : Answer(w, mid - 1 + z);
goto found;
}
}
// parity of (# corner) on (x0, y0)'s side
int cnt = cutX ? ((mid - x0) * (y1 - y0 + 1)) : ((x1 - x0 + 1) * (mid - y0));
for (int w = w0, ww = w0; w < w1; w = ww) {
for (; ww < w1 && at(0, w) == at(0, ww); ++ww) {}
cnt += (ww - w + 1);
}
cnt &= 1;
if (cnt & 1) {
(cutX ? x1 : y1) = mid - 1;
} else {
(cutX ? x0 : y0) = mid + 1;
}
}
assert(false);
found:{}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3648kb
input:
2 3 1 4 0 0 0 1 1 0 0 0 1
output:
! -1 -1 ? 2 1 ? 2 2 ? 2 3 ? 2 4 ? 3 1 ? 3 2 ? 3 3 ? 3 4 ! 2 2
result:
ok max_C=2.00, avg_C=1.00 (2 test cases)
Test #2:
score: 0
Accepted
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