結果

問題 No.2732 Similar Permutations
ユーザー Yukino DX.
提出日時 2024-04-27 15:00:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 116,352 KB
最終ジャッジ日時 2024-11-15 18:02:19
合計ジャッジ時間 23,536 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 101
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import permutations


def solve_less10():
    hm = dict()
    for p in permutations(range(1, n + 1), n):
        xor = 0
        for i in range(n):
            xor ^= p[i] + a[i]

        if xor in hm:
            print(*hm[xor])
            print(*p)
            exit()

        hm[xor] = p

    print(-1)


def solve_more10():
    xor_base = 0
    for i in range(11, n + 1):
        xor_base ^= i + a[i - 1]

    hm = dict()
    for p in permutations(range(1, 11), 10):
        xor = 0
        for i in range(10):
            xor ^= p[i] + a[i]

        if xor in hm:
            print(*(hm[xor] + tuple(range(11, n + 1))))
            print(*(p + tuple(range(11, n + 1))))
            exit()

        hm[xor] = p

    print(-1)


n = int(input())
a = list(map(int, input().split()))

if n <= 10:
    solve_less10()
else:
    solve_more10()
0