結果

問題 No.2496 LCM between Permutations
ユーザー mkawa2mkawa2
提出日時 2023-10-06 23:05:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,694 bytes
コンパイル時間 94 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 25,832 KB
平均クエリ数 925.90
最終ジャッジ日時 2023-10-06 23:05:05
合計ジャッジ時間 4,670 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
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 WA -
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())
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)
if a0==p:
    for j in range(n):bb[j]//=p
    j1=bb.index(1)
    for i in range(n):aa[i]=ask(i,j1)
else:
    j=0
    while bb[j]!=a0*p:j+=1
    for i in range(n):aa[i]=ask(i,j)//p
    i1=aa.index(1)
    for j in range(n):bb[j]=ask(i1,j)

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