結果

問題 No.1306 Exactly 2 Digits
ユーザー shotoyooshotoyoo
提出日時 2020-12-03 12:22:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,340 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 98,436 KB
平均クエリ数 1425.22
最終ジャッジ日時 2023-09-24 08:18:09
合計ジャッジ時間 36,745 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 139 ms
89,740 KB
testcase_02 AC 141 ms
90,160 KB
testcase_03 AC 140 ms
89,900 KB
testcase_04 AC 140 ms
89,960 KB
testcase_05 AC 138 ms
90,480 KB
testcase_06 AC 139 ms
90,820 KB
testcase_07 AC 139 ms
89,952 KB
testcase_08 AC 139 ms
90,252 KB
testcase_09 AC 139 ms
90,012 KB
testcase_10 AC 139 ms
90,312 KB
testcase_11 AC 142 ms
90,332 KB
testcase_12 AC 143 ms
90,036 KB
testcase_13 AC 143 ms
89,972 KB
testcase_14 AC 141 ms
90,708 KB
testcase_15 AC 140 ms
90,192 KB
testcase_16 AC 140 ms
89,936 KB
testcase_17 AC 141 ms
90,736 KB
testcase_18 AC 142 ms
90,144 KB
testcase_19 AC 142 ms
90,004 KB
testcase_20 AC 143 ms
89,860 KB
testcase_21 AC 141 ms
90,672 KB
testcase_22 AC 142 ms
90,656 KB
testcase_23 AC 144 ms
90,144 KB
testcase_24 AC 141 ms
89,868 KB
testcase_25 AC 142 ms
90,736 KB
testcase_26 AC 141 ms
89,948 KB
testcase_27 AC 143 ms
90,268 KB
testcase_28 AC 142 ms
90,224 KB
testcase_29 AC 141 ms
90,116 KB
testcase_30 AC 140 ms
89,668 KB
testcase_31 AC 140 ms
90,016 KB
testcase_32 AC 140 ms
90,236 KB
testcase_33 AC 145 ms
90,396 KB
testcase_34 AC 144 ms
89,692 KB
testcase_35 AC 141 ms
90,172 KB
testcase_36 AC 144 ms
90,044 KB
testcase_37 AC 142 ms
90,220 KB
testcase_38 AC 142 ms
90,040 KB
testcase_39 AC 146 ms
90,244 KB
testcase_40 AC 142 ms
90,532 KB
testcase_41 AC 144 ms
89,940 KB
testcase_42 AC 144 ms
89,984 KB
testcase_43 AC 144 ms
90,028 KB
testcase_44 AC 148 ms
90,520 KB
testcase_45 AC 147 ms
89,820 KB
testcase_46 AC 151 ms
93,656 KB
testcase_47 AC 152 ms
93,332 KB
testcase_48 AC 153 ms
93,944 KB
testcase_49 AC 155 ms
93,844 KB
testcase_50 AC 158 ms
93,508 KB
testcase_51 AC 162 ms
94,520 KB
testcase_52 AC 165 ms
93,536 KB
testcase_53 AC 167 ms
94,300 KB
testcase_54 AC 169 ms
94,388 KB
testcase_55 AC 175 ms
94,216 KB
testcase_56 AC 185 ms
94,356 KB
testcase_57 AC 187 ms
94,524 KB
testcase_58 AC 192 ms
95,444 KB
testcase_59 AC 196 ms
95,492 KB
testcase_60 AC 196 ms
94,536 KB
testcase_61 AC 195 ms
93,988 KB
testcase_62 AC 213 ms
94,428 KB
testcase_63 AC 212 ms
94,872 KB
testcase_64 AC 216 ms
94,900 KB
testcase_65 AC 227 ms
94,412 KB
testcase_66 AC 234 ms
94,840 KB
testcase_67 AC 236 ms
94,644 KB
testcase_68 AC 239 ms
95,192 KB
testcase_69 AC 254 ms
95,044 KB
testcase_70 AC 265 ms
95,628 KB
testcase_71 AC 285 ms
98,092 KB
testcase_72 AC 288 ms
97,372 KB
testcase_73 AC 277 ms
96,164 KB
testcase_74 AC 297 ms
97,248 KB
testcase_75 AC 281 ms
95,832 KB
testcase_76 AC 306 ms
96,248 KB
testcase_77 AC 312 ms
96,116 KB
testcase_78 AC 315 ms
95,848 KB
testcase_79 AC 320 ms
96,000 KB
testcase_80 AC 326 ms
96,356 KB
testcase_81 AC 310 ms
97,040 KB
testcase_82 AC 340 ms
96,564 KB
testcase_83 AC 350 ms
96,492 KB
testcase_84 AC 353 ms
96,356 KB
testcase_85 AC 367 ms
97,364 KB
testcase_86 AC 351 ms
96,568 KB
testcase_87 AC 359 ms
96,544 KB
testcase_88 AC 366 ms
97,172 KB
testcase_89 AC 357 ms
97,020 KB
testcase_90 AC 314 ms
97,004 KB
testcase_91 AC 350 ms
96,952 KB
testcase_92 AC 337 ms
97,136 KB
testcase_93 AC 356 ms
96,344 KB
testcase_94 AC 338 ms
96,860 KB
testcase_95 AC 365 ms
96,488 KB
testcase_96 AC 344 ms
96,724 KB
testcase_97 AC 331 ms
96,544 KB
testcase_98 AC 331 ms
97,888 KB
testcase_99 AC 357 ms
96,912 KB
testcase_100 AC 345 ms
96,252 KB
testcase_101 AC 359 ms
96,548 KB
testcase_102 AC 344 ms
96,984 KB
testcase_103 AC 346 ms
96,680 KB
testcase_104 AC 348 ms
96,696 KB
testcase_105 AC 357 ms
97,344 KB
testcase_106 AC 326 ms
97,084 KB
testcase_107 AC 360 ms
97,704 KB
testcase_108 AC 340 ms
97,952 KB
testcase_109 AC 373 ms
97,036 KB
testcase_110 AC 338 ms
97,028 KB
testcase_111 AC 336 ms
96,856 KB
testcase_112 AC 326 ms
97,804 KB
testcase_113 AC 374 ms
97,152 KB
testcase_114 AC 379 ms
97,256 KB
testcase_115 AC 358 ms
97,304 KB
testcase_116 AC 369 ms
97,644 KB
testcase_117 AC 363 ms
96,784 KB
testcase_118 AC 373 ms
97,136 KB
testcase_119 AC 346 ms
98,436 KB
testcase_120 AC 316 ms
95,952 KB
testcase_121 AC 360 ms
96,480 KB
testcase_122 AC 359 ms
97,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

