結果

問題 No.1830 Balanced Majority
ユーザー ぷらぷら
提出日時 2022-02-04 22:55:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 933 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 194,556 KB
最終ジャッジ日時 2025-01-27 19:39:05
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other WA * 15 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    cout << "? " << 1 << endl;
    int S;
    cin >> S;
    cout << "? " << N-1 << endl;
    int s;
    cin >> s;
    if(S == s) {
        cout << "! " << 2 << " " << N-1 << endl;
        return 0;
    }
    S = S-(N/2-S);
    s = s-(N/2-s);
    int l = 1,r = N;
    while (l+1 < r) {
        int mid = (l+r)/2;
        cout << "? " << mid << endl;
        int a;
        cin >> a;
        a = a-(mid-a);
        if(a == 0) {
            if(a >= N/2) {
                cout << "! " << 1 << " " << a << endl;
            }
            else {
                cout << "! " << a+1 << " " << N << endl;
            }
            return 0;
        }
        if(S < 0 && a < 0) {
            l = mid;
            continue;
        }
        if(S > 0 && a > 0) {
            l = mid;
            continue;
        }
        r = mid;
    }
    assert(0);
}
0