結果

問題 No.850 企業コンテスト2位
ユーザー tamato
提出日時 2021-08-13 09:25:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 76,504 KB
平均クエリ数 200.11
最終ジャッジ日時 2024-10-02 17:26:16
合計ジャッジ時間 4,458 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


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

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

    N = int(input())
    st = list(range(1, N+1))
    op = [[] for _ in range(N+1)]
    while len(st) > 1:
        st_new = []
        for i in range(len(st) // 2):
            x = st[i * 2]
            y = st[i * 2 + 1]
            op[x].append(y)
            op[y].append(x)
            z = ask(x, y)
            st_new.append(z)
        if len(st) & 1:
            st_new.append(st[-1])
        st = st_new
    first = st[0]
    second_list = op[first]
    x = second_list[0]
    for y in second_list[1:]:
        x = ask(x, y)
    print("!", x)
    sys.stdout.flush()


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