DEBUG = False
def main(n,a):
#     print(a)
    N = 0
    def _sub(i,j):
        p = a[i-1]//n - a[j-1]//n
        q = a[i-1]%n - a[j-1]%n
        if p>q:
            p,q = q,p
        return p,q
    import sys
    def query(i,j):
        nonlocal N
        N += 1
        print("? {0} {1}".format(i, j))
        sys.stdout.flush()
        if DEBUG:
            return _sub(i,j)
        else:
            return tuple(map(int, input().split()))

    m = n*n-n
    ts = [query(1,i) for i in range(2,m+1)]
    from collections import defaultdict
    c = defaultdict(int)
    for t in ts:
        c[t[0]] += 1
        c[t[1]] += 1
    kv = list(c.items())
    kv.sort()
    ys = []
    if kv[0][1]==n-1:
        val = kv[0][0]
        y = kv[0][0] + n - 1
        for item in kv:
            if item[1]==2*n-1 or (item[1]==2*n-3 and item[0]==0):
                break
            else:
                ys.append(item[0])
        x = item[0] + n - 1
    #     print(x,item)
    else:
    #     assert kv[-1][1]==n-1
        y = kv[-1][0]
        val = kv[-1][0]
        for item in kv[::-1]:
            if item[1]==2*n-1 or (item[1]==2*n-3 and item[0]==0):
                break
            else:
                ys.append(item[0])
        x = item[0] + 1
    # done = [[False]*n for _ in range(n)]
    # done[x][y] = True
    ans = [None]*m
    ans[0] = (x,y)
    xy2i = defaultdict(list)
#     print(val, ys, ts)
    for i,t in enumerate(ts):
        xy2i[min(t),max(t)].append(i)
        if val in t:
            if t[0]==val:
                t = (t[1], t[0])
            ans[i+1] = (x-t[0], y-t[1])
            if x-t[0]==n-1 and y-t[1]==0:
                index = i
                large = True
            elif x-t[0]==1 and y-t[1]==n-1:
                index = i
                large = False
        else:
            for vv in ys[1:]:
                if vv in t:
                    if t[0]==vv:
                        t = (t[1],t[0])
                    ans[i+1] = (x-t[0], y-t[1])
    for i,t in enumerate(ts):
        if ans[i+1] is None:
            tt = query(index+2, i+2)
            if large:
                tt = (tt[1],tt[0])
                ans[i+1] = (n-1-tt[0], -tt[1])
            else:
                ans[i+1] = (1-tt[0], n-1-tt[1])
            xx,yy = x - ans[i+1][0], y - ans[i+1][1]
            if xx<=yy:
                for ii in xy2i[xx,yy]:
                    if i==ii:
                        continue
                    if ans[ii+1] is None:
                        ans[ii+1] = (x-yy, y-xx)
    #                     print(ans[ii+1], ii+1)
            else:
                for ii in xy2i[yy,xx]:
                    if i==ii:
                        continue
                    if ans[ii+1] is None:
                        ans[ii+1] = (x-yy, y-xx)
    #                     print(ans[ii+1], ii+1)
    l = [item[0]*n+item[1] for item in ans]
    print("! "+ " ".join(map(str, l)))
#     print(xy2i)
    assert N<=3*n*(n-1)//2
# a = [3,5,4,8,7,6]
from itertools import permutations
from random import shuffle
import random
# random.seed(0)
n = int(input())
l = list(range(n, n*n))
shuffle(l)
main(n,l)
# for a in permutations(range(n, n*n)):
#     main(n,list(a))
0