QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#76562 | #4884. Battleship: New Rules | LG_Monkey | WA | 2ms | 3288kb | C++14 | 2.3kb | 2023-02-10 19:27:41 | 2023-02-10 19:27:43 |
Judging History
answer
/*NE Write and AFO here*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
int n, a[1010][1010];
pii dfs(int x1, int y1, int x2, int y2) {
int cnt = (x2 - x1 + 2) * (y2 - y1 + 2);
for (int i = y1 - 1; i <= y2 + 1; ) {
if (a[x2 + 1][i] != 1) continue;
int j = i;
while (j <= y2 && a[x2 + 1][j + 1] == 1) j++;
if (i == y1 - 1 && j == y2 + 1) cnt -= y2 - y1 + 2;
else if (i == y1 - 1 || j == y2 + 1) cnt -= j - i + 1;
else cnt -= j - i + 2;
i = j + 1;
}
for (int i = y1 - 1; i <= y2 + 1; ) {
if (a[x1 - 1][i] != 1) continue;
int j = i;
while (j <= y2 && a[x1 - 1][j + 1] == 1) j++;
if (i == y1 - 1 && j == y2 + 1) cnt -= y2 - y1 + 2;
else if (i == y1 - 1 || j == y2 + 1) cnt -= j - i + 1;
else cnt -= j - i + 2;
i = j + 1;
}
for (int i = x1 - 1; i <= x2 + 1; ) {
if (a[i][y1 - 1] != 1) continue;
int j = i;
while (j <= x2 && a[j + 1][y1 - 1] == 1) j++;
if (i == x1 - 1 && j == x2 + 1) cnt -= x2 - x1 + 2;
else if (i == x1 - 1 || j == x2 + 1) cnt -= j - i + 1;
else cnt -= j - i + 2;
i = j + 1;
}
for (int i = x1 - 1; i <= x2 + 1; ) {
if (a[i][y2 + 1] != 1) continue;
int j = i;
while (j <= x2 && a[j + 1][y2 + 1] == 1) j++;
if (i == x1 - 1 && j == x2 + 1) cnt -= x2 - x1 + 2;
else if (i == x1 - 1 || j == x2 + 1) cnt -= j - i + 1;
else cnt -= j - i + 2;
i = j + 1;
}
if (cnt % 2 == 0) return mp(-1, -1);
if (x1 == x2 && y1 == y2) return mp(x1, y1);
if (x2 - x1 > y2 - y1) {
int mid = (x1 + x2) >> 1;
for (int j = y1; j <= y2; j++) {
if (a[mid][j] == -1) {
int x; cin >> x; a[mid][j] = x;
}
}
pii la = dfs(x1, y1, mid - 1, y1), ra = dfs(mid + 1, y1, x2, y2);
if (la.first == -1) return ra; else return la;
} else {
int mid = (y1 + y2) >> 1;
for (int j = x1; j <= x2; j++) {
if (a[j][mid] == -1) {
int x; cin >> x; a[j][mid] = x;
}
}
pii la = dfs(x1, y1, x2, mid - 1), ra = dfs(x1, mid + 1, x2, y2);
if (la.first == -1) return ra; else return la;
}
}
signed main() {
int T;
cin >> T;
while (T--) {
cin >> n;
if (n & 1) {
cout << "! -1 -1" << endl; continue;
}
memset(a, -1, sizeof a);
pii ans = dfs(1, 1, n, n);
cout << "! " << ans.first << " " << ans.second << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3288kb
input:
2 3 1 4 -1
output:
! -1 -1 ! -1 -1
result:
wrong output format Unexpected end of file - int32 expected (test case 2)