結果

問題 No.850 企業コンテスト2位
ユーザー chocoruskchocorusk
提出日時 2019-03-23 02:47:03
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,744 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 100,452 KB
実行使用メモリ 24,540 KB
平均クエリ数 209.39
最終ジャッジ日時 2023-09-23 16:50:36
合計ジャッジ時間 7,264 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 24 ms
24,288 KB
testcase_03 AC 24 ms
23,808 KB
testcase_04 AC 25 ms
23,604 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    int d=1;
    while(d*d<n) d++;
    vector<int> v[20];
    for(int i=1; i<=n; i++){
        v[i%d].push_back(i);
    }
    int mxb[20];
    int ret;
    for(int i=0; i<d; i++){
        mxb[i]=v[i][0];
        for(int j=1; j<v[i].size(); j++){
            cout<<"? "<<v[i][j]<<" "<<mxb[i]<<endl;
            cin>>ret;
            if(ret==v[i][j]) mxb[i]=v[i][j];
        }
    }
    int mx=mxb[0], mx2=mxb[1];
    int mxi=0;
    cout<<"? "<<mxb[0]<<" "<<mxb[1]<<endl;
    cin>>ret;
    if(ret==mxb[1]){
        swap(mx, mx2);
        mxi=1;
    }
    for(int i=2; i<d; i++){
        cout<<"? "<<mx2<<" "<<mxb[i]<<endl;
        cin>>ret;
        if(ret==mx2) continue;
        cout<<"? "<<mx<<" "<<mxb[i]<<endl;
        cin>>ret;
        if(ret==mxb[i]){
            mx2=mx;
            mx=mxb[i];
            mxi=i;
        }else{
            mx2=mxb[i];
        }
    }
    if(v[mxi].size()==1){
        cout<<"! "<<mx2<<endl;
        return 0;
    }
    int mx22=v[mxi][0];
    if(mx22==mx) mx22=v[mxi][1];
    for(int j=1; j<v[mxi].size(); j++){
        if(v[mxi][j]==mx || v[mxi][j]==mx22) continue;
        cout<<"? "<<mx22<<" "<<v[mxi][j]<<endl;
        cin>>ret;
        if(ret==v[mxi][j]) mx22=v[mxi][j];
    }
    cout<<"! "<<mx22<<endl;
    return 0;
}
0