結果

問題 No.1830 Balanced Majority
ユーザー rianoriano
提出日時 2021-12-25 13:34:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 833 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 163,484 KB
実行使用メモリ 25,604 KB
平均クエリ数 7.54
最終ジャッジ日時 2024-04-17 01:44:22
合計ジャッジ時間 4,041 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 26 ms
25,208 KB
testcase_03 AC 26 ms
25,208 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 26 ms
24,824 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 30 ms
25,220 KB
testcase_12 AC 28 ms
24,836 KB
testcase_13 AC 30 ms
25,220 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 26 ms
24,580 KB
testcase_21 AC 30 ms
24,836 KB
testcase_22 AC 29 ms
24,836 KB
testcase_23 AC 28 ms
24,836 KB
testcase_24 AC 29 ms
25,220 KB
testcase_25 AC 27 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 << " " << 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