結果

問題 No.850 企業コンテスト2位
ユーザー 👑 kmjpkmjp
提出日時 2019-07-05 22:11:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 168,312 KB
実行使用メモリ 24,312 KB
平均クエリ数 200.39
最終ジャッジ日時 2023-09-23 17:27:23
合計ジャッジ時間 4,202 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,616 KB
testcase_01 AC 24 ms
23,328 KB
testcase_02 AC 24 ms
24,300 KB
testcase_03 AC 24 ms
23,916 KB
testcase_04 AC 23 ms
23,964 KB
testcase_05 AC 23 ms
23,352 KB
testcase_06 AC 24 ms
23,352 KB
testcase_07 AC 28 ms
23,376 KB
testcase_08 AC 31 ms
23,964 KB
testcase_09 AC 30 ms
23,352 KB
testcase_10 AC 35 ms
23,328 KB
testcase_11 AC 34 ms
23,568 KB
testcase_12 AC 34 ms
23,964 KB
testcase_13 AC 35 ms
23,364 KB
testcase_14 AC 35 ms
23,352 KB
testcase_15 AC 32 ms
23,568 KB
testcase_16 AC 33 ms
23,568 KB
testcase_17 AC 35 ms
24,312 KB
testcase_18 AC 35 ms
23,340 KB
testcase_19 AC 36 ms
23,928 KB
testcase_20 AC 35 ms
23,748 KB
testcase_21 AC 34 ms
23,508 KB
testcase_22 AC 34 ms
24,180 KB
testcase_23 AC 34 ms
23,532 KB
testcase_24 AC 35 ms
23,568 KB
testcase_25 AC 36 ms
24,216 KB
testcase_26 AC 35 ms
23,352 KB
testcase_27 AC 25 ms
24,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;

int lose[333];
int ask(int x,int y) {
	int r;
	cout<<"? "<<x<<" "<<y<<endl;
	cin>>r;
	return r;
}

int ans(int a) {
	cout<<"! "<<a<<endl;
	exit(0);
}

int win(int L,int R) {
	if(L+1>=R) return L;
	int M=(L+R)/2;
	
	int x=win(L,M);
	int y=win(M,R);
	if(ask(x,y)==x) {
		lose[y]=x;
		return x;
	}
	else {
		lose[x]=y;
		return y;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	x=win(1,N+1);
	
	vector<int> V;
	for(i=1;i<=N;i++) if(lose[i]==x) V.push_back(i);
	
	int cur=V[0];
	for(i=1;i<V.size();i++) cur=ask(cur,V[i]);
	ans(cur);
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0