結果

問題 No.1830 Balanced Majority
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-23 23:29:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 104,948 KB
実行使用メモリ 24,432 KB
平均クエリ数 7.73
最終ジャッジ日時 2023-08-24 22:01:46
合計ジャッジ時間 6,762 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
23,628 KB
testcase_01 AC 24 ms
24,372 KB
testcase_02 AC 25 ms
24,000 KB
testcase_03 AC 26 ms
23,652 KB
testcase_04 AC 25 ms
24,060 KB
testcase_05 AC 25 ms
24,060 KB
testcase_06 AC 25 ms
23,544 KB
testcase_07 AC 27 ms
24,432 KB
testcase_08 AC 27 ms
23,400 KB
testcase_09 AC 27 ms
24,228 KB
testcase_10 AC 55 ms
23,856 KB
testcase_11 AC 56 ms
23,400 KB
testcase_12 AC 27 ms
23,388 KB
testcase_13 AC 27 ms
23,556 KB
testcase_14 AC 27 ms
23,568 KB
testcase_15 AC 26 ms
23,400 KB
testcase_16 AC 27 ms
23,856 KB
testcase_17 AC 27 ms
23,424 KB
testcase_18 AC 25 ms
23,448 KB
testcase_19 AC 25 ms
23,412 KB
testcase_20 AC 24 ms
23,856 KB
testcase_21 AC 26 ms
23,856 KB
testcase_22 AC 26 ms
23,688 KB
testcase_23 AC 26 ms
24,312 KB
testcase_24 AC 27 ms
24,000 KB
testcase_25 AC 24 ms
23,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <cassert>
 
using namespace std;

using ll = long long;

void query(ll K){
    cout << "? " << K << endl;
}

void ans(ll a, ll b){
    cout << "! " << a << " " << b << endl;
    exit(0);
}
 
int main(){
 
    ll N, x, y, z;
    cin >> N;
    ll l, r, c;
    l = 2, r = N;
    query(1);
    cin >> x;
    x = 2*x-1;
    query(N-1);
    cin >> y;
    y = 2*y-(N-1);
    if (x == y) ans(2, N-1);
    z = x;

    while(r-l>1){
        c = (r+l)/2;
        query(c);
        cin >> x;
        x =2*x-c;
        if (x*z == 0){
            l = c;
            r = c;
        }
        else if (x*z > 0) l = c;
        else r = c;
    }
 
    if (l >= N/2) ans(1LL, l);
    else ans(l+1, N);
 
    return 0;
}
0