結果

問題 No.2085 Directed Complete Graph
ユーザー kemuniku
提出日時 2024-10-23 06:33:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 344 ms / 2,000 ms
コード長 1,393 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 95,392 KB
平均クエリ数 2533.76
最終ジャッジ日時 2024-10-23 06:33:10
合計ジャッジ時間 6,180 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

from random import shuffle,randint
N = int(input())
P = list(range(1,N+1))
#shuffle(P) 

paths = set()
ask_count = 0
def ask(a,b):
    if (a,b) in paths:
        return True
    elif (b,a) in paths:
        return False
    # global ask_count
    # if ask_count == 4000:
    #     print("質問回数上限を超えました")
    #     exit()
    # ask_count += 1
    print("?",P[a],P[b])
    T = int(input())
    if T == 1:
        paths.add((a,b))
    else:
        paths.add((b,a))
    return T == 1

# def ask(a,b,x=-1):
#     if (a,b) in paths:
#         print("!")
#         return True
#     elif (b,a) in paths:
#         print("!")
#         return False
#     global ask_count
#     # if ask_count == 4000:
#     #     print("質問回数上限を超えました")
#     #     exit()
#     ask_count += 1
#     print("?",P[a],P[b])
#     if x == -1:
#         T = randint(0,1)
#     else:
#         T = x
#     if T == 1:
#         paths.add((a,b))
#     else:
#         paths.add((b,a))
#     return T == 1
    


if ask(0,1):
    now = [0,1]
else:
    now = [1,0]

for i in range(2,N):
    ok = -1
    ng = len(now)
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if ask(now[mid],i):
            ok = mid
        else:
            ng = mid
    now.insert(ok+1,i)
print("!")
print(len(now)-1)
print(*list(map(lambda x:P[x],now)))
#print("質問回数",ask_count)
0