結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,352 KB
testcase_01 AC 39 ms
52,224 KB
testcase_02 AC 39 ms
52,352 KB
testcase_03 AC 40 ms
52,224 KB
testcase_04 AC 40 ms
52,608 KB
testcase_05 AC 42 ms
52,480 KB
testcase_06 AC 41 ms
52,352 KB
testcase_07 AC 39 ms
52,224 KB
testcase_08 AC 43 ms
52,224 KB
testcase_09 AC 39 ms
51,968 KB
testcase_10 AC 39 ms
52,352 KB
testcase_11 AC 40 ms
52,224 KB
testcase_12 AC 42 ms
52,224 KB
testcase_13 AC 41 ms
52,352 KB
testcase_14 AC 39 ms
52,480 KB
testcase_15 AC 41 ms
52,352 KB
testcase_16 AC 41 ms
52,096 KB
testcase_17 AC 40 ms
52,608 KB
testcase_18 AC 40 ms
52,224 KB
testcase_19 AC 93 ms
82,304 KB
testcase_20 AC 88 ms
78,720 KB
testcase_21 AC 107 ms
90,368 KB
testcase_22 AC 127 ms
99,200 KB
testcase_23 AC 119 ms
94,592 KB
testcase_24 AC 122 ms
97,536 KB
testcase_25 AC 120 ms
97,152 KB
testcase_26 AC 91 ms
79,232 KB
testcase_27 AC 102 ms
84,736 KB
testcase_28 AC 108 ms
89,344 KB
testcase_29 AC 119 ms
96,256 KB
testcase_30 AC 125 ms
96,000 KB
testcase_31 AC 105 ms
88,576 KB
testcase_32 AC 143 ms
110,336 KB
testcase_33 AC 85 ms
78,336 KB
testcase_34 AC 95 ms
80,256 KB
testcase_35 AC 86 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 % 2 == 1:
        if n == 5:
            a = [3, 4, 2, 2, 3, 3, 2, 4, 4]
            b = make_b(2)
            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 >= 2
    if n == 2:
        return [0, 0, 0, 1, 1, 1]
    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