結果

問題 No.1306 Exactly 2 Digits
ユーザー mkawa2mkawa2
提出日時 2020-12-04 13:18:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 1,842 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 28,488 KB
平均クエリ数 1245.39
最終ジャッジ日時 2024-07-17 09:28:18
合計ジャッジ時間 19,865 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
27,592 KB
testcase_01 AC 51 ms
27,720 KB
testcase_02 AC 52 ms
27,608 KB
testcase_03 AC 51 ms
27,736 KB
testcase_04 AC 50 ms
27,608 KB
testcase_05 AC 55 ms
27,736 KB
testcase_06 AC 51 ms
27,608 KB
testcase_07 AC 51 ms
27,480 KB
testcase_08 AC 50 ms
27,352 KB
testcase_09 AC 51 ms
27,480 KB
testcase_10 AC 51 ms
27,600 KB
testcase_11 AC 52 ms
27,480 KB
testcase_12 AC 50 ms
27,736 KB
testcase_13 AC 52 ms
27,720 KB
testcase_14 AC 51 ms
27,592 KB
testcase_15 AC 51 ms
27,976 KB
testcase_16 AC 51 ms
27,592 KB
testcase_17 AC 51 ms
27,336 KB
testcase_18 AC 51 ms
27,464 KB
testcase_19 AC 52 ms
27,848 KB
testcase_20 AC 51 ms
27,464 KB
testcase_21 AC 51 ms
27,592 KB
testcase_22 AC 51 ms
27,624 KB
testcase_23 AC 52 ms
27,336 KB
testcase_24 AC 52 ms
27,720 KB
testcase_25 AC 52 ms
27,592 KB
testcase_26 AC 52 ms
27,464 KB
testcase_27 AC 52 ms
27,336 KB
testcase_28 AC 53 ms
27,720 KB
testcase_29 AC 52 ms
27,208 KB
testcase_30 AC 52 ms
28,104 KB
testcase_31 AC 52 ms
27,592 KB
testcase_32 AC 51 ms
27,464 KB
testcase_33 AC 52 ms
27,592 KB
testcase_34 AC 52 ms
27,592 KB
testcase_35 AC 52 ms
28,008 KB
testcase_36 AC 53 ms
27,208 KB
testcase_37 AC 53 ms
27,456 KB
testcase_38 AC 52 ms
27,592 KB
testcase_39 AC 53 ms
27,856 KB
testcase_40 AC 53 ms
27,720 KB
testcase_41 AC 53 ms
27,464 KB
testcase_42 AC 53 ms
27,336 KB
testcase_43 AC 57 ms
27,336 KB
testcase_44 AC 53 ms
27,464 KB
testcase_45 AC 55 ms
28,104 KB
testcase_46 AC 56 ms
27,464 KB
testcase_47 AC 57 ms
27,464 KB
testcase_48 AC 57 ms
27,848 KB
testcase_49 AC 62 ms
27,848 KB
testcase_50 AC 60 ms
27,464 KB
testcase_51 AC 63 ms
27,336 KB
testcase_52 AC 63 ms
27,720 KB
testcase_53 AC 65 ms
27,464 KB
testcase_54 AC 72 ms
27,336 KB
testcase_55 AC 69 ms
27,872 KB
testcase_56 AC 80 ms
28,104 KB
testcase_57 AC 80 ms
27,592 KB
testcase_58 AC 83 ms
27,592 KB
testcase_59 AC 85 ms
27,592 KB
testcase_60 AC 89 ms
27,456 KB
testcase_61 AC 85 ms
27,464 KB
testcase_62 AC 94 ms
28,136 KB
testcase_63 AC 86 ms
27,848 KB
testcase_64 AC 100 ms
27,848 KB
testcase_65 AC 99 ms
27,848 KB
testcase_66 AC 98 ms
27,592 KB
testcase_67 AC 104 ms
27,712 KB
testcase_68 AC 118 ms
27,720 KB
testcase_69 AC 107 ms
27,848 KB
testcase_70 AC 123 ms
27,720 KB
testcase_71 AC 119 ms
27,848 KB
testcase_72 AC 122 ms
27,880 KB
testcase_73 AC 131 ms
27,592 KB
testcase_74 AC 138 ms
27,592 KB
testcase_75 AC 147 ms
28,104 KB
testcase_76 AC 156 ms
27,720 KB
testcase_77 AC 150 ms
28,104 KB
testcase_78 AC 150 ms
28,360 KB
testcase_79 AC 165 ms
28,104 KB
testcase_80 AC 167 ms
27,976 KB
testcase_81 AC 180 ms
28,232 KB
testcase_82 AC 165 ms
27,976 KB
testcase_83 AC 195 ms
28,104 KB
testcase_84 AC 188 ms
28,128 KB
testcase_85 AC 233 ms
28,360 KB
testcase_86 AC 206 ms
28,232 KB
testcase_87 AC 182 ms
28,104 KB
testcase_88 AC 216 ms
27,720 KB
testcase_89 AC 206 ms
27,720 KB
testcase_90 AC 208 ms
27,976 KB
testcase_91 AC 161 ms
28,360 KB
testcase_92 AC 171 ms
27,848 KB
testcase_93 AC 176 ms
28,104 KB
testcase_94 AC 158 ms
28,104 KB
testcase_95 AC 198 ms
27,976 KB
testcase_96 AC 182 ms
28,360 KB
testcase_97 AC 197 ms
27,976 KB
testcase_98 AC 165 ms
28,488 KB
testcase_99 AC 195 ms
27,976 KB
testcase_100 AC 186 ms
28,104 KB
testcase_101 AC 188 ms
27,712 KB
testcase_102 AC 195 ms
28,488 KB
testcase_103 AC 179 ms
28,360 KB
testcase_104 AC 172 ms
28,232 KB
testcase_105 AC 173 ms
28,104 KB
testcase_106 AC 170 ms
28,488 KB
testcase_107 AC 177 ms
28,488 KB
testcase_108 AC 186 ms
28,360 KB
testcase_109 AC 207 ms
28,432 KB
testcase_110 AC 203 ms
28,104 KB
testcase_111 AC 184 ms
28,232 KB
testcase_112 AC 177 ms
27,976 KB
testcase_113 AC 190 ms
28,104 KB
testcase_114 AC 201 ms
28,104 KB
testcase_115 AC 175 ms
28,360 KB
testcase_116 AC 186 ms
28,488 KB
testcase_117 AC 179 ms
28,232 KB
testcase_118 AC 185 ms
28,232 KB
testcase_119 AC 223 ms
27,976 KB
testcase_120 AC 163 ms
28,344 KB
testcase_121 AC 169 ms
28,352 KB
testcase_122 AC 210 ms
28,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

