結果

問題 No.2496 LCM between Permutations
ユーザー mkawa2mkawa2
提出日時 2023-10-06 23:22:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 2,040 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 11,184 KB
実行使用メモリ 25,780 KB
平均クエリ数 926.31
最終ジャッジ日時 2023-10-06 23:22:30
合計ジャッジ時間 5,282 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 45 ms
25,212 KB
testcase_02 RE -
testcase_03 AC 45 ms
24,568 KB
testcase_04 AC 45 ms
25,156 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 46 ms
24,712 KB
testcase_08 WA -
testcase_09 AC 47 ms
24,708 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class Sieve:
    def __init__(self, n):
        self.plist = [2]
        min_prime_factor = [2, 0]*(n//2+1)
        for x in range(3, n+1, 2):
            if min_prime_factor[x] == 0:
                min_prime_factor[x] = x
                self.plist.append(x)
                if x**2 > n: continue
                for y in range(x**2, n+1, 2*x):
                    if min_prime_factor[y] == 0:
                        min_prime_factor[y] = x
        self.min_prime_factor = min_prime_factor

    def isprime(self, x):
        return self.min_prime_factor[x] == x

    def pf(self, x):
        pp, ee = [], []
        while x > 1:
            mpf = self.min_prime_factor[x]
            if pp and mpf == pp[-1]:
                ee[-1] += 1
            else:
                pp.append(mpf)
                ee.append(1)
            x //= mpf
        return pp, ee

    # unsorted
    def factor(self, a):
        ff = [1]
        pp, ee = self.pf(a)
        for p, e in zip(pp, ee):
            ff, gg = [], ff
            w = p
            for _ in range(e):
                for f in gg: ff.append(f*w)
                w *= p
            ff += gg
        return ff

from functools import lru_cache

@lru_cache(None)
def ask(i, j):
    print("?", i+1, j+1, flush=True)
    res = int(input())
    return res

n = int(input())

if n==1:
    print("!",1,1,flush=True)
    exit()

sv = Sieve(n)
p = sv.plist[-1]
aa = [0]*n
bb = [0]*n
for j in range(n):bb[j] = ask(0, j)
a0=min(bb)
aa[0]=a0
if a0==p:
    for j in range(n):bb[j]//=p
    js=[]
    for j in range(n):
        if bb[j]==1:js.append(j)
    l,r=js
    if ask(1,l)<ask(1,r):
        j1=l
        bb[r]=p
    else:
        j1=r
        bb[l]=p
    for i in range(n):aa[i]=ask(i,j1)
else:
    jp=0
    while bb[jp]!=a0*p:jp+=1
    ii=[]
    for i in range(1,n):
        aa[i]=ask(i,jp)//p
        if aa[i]==1:ii.append(i)
    l,r=ii
    j=jp+1
    if jp:j=jp-1
    if ask(l,j)%p:
        i1=l
    else:
        i1=r
    for j in range(n):bb[j]=ask(i1,j)

print("!", *aa, *bb, flush=True)
0