結果

問題 No.1306 Exactly 2 Digits
ユーザー Kude
提出日時 2020-12-03 02:51:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 28,904 KB
平均クエリ数 1236.78
最終ジャッジ日時 2024-07-17 08:17:33
合計ジャッジ時間 19,841 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 123
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
n = int(input())
sz = n * n - n

def query(i, j):
    print('?', i+1, j+1)
    return tuple(map(int, input().split()))

d = [(0, 0) if i == 0 else query(i, 0) for i in range(sz)]

i_mn = min(range(sz), key=lambda x: d[x])
i_mx = max(range(sz), key=lambda x: d[x])
p0, q0 = -d[i_mn][0], -d[i_mn][1]
if p0 + d[i_mx][0] != n - 2:
    p0, q0 = q0, p0
d2i = defaultdict(list)
for i in range(sz):
    d2i[d[i]].append(i)
ans = [None] * sz
for (p, q), s in d2i.items():
    if len(s) == 1:
        np, nq = p0 + p, q0 + q
        if not (0 <= np <= n - 2 and 0 <= nq <= n - 1):
            np, nq = p0 + q, q0 + p
        ans[s[0]] = (np, nq)
    else:
        if p0 != q0:
            a, b = query(s[0], i_mn)
            if {a, b} != {p0 + p, q0 + q}:
                p, q = q, p
            ans[s[0]] = (p0 + p, q0 + q)
            ans[s[1]] = (p0 + q, q0 + p)
        else:
            a, b = query(s[0], i_mx)
            if {a, b} != {p0 + p - (n - 2), q0 + q - (n - 1)}:
                p, q = q, p
            ans[s[0]] = (p0 + p, q0 + q)
            ans[s[1]] = (p0 + q, q0 + p)
ans = [(t[0] + 1) * n + t[1] for t in ans]
print('!', *ans)
0