結果

問題 No.2496 LCM between Permutations
ユーザー pitPpitP
提出日時 2023-10-07 10:31:57
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,010 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 95,548 KB
平均クエリ数 951.03
最終ジャッジ日時 2023-10-07 10:32:06
合計ジャッジ時間 8,956 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
87,336 KB
testcase_01 AC 96 ms
87,492 KB
testcase_02 AC 97 ms
87,780 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 97 ms
87,324 KB
testcase_06 AC 99 ms
87,108 KB
testcase_07 AC 98 ms
87,440 KB
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 100 ms
87,408 KB
testcase_14 WA -
testcase_15 AC 113 ms
91,388 KB
testcase_16 AC 123 ms
91,392 KB
testcase_17 AC 123 ms
92,412 KB
testcase_18 AC 241 ms
93,768 KB
testcase_19 AC 200 ms
93,208 KB
testcase_20 AC 244 ms
93,780 KB
testcase_21 AC 261 ms
93,972 KB
testcase_22 AC 221 ms
93,204 KB
testcase_23 AC 259 ms
93,848 KB
testcase_24 AC 240 ms
94,116 KB
testcase_25 AC 299 ms
93,488 KB
testcase_26 AC 275 ms
93,596 KB
testcase_27 AC 268 ms
93,928 KB
testcase_28 AC 275 ms
93,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
if N == 1:
    print('!', 1, 1)
    exit()

import math
def is_prime(n):
    sqrt_n = math.ceil(math.sqrt(n))
    for i in range(2, sqrt_n):
        if n % i == 0:
            return False
    return True

P = -1
for i in range(N, -1, -1):
    if is_prime(i) :
        P = i
        break

def query(i, j):
    print("?", i, j)
    z = int(input())
    return z

A = [-1] * (N + 1)
B = [-1] * (N + 1)
p_idx = []
for i in range(1, N + 1):
    z = query(i, i)
    if z % P == 0:
        p_idx.append(i)

x = y = -1
# A[x] = B[y] = P
if p_idx == 1:     
    x = y = p_idx[0]
else:
    z = query(p_idx[0], p_idx[1])
    if z % P == 0: 
        x = p_idx[0] 
        y = p_idx[1]
    else:
        y = p_idx[0]
        x = p_idx[1]

A[x] = B[y] = P

# A[i], B[y]
for i in range(1, N + 1):
    if i == x :
        continue
    z = query(i, y)
    A[i] = z // P

# A[x], B[i]
for i in range(1, N + 1):
    if i == y :
        continue
    z = query(x, i)
    B[i] = z // P

print("!", *A[1:], *B[1:])
0