結果

問題 No.1830 Balanced Majority
ユーザー ぷらぷら
提出日時 2022-02-04 23:02:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 198,808 KB
実行使用メモリ 24,348 KB
平均クエリ数 7.50
最終ジャッジ日時 2023-09-02 05:42:59
合計ジャッジ時間 4,216 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,652 KB
testcase_01 AC 25 ms
23,376 KB
testcase_02 AC 25 ms
23,544 KB
testcase_03 AC 24 ms
24,048 KB
testcase_04 AC 23 ms
23,520 KB
testcase_05 AC 24 ms
23,532 KB
testcase_06 AC 24 ms
24,024 KB
testcase_07 AC 26 ms
24,288 KB
testcase_08 AC 25 ms
24,300 KB
testcase_09 AC 26 ms
23,628 KB
testcase_10 AC 25 ms
24,348 KB
testcase_11 AC 26 ms
23,532 KB
testcase_12 AC 26 ms
24,324 KB
testcase_13 AC 27 ms
23,832 KB
testcase_14 AC 27 ms
23,424 KB
testcase_15 AC 27 ms
24,024 KB
testcase_16 AC 27 ms
24,060 KB
testcase_17 AC 27 ms
23,544 KB
testcase_18 AC 26 ms
24,264 KB
testcase_19 AC 25 ms
23,424 KB
testcase_20 AC 26 ms
24,048 KB
testcase_21 AC 27 ms
23,244 KB
testcase_22 AC 25 ms
24,048 KB
testcase_23 AC 26 ms
23,544 KB
testcase_24 AC 25 ms
24,060 KB
testcase_25 AC 24 ms
23,556 KB
権限があれば一括ダウンロードができます

ソースコード

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;
    S = S-(1-S);
    s = s-(N-1-s);
    if(S == s) {
        cout << "! " << 2 << " " << N-1 << endl;
        return 0;
    }
    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(mid >= N/2) {
                cout << "! " << 1 << " " << mid << endl;
            }
            else {
                cout << "! " << mid+1 << " " << N << endl;
            }
            return 0;
        }
        if(S < 0 && a < 0) {
            l = mid;
            continue;
        }
        if(S > 0 && a > 0) {
            l = mid;
            continue;
        }
        r = mid;
    }
    if(r >= N/2) {
        cout << "! " << 1 << " " << r << endl;
    }
    else {
        cout << "! " << r+1 << " " << N << endl;
    }
}
0