結果

問題 No.1830 Balanced Majority
コンテスト
ユーザー ぷら
提出日時 2022-02-04 22:46:12
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,057 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,380 ms
コンパイル使用メモリ 210,772 KB
実行使用メモリ 30,032 KB
平均クエリ数 10.92
最終ジャッジ日時 2026-06-25 04:59:08
合計ジャッジ時間 3,675 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 17 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

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