結果

問題 No.2496 LCM between Permutations
ユーザー naut3naut3
提出日時 2023-10-06 23:01:21
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,462 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 94,816 KB
平均クエリ数 953.21
最終ジャッジ日時 2024-07-26 16:53:35
合計ジャッジ時間 5,782 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,780 KB
testcase_01 AC 56 ms
71,472 KB
testcase_02 AC 57 ms
71,992 KB
testcase_03 AC 62 ms
70,768 KB
testcase_04 AC 61 ms
71,852 KB
testcase_05 AC 59 ms
70,844 KB
testcase_06 AC 57 ms
71,536 KB
testcase_07 AC 57 ms
72,120 KB
testcase_08 AC 58 ms
72,692 KB
testcase_09 RE -
testcase_10 AC 58 ms
71,716 KB
testcase_11 AC 59 ms
73,012 KB
testcase_12 RE -
testcase_13 AC 61 ms
72,300 KB
testcase_14 RE -
testcase_15 AC 71 ms
72,944 KB
testcase_16 AC 73 ms
73,516 KB
testcase_17 RE -
testcase_18 AC 199 ms
93,808 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 176 ms
93,860 KB
testcase_22 AC 176 ms
94,020 KB
testcase_23 RE -
testcase_24 AC 191 ms
93,744 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 216 ms
93,644 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