結果

問題 No.1061 素敵な数列
ユーザー koba-e964koba-e964
提出日時 2020-05-25 15:25:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,778 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 110,848 KB
最終ジャッジ日時 2024-04-21 03:44:32
合計ジャッジ時間 6,240 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,480 KB
testcase_01 AC 45 ms
52,608 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 43 ms
52,480 KB
testcase_04 AC 41 ms
52,352 KB
testcase_05 AC 41 ms
52,096 KB
testcase_06 AC 44 ms
52,992 KB
testcase_07 AC 42 ms
52,096 KB
testcase_08 AC 42 ms
52,352 KB
testcase_09 AC 41 ms
52,480 KB
testcase_10 AC 41 ms
52,096 KB
testcase_11 AC 42 ms
52,224 KB
testcase_12 AC 43 ms
52,480 KB
testcase_13 AC 41 ms
52,096 KB
testcase_14 AC 42 ms
52,480 KB
testcase_15 AC 44 ms
52,224 KB
testcase_16 AC 42 ms
52,096 KB
testcase_17 AC 43 ms
52,352 KB
testcase_18 AC 42 ms
52,224 KB
testcase_19 AC 100 ms
82,048 KB
testcase_20 AC 93 ms
78,976 KB
testcase_21 AC 114 ms
90,368 KB
testcase_22 AC 140 ms
99,072 KB
testcase_23 AC 128 ms
94,592 KB
testcase_24 AC 133 ms
97,536 KB
testcase_25 AC 131 ms
97,280 KB
testcase_26 AC 95 ms
79,104 KB
testcase_27 AC 106 ms
84,480 KB
testcase_28 AC 114 ms
89,088 KB
testcase_29 AC 127 ms
96,000 KB
testcase_30 AC 133 ms
96,000 KB
testcase_31 AC 112 ms
88,320 KB
testcase_32 AC 159 ms
110,848 KB
testcase_33 AC 91 ms
78,848 KB
testcase_34 AC 98 ms
80,256 KB
testcase_35 AC 90 ms
78,720 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 == 5:
        a = [3, 4, 2, 2, 3, 3, 2, 4, 4]
        b = make_b(2)
        return join_b(a, b)
    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_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 >= 2
    if n == 3:
        return [0, 0, 0, 2, 1, 2, 1, 1, 2]
    if n == 4:
        return [0, 0, 0, 3, 1, 3, 1, 1, 2, 2, 3, 2]
    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