結果

問題 No.1830 Balanced Majority
ユーザー 👑 tamatotamato
提出日時 2022-02-04 21:48:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,568 KB
実行使用メモリ 88,024 KB
平均クエリ数 7.54
最終ジャッジ日時 2023-09-02 04:41:42
合計ジャッジ時間 4,587 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
87,568 KB
testcase_01 AC 96 ms
87,496 KB
testcase_02 AC 98 ms
87,716 KB
testcase_03 AC 95 ms
87,628 KB
testcase_04 AC 95 ms
87,112 KB
testcase_05 AC 95 ms
87,240 KB
testcase_06 AC 94 ms
87,932 KB
testcase_07 AC 97 ms
87,568 KB
testcase_08 AC 98 ms
87,572 KB
testcase_09 AC 98 ms
88,024 KB
testcase_10 AC 97 ms
87,588 KB
testcase_11 AC 100 ms
87,692 KB
testcase_12 AC 100 ms
87,576 KB
testcase_13 AC 101 ms
87,252 KB
testcase_14 AC 98 ms
87,640 KB
testcase_15 AC 98 ms
87,380 KB
testcase_16 AC 100 ms
87,620 KB
testcase_17 AC 100 ms
87,808 KB
testcase_18 AC 99 ms
87,640 KB
testcase_19 AC 96 ms
87,448 KB
testcase_20 AC 100 ms
87,488 KB
testcase_21 AC 102 ms
87,696 KB
testcase_22 AC 100 ms
87,472 KB
testcase_23 AC 101 ms
87,348 KB
testcase_24 AC 99 ms
87,256 KB
testcase_25 AC 98 ms
87,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    def ask(k):
        print("?", k)
        sys.stdout.flush()
        return int(input())

    N = int(input())

    s0 = ask(1)
    s1 = ask(N - 1)
    s0 = s0 - (1 - s0)
    s1 = s1 - (N - 1 - s1)
    if s0 == s1:
        print("!", 2, N - 1)
        sys.stdout.flush()
        exit()
    ll = s0
    rr = s1
    l = 1
    r = N - 1
    for _ in range(18):
        mid = (l + r) // 2
        s = ask(mid)
        s = s - (mid - s)
        if s == 0:
            if mid < N // 2:
                print("!", mid + 1, N)
            else:
                print("!", 1, mid)
            sys.stdout.flush()
            exit()
        if s // abs(s) == ll:
            l = mid
        else:
            r = mid


if __name__ == '__main__':
    main()
0