結果
| 問題 |
No.850 企業コンテスト2位
|
| コンテスト | |
| ユーザー |
ttttan2
|
| 提出日時 | 2019-07-05 23:03:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 35 ms / 2,000 ms |
| コード長 | 1,918 bytes |
| コンパイル時間 | 1,459 ms |
| コンパイル使用メモリ | 164,064 KB |
| 実行使用メモリ | 25,604 KB |
| 平均クエリ数 | 200.11 |
| 最終ジャッジ日時 | 2024-07-16 17:31:23 |
| 合計ジャッジ時間 | 4,064 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 27 |
ソースコード
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
if(a<b)return b;
else return a;
}
ll lmin(ll a,ll b){
if(a<b)return a;
else return b;
}
ll n,k,m;
vector<ll> pri;
bool prijud(ll n){
for(int i=2;i*i<=n;i++){
if(n%i==0)return false;
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
int d[n+1];
fill(d,d+n+1,-1);
int cnt=0;
int win=0;
for(;;){
if(cnt==n-1)break;
int now=0;
rep(i,1,n+1){
if(d[i]>0)continue;
if(now==0)now=i;
else{
cout<<"? "<<now<<" "<<i<<endl;
int y;cin>>y;
win=y;
if(y==now)d[i]=now;
else d[now]=i;
now=0;
cnt++;
}
}
}
vector<int> v;
rep(i,1,n+1){
if(d[i]==win)v.push_back(i);
}
int m=v.size();
int e[m];
fill(e,e+m,-1);
win=0;
cnt=0;
if(m==1){
cout<<"! "<<v[0]<<endl;
return 0;
}
for(;;){
if(cnt==m-1)break;
int now=-1;
rep(i,0,m){
if(e[i]>=0)continue;
if(now==-1)now=i;
else{
cout<<"? "<<v[now]<<" "<<v[i]<<endl;
int y;cin>>y;
win=y;
if(y==v[now])e[i]=now;
else e[now]=i;
now=-1;
cnt++;
}
}
}
cout<<"! "<<win<<endl;
}
ttttan2