結果

問題 No.1830 Balanced Majority
ユーザー rianoriano
提出日時 2021-12-25 13:36:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 163,360 KB
実行使用メモリ 25,464 KB
平均クエリ数 7.54
最終ジャッジ日時 2024-04-17 01:44:08
合計ジャッジ時間 3,920 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
25,464 KB
testcase_01 AC 23 ms
25,076 KB
testcase_02 AC 24 ms
24,952 KB
testcase_03 AC 24 ms
24,568 KB
testcase_04 AC 25 ms
25,208 KB
testcase_05 AC 24 ms
24,824 KB
testcase_06 AC 24 ms
24,824 KB
testcase_07 AC 26 ms
24,836 KB
testcase_08 AC 25 ms
25,220 KB
testcase_09 AC 25 ms
25,220 KB
testcase_10 AC 25 ms
24,836 KB
testcase_11 AC 26 ms
24,964 KB
testcase_12 AC 25 ms
25,220 KB
testcase_13 AC 25 ms
25,220 KB
testcase_14 AC 26 ms
24,836 KB
testcase_15 AC 26 ms
25,220 KB
testcase_16 AC 26 ms
24,836 KB
testcase_17 AC 26 ms
25,220 KB
testcase_18 AC 25 ms
24,836 KB
testcase_19 AC 24 ms
25,220 KB
testcase_20 AC 24 ms
24,836 KB
testcase_21 AC 26 ms
24,580 KB
testcase_22 AC 26 ms
25,220 KB
testcase_23 AC 26 ms
24,836 KB
testcase_24 AC 26 ms
24,836 KB
testcase_25 AC 24 ms
24,836 KB
権限があれば一括ダウンロードができます

ソースコード

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 l = 1,r = N-1,sl,sr;
    cout << "? " << l << endl;
    cin >> sl; sl = sl*2-1;
    cout << "? " << r << endl;
    cin >> sr; sr = sr*2-(N-1);
    if(sl==sr){
        cout << "! " << l+1 << " " << r << endl;
        return 0;
    }
    int pm = 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