QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#384283#4884. Battleship: New RuleszhoukangyangTL 0ms0kbC++141.8kb2024-04-09 21:24:292024-04-09 21:24:29

Judging History

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

  • [2024-04-09 21:24:29]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-04-09 21:24:29]
  • 提交

answer

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define sz(a) ((int) (a).size())
#define vi vector < int >
#define me(a, x) memset(a, x, sizeof(a))
#define ull unsigned long long
#define ld __float128
#define pb emplace_back
using namespace std;
#define i128 __int128
const int N = 2e3 + 7;
int n;
bool vis[N][N]; 

bool gr[N][N];
int query(int x, int y) {
	cout << "? " << x << ' ' << y << endl;
//	return gr[x][y];
	int w;
	cin >> w;
	return w;
}
void dc(int l1, int r1, int l2, int r2) {
	if(l1 == r1 && l2 == r2) {
		if(l1 == 0 || r1 == 0 || l2 == n || r2 == n) {
			cout << "! " << -1 << ' ' << -1 << endl;
		} else {
			cout << "! " << l1 << ' ' << r1 << endl;
		}
		return;
	}
	if(r1 - l1 > r2 - l2) {
		int m1 = (l1 + r1) >> 1;
		L(j, l2 + 1, r2) {
			int u = query(m1, j);
			if(u) vis[m1][j] = vis[m1][j - 1] = vis[m1 - 1][j] = vis[m1 - 1][j - 1] = 1;
		}
		int op = 0;
		L(i, l1, m1) L(j, l2, r2)op ^= !vis[i][j];
		if(op)dc(l1, m1, l2, r2);
		else dc(m1 + 1, r1, l2, r2);
	} else {
		int m2 = (l2 + r2) >> 1;
		L(j, l1 + 1, r1) {
			int u = query(j, m2);
			if(u) vis[j][m2] = vis[j - 1][m2] = vis[j][m2 - 1] = vis[j - 1][m2 - 1] = 1;
		}
		int op = 0;
		L(i, l1, r1) L(j, l2, m2)op ^= !vis[i][j];
		if(op)dc(l1, r1, l2, m2);
		else dc(l1, r1, m2 + 1, r2);
	}
}
void Main() {
	cin >> n;
	if(n % 2 == 1) {
		cout << "! -1 -1\n";
		return ;
	}
	L(i, 0, n) L(j, 0, n)vis[i][j] = 0;
	dc(0, n, 0, n);
}
int main() {
	gr[1][1] = 1;
	gr[1][2] = 1;
	gr[3][1] = 1;
	gr[4][1] = 1;
	gr[1][4] = 1;
	gr[2][4] = 1;
	gr[4][3] = 1;
	gr[4][4] = 1;
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t; cin >> t; while(t--) Main();
	return 0;
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

2
3

output:


result: