結果

問題 No.1830 Balanced Majority
ユーザー srjywrdnprkt
提出日時 2023-05-23 23:29:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 789 ms
コンパイル使用メモリ 102,384 KB
最終ジャッジ日時 2025-02-13 04:18:04
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <cassert>
 
using namespace std;

using ll = long long;

void query(ll K){
    cout << "? " << K << endl;
}

void ans(ll a, ll b){
    cout << "! " << a << " " << b << endl;
    exit(0);
}
 
int main(){
 
    ll N, x, y, z;
    cin >> N;
    ll l, r, c;
    l = 2, r = N;
    query(1);
    cin >> x;
    x = 2*x-1;
    query(N-1);
    cin >> y;
    y = 2*y-(N-1);
    if (x == y) ans(2, N-1);
    z = x;

    while(r-l>1){
        c = (r+l)/2;
        query(c);
        cin >> x;
        x =2*x-c;
        if (x*z == 0){
            l = c;
            r = c;
        }
        else if (x*z > 0) l = c;
        else r = c;
    }
 
    if (l >= N/2) ans(1LL, l);
    else ans(l+1, N);
 
    return 0;
}
0