QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56102#4884. Battleship: New RulesSorting#TL 4ms3708kbC++2.5kb2022-10-16 23:24:152022-10-16 23:24:16

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-16 23:24:16]
  • 评测
  • 测评结果:TL
  • 用时:4ms
  • 内存:3708kb
  • [2022-10-16 23:24:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned char uc;
typedef long long ll;
#define fi first
#define se second
int n;
char c[2001][2001];
char ask(int x,int y){
	cout << "? " << x << ' ' << y << endl;
	int z;cin >> z;
	if(z==1) return 'X';
	else return '.';
}
void solve(int xl,int xr,int yl,int yr){
	if(xr==xl+1 && yr==yl+1){
		cout << "! " << xl*2 << ' ' << yl*2 << endl;
		int res;cin >> res;
		return;
	}
	if(xr-xl>yr-yl){
		int xm=(xl+xr)/2;
		for(int i=xm*2-1; i<=xm*2 ;i++){
			for(int j=yl*2-1; j<=yr ;j++){
				if(c[i][j]=='?') c[i][j]=ask(i,j);
			}
		}
		for(int i=xm; i<=xm ;i++){
			for(int j=yl; j<=yr ;j++){
				bool ok=true;
				for(int x=0; x<2 ;x++){
					for(int y=0; y<2 ;y++){
						ok&=(c[2*i-x][2*j-y]=='.');
					}
				}
				if(ok){
					cout << "! " << i*2-1 << ' ' << j*2-1 << endl;
					int res;cin >> res;
					return;
				}
			}
		}
		for(int k=yl; k<=yr ;k++){
			if(c[xm*2-1][2*k-1]=='X' && c[xm*2-1][2*k]=='X'){
				solve(xm,xr,yl,yr);
				return;
			}
			if(c[xm*2][2*k-1]=='X' && c[xm*2][2*k]=='X'){
				solve(xl,xm,yl,yr);
				return;
			}
		}
		if(c[xm*2-1][2*yl]=='X' || c[xm*2-1][2*yr-1]=='X'){
			solve(xm,xr,yl,yr);
			return;
		}
		else if(c[xm*2][2*yl]=='X' || c[xm*2][2*yr-1]=='X'){
			solve(xl,xm,yl,yr);
			return;
		}
		else while(true);
	}
	else{
		int ym=(yl+yr)/2;
		for(int i=xl*2-1; i<=xr*2 ;i++){
			for(int j=ym*2-1; j<=ym ;j++){
				if(c[i][j]=='?') c[i][j]=ask(i,j);
			}
		}
		
		for(int i=xl; i<=xr ;i++){
			for(int j=ym; j<=ym ;j++){
				bool ok=true;
				for(int x=0; x<2 ;x++){
					for(int y=0; y<2 ;y++){
						ok&=(c[2*i-x][2*j-y]=='.');
					}
				}
				if(ok){
					cout << "! " << i*2-1 << ' ' << j*2-1 << endl;
					int res;cin >> res;
					return;
				}
			}
		}
		for(int k=xl; k<=xr ;k++){
			if(c[2*k-1][ym*2-1]=='X' && c[2*k][ym*2-1]=='X'){
				solve(xl,xr,ym,yr);
				return;
			}
			if(c[2*k-1][ym*2]=='X' && c[2*k][ym*2]=='X'){
				solve(xl,xr,yl,ym);
				return;
			}
		}
		if(c[2*xl][ym*2-1]=='X' || c[2*xr-1][ym*2-1]=='X'){
			solve(xl,xr,ym,yr);
			return;
		}
		else if(c[2*xl][ym*2]=='X' || c[2*xr-1][ym*2]=='X'){
			solve(xl,xr,yl,ym);
			return;
		}
		else while(true);
	}
}
void solve(){
	cin >> n;
	if(n%2==1){
		cout << "! -1 -1" << endl;
		int res;cin >> res;
		return;
	}
	for(int i=1; i<=n ;i++){
		for(int j=1; j<=n ;j++){
			c[i][j]='?';
		}
	}
	solve(1,n/2,1,n/2);
}
int main(){
	ios::sync_with_stdio(false);
	int t;cin >> t;while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3708kb

input:

2
3
1
4
1

output:

! -1 -1
! 2 2

result:

ok max_C=0.00, avg_C=0.00 (2 test cases)

Test #2:

score: 0
Accepted
time: 4ms
memory: 3536kb

input:

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

output:

! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
! 2 2
...

result:

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

Test #3:

score: -100
Time Limit Exceeded

input:

100
10

output:


result: