結果

問題 No.2496 LCM between Permutations
ユーザー yupoohyupooh
提出日時 2023-10-06 22:14:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,756 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 93,760 KB
平均クエリ数 953.17
最終ジャッジ日時 2023-10-06 22:14:55
合計ジャッジ時間 6,804 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
87,732 KB
testcase_01 AC 93 ms
87,128 KB
testcase_02 AC 96 ms
87,140 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 94 ms
87,264 KB
testcase_08 AC 97 ms
87,360 KB
testcase_09 WA -
testcase_10 AC 96 ms
87,052 KB
testcase_11 WA -
testcase_12 AC 95 ms
87,492 KB
testcase_13 AC 100 ms
87,068 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 111 ms
91,732 KB
testcase_17 AC 114 ms
92,764 KB
testcase_18 AC 208 ms
92,732 KB
testcase_19 AC 176 ms
92,328 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 188 ms
92,572 KB
testcase_23 WA -
testcase_24 AC 214 ms
92,680 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
def isprime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1
    
    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True
n=int(input())
if n==1:
  print("!",1,1,flush=True)
  exit()
for i in range(n,0,-1):
  if isprime(i):
    x=i
    break
l=[]
for i in range(n):
  print("?",1,i+1,flush=True)
  l.append(int(input()))
cnt=0
for i in range(n):
  if l[i]%x==0:
    cnt+=1
    idx=i
if cnt==n:
  B=[]
  for i in l:
    B.append(i//x)
  for i in range(n):
    if B[i]==1:
      idx=i
      break
  A=[]
  for i in range(n):
    print("?",i+1,idx+1,flush=True)
    A.append(int(input()))
  AA=A[:]
  AA.sort()
  if AA==[i+1 for i in range(n)]:
    for i in range(n):
      if i==idx:
        continue
      if B[i]==1:
        B[i]=x
  else:
    B[idx]=x
    for i in range(n):
      A[i]//=x
  A+=B
  print("!",*A,flush=True)
  exit()
A=[]
for i in range(n):
  print("?",i+1,idx+1,flush=True)
  A.append(int(input())//x)
for i in range(n):
  if A[i]==1:
    idx=i
    break
B=[]
for i in range(n):
  print("?",idx+1,i+1,flush=True)
  B.append(int(input()))
BB=B[:]
BB.sort()
if BB==[i+1 for i in range(n)]:
  for i in range(n):
    if i==idx:
      continue
    if A[i]==1:
      A[i]=x
else:
  A[idx]=x
  for i in range(n):
    B[i]//=x
A+=B
print("!",*A,flush=True)
exit()  
0