結果

問題 No.1830 Balanced Majority
ユーザー riano
提出日時 2022-01-23 15:50:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 166,652 KB
実行使用メモリ 25,476 KB
平均クエリ数 7.54
最終ジャッジ日時 2024-11-29 16:43:51
合計ジャッジ時間 3,389 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define riano_ std::ios::sync_with_stdio(false);std::cin.tie(nullptr)

int main() {
    riano_;
	ll N; cin >> N;
    ll sl,sr;
    cout << "? " << 1 << endl;
    cin >> sl; sl = sl*2-1;
    cout << "? " << N-1 << endl;
    cin >> sr; sr = sr*2-(N-1);
    if(sl==sr){
        cout << "! " << 2 << " " << N-1 << endl;
        return 0;
    }
    int pm = 1; ll l = 1,r = N-1;
    if(sl>0) pm = -1;
    while(l<r){
        ll c = (l+r)/2;
        cout << "? " << c << endl;
        cin >> sl; sl = sl*2-c;
        if(sl==0){
            l = c; r = c;
        }
        else if(sl*pm<0){
            l = c;
        }
        else r = c;
    }
    if(l>=N/2){
        cout << "! " << 1 << " " << l << endl;
    }
    else{
        cout << "! " << l+1 << " " << N << endl;
    }
}
0