結果

問題 No.2496 LCM between Permutations
ユーザー nautnaut
提出日時 2023-10-06 23:01:21
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,462 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 99,804 KB
平均クエリ数 953.48
最終ジャッジ日時 2023-10-06 23:01:30
合計ジャッジ時間 8,745 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
88,044 KB
testcase_01 AC 113 ms
88,620 KB
testcase_02 AC 112 ms
87,984 KB
testcase_03 AC 140 ms
87,748 KB
testcase_04 AC 113 ms
88,352 KB
testcase_05 RE -
testcase_06 AC 120 ms
88,152 KB
testcase_07 AC 113 ms
88,484 KB
testcase_08 AC 114 ms
88,288 KB
testcase_09 AC 113 ms
88,708 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 115 ms
87,936 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 127 ms
88,384 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 229 ms
94,528 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 316 ms
94,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import lcm, gcd
import random


def main():
    N = int(input())

    A = [-1 for _ in range(N)]
    B = [-1 for _ in range(N)]

    b_lcm_azero = []

    r = random.randint(0, N - 1)

    for i in range(N):
        print("? {} {}".format(r + 1, i + 1), flush=True)
        x = int(input())
        b_lcm_azero.append(x)

    a_r = min(b_lcm_azero)
    A[r] = a_r

    b_one_cand = []

    for i in range(N):
        if b_lcm_azero[i] == a_r:
            b_one_cand.append(i)

    for i in range(N):
        values = []
        for c in b_one_cand:
            print("? {} {}".format(i + 1, c + 1), flush=True)
            x = int(input())
            values.append(x)

        b_one_cand_nxt = []

        m = min(values)
        A[i] = m

        for j in range(len(b_one_cand)):
            if values[j] == m:
                b_one_cand_nxt.append(b_one_cand[j])

        b_one_cand = b_one_cand_nxt

        if len(b_one_cand) == 1:
            break

    j = b_one_cand[0]

    B[j] = 1

    for i in range(N):
        if A[i] != -1:
            continue

        print("? {} {}".format(i + 1, j + 1), flush=True)
        x = int(input())

        A[i] = x

    j = -1

    for i in range(N):
        if A[i] == 1:
            j = i

    for i in range(N):
        if B[i] != -1:
            continue

        print("? {} {}".format(j + 1, i + 1), flush=True)
        x = int(input())
        B[i] = x

    print("!", *A, *B, flush=True)


main()
0