# aa = [12, 13, 11, 6, 15, 5, 7, 9, 14, 10, 8, 4]
# aa = [3, 5, 4, 8, 7, 6]
# def ask(i, j):
#     a = aa[i]//n-aa[j]//n
#     b = aa[i]%n-aa[j]%n
#     return min(a, b), max(a, b)

def ask(i, j):
    print("?", i+1, j+1, flush=True)
    p, q = map(int, input().split())
    return p, q

n = int(input())
# aa = list(map(int, input().split()))
m = n**2-n
pqi = defaultdict(list)
for i in range(m-1):
    p, q = ask(i, m-1)
    pqi[p, q].append(i)
# print(pqi)

ans = [0]*m
(p0, q0), mni = min(pqi.items(), key=lambda x: sum(x[0]))
(p1, q1), mxi = max(pqi.items(), key=lambda x: sum(x[0]))
# print(p0, q0, mni)
# print(p1, q1, mxi)

if (p0, q0) == (0, 1):
    a = 1
    b = 0
    ans[mxi[0]] = n**2-1
elif (p1, q1) == (-1, 0):
    a = n-1
    b = n-1
    ans[mni[0]] = n
else:
    can = [(n-1-p1, n-1-q1), (n-1-q1, n-1-p1)]
    if (1-p0, -q0) in can:
        a, b = 1-p0, -q0
    else:
        a, b = 1-q0, -p0
    ans[mxi[0]] = n**2-1
    ans[mni[0]] = n

ans[-1] = a*n+b
# print(ans)

for (p, q), ii in pqi.items():
    if len(ii) == 1:
        i = ii[0]
        if ans[i]: continue
        x0, y0 = a+p, b+q
        x1, y1 = a+q, b+p
        if 1 <= x0 < n and 0 <= y0 < n:
            ans[i] = x0*n+y0
        else:
            ans[i] = x1*n+y1

(p2, q2), [ci] = max(pqi.items(), key=lambda x: x[0][1]-x[0][0])
# print(p2, q2, ci)

c, d = divmod(ans[ci], n)
for (ap, aq), ii in pqi.items():
    if len(ii) == 2:
        i0, i1 = ii
        cp, cq = ask(i0, ci)
        x0, y0 = c+cp, d+cq
        x1, y1 = c+cq, d+cp
        if 1 <= x0 < n and 0 <= y0 < n:
            ans[i0] = x0*n+y0
        else:
            ans[i0] = x1*n+y1

        x0, y0 = a+ap, b+aq
        x1, y1 = a+aq, b+ap
        if ans[i0] == x0*n+y0: ans[i1] = x1*n+y1
        else: ans[i1] = x0*n+y0

print("!", end=" ")
print(*ans)
0