結果

問題 No.1061 素敵な数列
ユーザー koba-e964koba-e964
提出日時 2020-05-25 14:43:58
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,668 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 98,944 KB
最終ジャッジ日時 2024-04-21 03:43:59
合計ジャッジ時間 8,594 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,968 KB
testcase_01 AC 38 ms
52,480 KB
testcase_02 AC 39 ms
52,096 KB
testcase_03 RE -
testcase_04 AC 40 ms
52,224 KB
testcase_05 AC 39 ms
52,480 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 40 ms
52,608 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 41 ms
52,224 KB
testcase_13 AC 40 ms
52,224 KB
testcase_14 AC 39 ms
52,352 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 AC 41 ms
52,608 KB
testcase_18 AC 40 ms
52,352 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 129 ms
98,944 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 87 ms
79,616 KB
testcase_27 AC 101 ms
84,608 KB
testcase_28 RE -
testcase_29 AC 120 ms
96,384 KB
testcase_30 AC 124 ms
96,000 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 AC 93 ms
80,256 KB
testcase_35 AC 89 ms
78,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3

import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

# The author read the editorial.


def join_b(a, b):
    ret = a.copy()
    last = ret.pop()
    ret.append(b.pop())
    ret.append(last)
    for elem in reversed(b):
        ret.append(elem)
    return ret


def make_a(n):
    assert n != 2
    if n == 0:
        return []
    if n % 2 == 1:
        if n == 5:
            a = [3, 4, 2, 2, 3, 3, 2, 4, 4]
            b = make_b(1)
            return join_b(a, b)
        a = []
        for i in range(n // 2, n):
            a.append(i)
        for i in range(n // 2, n):
            a.append(i)
            a.append(i)
        b = make_a(n // 2)
        return a + b
    assert n % 2 == 0
    a = []
    for i in range(n // 2, n):
        a.append(i)
    a.append(n - 1)
    for i in range(n // 2, n - 1):
        a.append(i)
        a.append(i)
    a.append(n - 1)
    b = make_b(n // 2)
    return join_b(a, b)


def make_b(n):
    assert n > 0
    if n % 2 == 1:
        a = []
        for i in range(n // 2, n):
            a.append(i)
        for i in range(n // 2, n):
            a.append(i)
            a.append(i)
        b = make_b(n // 2)
        return a + b
    assert n % 2 == 0
    a = []
    for i in range(n // 2, n):
        a.append(i)
    a.append(n - 1)
    for i in range(n // 2, n - 1):
        a.append(i)
        a.append(i)
    a.append(n - 1)
    b = make_a(n // 2)
    return b + a


n = int(readline())

if n == 2:
    print(-1)
    exit()

ans = make_a(n)
for i in range(3 * n):
    print(ans[i], end='')
    if i == 3 * n - 1:
        print()
    else:
        print(' ', end='')
0