QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406126#8239. Mysterious TreeoscaryangTL 1ms3664kbC++202.3kb2024-05-06 20:36:442024-05-06 20:36:44

Judging History

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

  • [2024-05-06 20:36:44]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3664kb
  • [2024-05-06 20:36:44]
  • 提交

answer

//OccDreamer
#include<bits/stdc++.h>

#define fi first
#define se second
#define vc vector
#define db double
#define ll long long
#define mk make_pair
#define pb push_back
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << "   -_-   " << endl
#define debug cerr << " ------------------- " << endl

#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)

#define NO puts("No")
#define YES puts("Yes")

//#define int long long

using namespace std;

namespace IO{
	inline int read(){
		int X=0, W=0; char ch=getchar();
		while(!isdigit(ch)) W|=ch=='-', ch=getchar();
		while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
		return W?-X:X;
	}
	inline void write(int x){
		if(x<0) x=-x, putchar('-');
		if(x>9) write(x/10);
		putchar(x%10+'0');
	}
	inline void sprint(int x){write(x), putchar(32);}
	inline void eprint(int x){write(x), putchar(10);}
}using namespace IO;

const int MAXN = 3005;
const int mod = 998244353;
//const int mod = 1e9+7;

int ca[MAXN], n;

inline void solve(){
	n=read();
	for(int i=1;i<=n;i+=2) ca[i]=i+1;
	if(n&1) ca[n]=n-1; int x, y;
	for(int i=1;i<=n;i+=2){
		cout << "? " << i << ' ' << ca[i] << endl;
		bool res; cin >> res;
		if(res==1) x=i, y=ca[i];
	}
	bool okx=0, oky=0; int cx, cy;
	for(int i=1;i<=n;++i){
		if(i!=x && i!=y){
			cx=i;
			cout << "? " << x << ' ' << i << endl;
			cin >> okx;  break;
		}
	}
	for(int i=1;i<=n;++i){
		if(i!=x && i!=y){
			cy=i;
			cout << "? " << y << ' ' << i << endl;
			cin >> oky;  break;
		}
	}
	if(!okx && !oky){cout << "! 1" << endl; return ;}
	if(okx && oky){cout << "! 1" << endl; return ;}
	if(okx){
		for(int i=1;i<=n;++i){
			if(i!=x && i!=y && i!=cx){
				cout << "? " << x << ' ' << i << endl;
				cin >> okx;
				if(okx==1){cout << "! 2" << endl; return ;}
				cout << "! 1" << endl; return ;
			}
		}
	}
	for(int i=1;i<=n;++i){
		if(i!=x && i!=y && i!=cy){
			cout << "? " << y << ' ' << i << endl;
			cin >> okx;
			if(okx==1){cout << "! 2" << endl; return ;}
			cout << "! 1" << endl; return ;
		}
	}
}

int main(){
	int t=read();
	while(t--) solve();
	return 0;
}





































































详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3664kb

input:

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

output:

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

result:

ok Correct (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

87
13
0
0
0
0
0
1
1
0
1
1
15
0
0
0
0
0
0
1
0
1
0
1
7
0
0
0
1
1
0
1
15
0
0
0
1
1
0
0
0
1
0
0
19
0
0
0
0
0
1
0
0
0
0
1
0
1
20
0
0
0
0
0
0
0
0
0
0

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 12
? 13 1
? 12 1
? 12 2
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 15 14
? 13 1
? 14 1
? 13 2
! 2
? 1 2
? 3 4
? 5 6
? 7 6
? 7 1
? 6 1
? 7 2
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 15 14
? 9 1
? 10 1
? 9 2
! 1
? 1 2
? 3 4
? 5 6
? 7 8
...

result: