QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#76594#4884. Battleship: New RulesLG_MonkeyTL 45ms11308kbC++142.6kb2023-02-10 21:37:302023-02-10 21:37:33

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-10 21:37:33]
  • 评测
  • 测评结果:TL
  • 用时:45ms
  • 内存:11308kb
  • [2023-02-10 21:37:30]
  • 提交

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 x2 = X2 - 1, y2 = Y2 - 1; 
	int cnt = (x2 - x1 + 2) * (y2 - y1 + 2) + 88888888886;
	for (int i = y1; i <= y2; ) {
		if (a[x2 + 1][i] != 1) {
			i++; continue;
		}
		int j = i;
		while (j < y2 && a[x2 + 1][j + 1] == 1) j++;
		cnt -= j - i + 2; i = j + 1;
	} 
	for (int i = y1; i <= y2; ) {
		if (a[x1 - 1][i] != 1) {
			i++; continue;
		}
		int j = i;
		while (j < y2 && a[x1 - 1][j + 1] == 1) j++;
		cnt -= j - i + 2; i = j + 1;
	} 
	for (int i = x1; i <= x2; ) {
		if (a[i][y1 - 1] != 1) {
			i++; continue;
		}
		int j = i;
		while (j < x2 && a[j + 1][y1 - 1] == 1) j++;
		cnt -= j - i + 2; i = j + 1;
	} 
	for (int i = x1; i <= x2; ) {
		if (a[i][y2 + 1] != 1) {
			i++; continue;
		}
		int j = i;
		while (j < x2 && a[j + 1][y2 + 1] == 1) j++;
		cnt -= j - i + 2; i = j + 1;
	} 
	if (a[x1 - 1][y1 - 1] == 1 && a[x1 - 1][y1] != 1 && a[x1][y1 - 1] != 1) cnt--;
	if (a[x2 + 1][y1 - 1] == 1 && a[x2 + 1][y1] != 1 && a[x2][y1 - 1] != 1) cnt--;
	if (a[x1 - 1][y2 + 1] == 1 && a[x1 - 1][y2] != 1 && a[x1][y2 + 1] != 1) cnt--;
	if (a[x2 + 1][y2 + 1] == 1 && a[x2 + 1][y2] != 1 && a[x2][y2 + 1] != 1) cnt--;
	if (a[x1 - 1][y1] == 1 && a[x1][y1 - 1] == 1) cnt++;
	if (a[x2 + 1][y1] == 1 && a[x2][y1 - 1] == 1) cnt++;
	if (a[x1 - 1][y2] == 1 && a[x1][y2 + 1] == 1) cnt++;
	if (a[x2 + 1][y2] == 1 && a[x2][y2 + 1] == 1) cnt++;
	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) {
				cout << "? " << mid << " " << j << endl; int x; cin >> x; a[mid][j] = x;
			}
		}
		pii la = dfs(x1, y1, mid, Y2), ra = dfs(mid + 1, y1, X2, Y2);
		if (la.first == -1) return ra; else if (ra.first != -1) while (1); else return la;
	} else {
		int mid = (y1 + y2) >> 1;
		for (int j = x1; j <= x2; j++) {
			if (a[j][mid] == -1) {
				cout << "? " << j << " " << mid << endl; int x; cin >> x; a[j][mid] = x;
			}
		}
		pii la = dfs(x1, y1, X2, mid), ra = dfs(x1, mid + 1, X2, Y2);
		if (la.first == -1) return ra; else if (ra.first != -1) while (1); else return la;
	}
}
signed main() {
	int T;
	cin >> T;
	while (T--) {
		cin >> n;
		if (n & 1) {
			cout << "! -1 -1" << endl; int x; cin >> x; continue;
		}
		memset(a, -1, sizeof a);
		pii ans = dfs(1, 1, n + 1, n + 1);
		cout << "! " << ans.first - 1 << " " << ans.second - 1 << endl; int x; cin >> x;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 11308kb

input:

2
3
1
4
1
0
0
0
0
1
0
1
1

output:

! -1 -1
? 1 2
? 2 2
? 3 2
? 4 2
? 2 3
? 2 4
? 3 3
? 4 3
! 2 2

result:

ok max_C=2.00, avg_C=1.00 (2 test cases)

Test #2:

score: 0
Accepted
time: 45ms
memory: 11260kb

input:

100
4
1
0
0
0
0
1
0
1
1
4
1
0
0
0
0
1
0
1
1
4
0
0
0
1
0
0
0
0
1
4
0
0
0
1
0
0
0
0
1
4
1
0
0
0
0
1
0
1
1
4
1
0
0
0
0
1
0
1
1
4
1
0
0
0
0
1
0
1
1
4
0
0
0
1
0
0
0
0
1
4
0
0
0
1
0
0
0
0
1
4
0
0
0
1
0
0
0
0
1
4
0
0
0
1
0
0
0
0
1
4
1
0
0
0
0
1
0
1
1
4
0
0
0
1
0
0
0
0
1
4
1
0
0
0
0
1
0
1
1
4
1
0
0
0
0
1
0
...

output:

? 1 2
? 2 2
? 3 2
? 4 2
? 2 3
? 2 4
? 3 3
? 4 3
! 2 2
? 1 2
? 2 2
? 3 2
? 4 2
? 2 3
? 2 4
? 3 3
? 4 3
! 2 2
? 1 2
? 2 2
? 3 2
? 4 2
? 2 3
? 2 4
? 3 3
? 4 3
! 2 2
? 1 2
? 2 2
? 3 2
? 4 2
? 2 3
? 2 4
? 3 3
? 4 3
! 2 2
? 1 2
? 2 2
? 3 2
? 4 2
? 2 3
? 2 4
? 3 3
? 4 3
! 2 2
? 1 2
? 2 2
? 3 2
? 4 2
? 2 3
...

result:

ok max_C=2.00, avg_C=2.00 (100 test cases)

Test #3:

score: -100
Time Limit Exceeded

input:

100
10
1
0
0
0
0
0
0
1
0
1
0
0
0
1
0
0
0
0
0
0
1
0
1
10
1
0
1
0
1
0
1
0
1
1
1
0
1
0
1
1
0
1
0
1
0
0
0
0
0
1
10
1
0
1
0
1
0
0
0
0
1
0
0
0
0
1
1
0
1
1
0
0
0
0
1
10
1
0
1
0
1
0
1
1
0
1
1
1
1
0
1
0
0
0
0
1
0
0
0
0
1
10
1
0
1
1
1
1
0
1
0
1
0
0
0
0
0
1
0
0
0
0
1
0
1
1
10
1
0
1
0
0
0
0
0
1
1
1
0
1
0
1
1
0
...

output:

? 1 5
? 2 5
? 3 5
? 4 5
? 5 5
? 6 5
? 7 5
? 8 5
? 9 5
? 10 5
? 5 1
? 5 2
? 5 3
? 5 4
? 1 2
? 2 2
? 3 2
? 4 2
? 2 3
? 2 4
? 3 3
? 4 3
! 4 2
? 1 5
? 2 5
? 3 5
? 4 5
? 5 5
? 6 5
? 7 5
? 8 5
? 9 5
? 10 5
? 5 6
? 5 7
? 5 8
? 5 9
? 5 10
? 6 8
? 7 8
? 8 8
? 9 8
? 10 8
? 8 6
? 8 7
? 9 6
? 10 6
? 9 7
! 8 6
?...

result: