結果

問題 No.2496 LCM between Permutations
ユーザー nautnaut
提出日時 2023-10-06 23:12:26
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,896 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 106,260 KB
平均クエリ数 953.31
最終ジャッジ日時 2023-10-06 23:12:35
合計ジャッジ時間 8,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
88,136 KB
testcase_01 AC 121 ms
88,304 KB
testcase_02 AC 113 ms
88,460 KB
testcase_03 AC 115 ms
88,424 KB
testcase_04 RE -
testcase_05 AC 112 ms
88,180 KB
testcase_06 RE -
testcase_07 AC 114 ms
88,704 KB
testcase_08 AC 113 ms
88,660 KB
testcase_09 AC 115 ms
88,344 KB
testcase_10 AC 144 ms
88,220 KB
testcase_11 AC 114 ms
87,828 KB
testcase_12 AC 117 ms
88,440 KB
testcase_13 AC 116 ms
88,576 KB
testcase_14 AC 117 ms
87,964 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 138 ms
92,764 KB
testcase_18 RE -
testcase_19 AC 216 ms
95,532 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 284 ms
98,960 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
権限があれば一括ダウンロードができます

ソースコード

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)]

    res = [[-1 for _ in range(N)] 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)

        res[r][i] = 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)

    cand = [i for i in range(N)]
    random.shuffle(cand)

    for i in range(N):
        r = cand[i]

        if A[r] != -1:
            continue

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

            res[r][c] = x

        b_one_cand_nxt = []

        m = min(values)
        A[r] = 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

        if res[i][j] != -1:
            A[i] = res[i][j]
            continue

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

        res[i][j] = x

        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

        if res[j][i] != -1:
            B[i] = res[j][i]
            continue

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

        res[j][i] = x

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


main()
0