Submission #69539251


Source Code Expand

from sys import stdin
def input():
    return stdin.readline().rstrip("\n")

memo = {
    (1, 0): (),
    (1, 1): (1,),

    (2, 0): (),
    (2, 1): (),
    (2, 2): (1, 2),

    (3, 0): (),
    (3, 1): (),
    (3, 2): (1, 3, 2),
    (3, 3): (1, 2, 3),

    (4, 0): (),
    (4, 1): (),
    (4, 2): (1, 2, 4, 3),
    (4, 3): (1, 4, 3, 2),
    (4, 4): (1, 2, 3, 4),

    (5, 0): (),
    (5, 1): (2, 5, 3, 1, 4),
    (5, 2): (1, 2, 3, 5, 4),
    (5, 3): (1, 2, 5, 4, 3),
    (5, 4): (1, 3, 2, 5, 4),
    (5, 5): (1, 2, 3, 4, 5),

    (6, 0): (),
    (6, 1): (1, 3, 6, 4, 2, 5),
    (6, 2): (1, 2, 3, 4, 6, 5),
    (6, 3): (1, 2, 3, 6, 5, 4),
    (6, 4): (1, 2, 4, 3, 6, 5),
    (6, 5): (1, 6, 5, 4, 3, 2),
    (6, 6): (1, 2, 3, 4, 5, 6),

    (7, 0): (),
    (7, 1): (1, 2, 4, 7, 5, 3, 6),
    (7, 2): (1, 2, 3, 4, 5, 7, 6),
    (7, 3): (1, 2, 3, 4, 7, 6, 5),
    (7, 4): (1, 2, 3, 5, 4, 7, 6),
    (7, 5): (1, 2, 7, 6, 5, 4, 3),
    (7, 6): (1, 3, 2, 5, 4, 7, 6),
    (7, 7): (1, 2, 3, 4, 5, 6, 7),

    (8, 0): (3, 4, 8, 7, 2, 1, 5, 6),
    (8, 1): (1, 2, 3, 5, 8, 6, 4, 7),
    (8, 2): (1, 2, 3, 4, 5, 6, 8, 7),
    (8, 3): (1, 2, 3, 4, 5, 8, 7, 6),
    (8, 4): (1, 2, 3, 4, 6, 5, 8, 7),
    (8, 5): (1, 2, 3, 8, 7, 6, 5, 4),
    (8, 6): (1, 2, 4, 3, 6, 5, 8, 7),
    (8, 7): (1, 8, 7, 6, 5, 4, 3, 2),
    (8, 8): (1, 2, 3, 4, 5, 6, 7, 8),

    (9, 0): (1, 4, 5, 9, 8, 3, 2, 6, 7),
    (9, 1): (1, 2, 3, 4, 6, 9, 7, 5, 8),
    (9, 2): (1, 2, 3, 4, 5, 6, 7, 9, 8),
    (9, 3): (1, 2, 3, 4, 5, 6, 9, 8, 7),
    (9, 4): (1, 2, 3, 4, 5, 7, 6, 9, 8),
    (9, 5): (1, 2, 3, 4, 9, 8, 7, 6, 5),
    (9, 6): (1, 2, 3, 5, 4, 7, 6, 9, 8),
    (9, 7): (1, 2, 9, 8, 7, 6, 5, 4, 3),
    (9, 8): (1, 3, 2, 5, 4, 7, 6, 9, 8),
    (9, 9): (1, 2, 3, 4, 5, 6, 7, 8, 9),

    (10, 0): (1, 2, 5, 6, 10, 9, 4, 3, 7, 8),
    (10, 1): (1, 2, 3, 4, 5, 7, 10, 8, 6, 9),
    (10, 2): (1, 2, 3, 4, 5, 6, 7, 8, 10, 9),
    (10, 3): (1, 2, 3, 4, 5, 6, 7, 10, 9, 8),
    (10, 4): (1, 2, 3, 4, 5, 6, 8, 7, 10, 9),
    (10, 5): (1, 2, 3, 4, 5, 10, 9, 8, 7, 6),
    (10, 6): (1, 2, 3, 4, 6, 5, 8, 7, 10, 9),
    (10, 7): (1, 2, 3, 10, 9, 8, 7, 6, 5, 4),
    (10, 8): (1, 2, 4, 3, 6, 5, 8, 7, 10, 9),
    (10, 9): (1, 4, 3, 2, 7, 6, 5, 10, 9, 8),
    (10, 10): (1, 2, 3, 4, 5, 6, 7, 8, 9, 10),

    (11, 0): (1, 2, 3, 6, 7, 11, 10, 5, 4, 8, 9),
    (11, 1): (1, 2, 3, 4, 5, 6, 8, 11, 9, 7, 10),
    (11, 2): (1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 10),
    (11, 3): (1, 2, 3, 4, 5, 6, 7, 8, 11, 10, 9),
    (11, 4): (1, 2, 3, 4, 5, 6, 7, 9, 8, 11, 10),
    (11, 5): (1, 2, 3, 4, 5, 6, 11, 10, 9, 8, 7),
    (11, 6): (1, 2, 3, 4, 5, 7, 6, 9, 8, 11, 10),
    (11, 7): (1, 2, 3, 4, 11, 10, 9, 8, 7, 6, 5),
    (11, 8): (1, 2, 3, 5, 4, 7, 6, 9, 8, 11, 10),
    (11, 9): (1, 2, 5, 4, 3, 8, 7, 6, 11, 10, 9),
    (11, 10): (1, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10),
    (11, 11): (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
}

def solve1(n, k):
    if n <= 11:
        return memo[n, k]
    if k == 0:
        t = [*range(n // 4 * 1, n // 4 * 2), *range(n // 4 * 3, n)[::-1], *range(n // 4)[::-1], *range(n // 4 * 2, n // 4 * 3)]
        return tuple(e + 1 for e in t)
    if k == 1:
        t = [*range(1, n - 4), *[e - 11 + n for e in (8, 11, 9, 7, 10)]]
        return tuple(t)
    else:
        t = [*range(n - k), *range(n - k, n)[::-1]]
        return tuple(e + 1 for e in t)


case_t = 1
case_t = int(input())
for _ in [None] * case_t:
    n, k = map(lambda s_: int(s_), input().split())
    ans = solve1(n, k)
    if ans == ():
        print(-1)
    else:
        print(*ans)


Submission Info

Submission Time
Task D - LIS ∩ LDS
User wasd314
Language Python (PyPy 3.10-v7.3.12)
Score 700
Code Size 3642 Byte
Status AC
Exec Time 132 ms
Memory 108292 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 1
AC × 24
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_max_00.txt, 02_max_01.txt, 02_max_02.txt, 02_max_03.txt, 02_max_04.txt, 02_max_05.txt, 03_small_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 62 ms 80096 KiB
01_random_00.txt AC 86 ms 89364 KiB
01_random_01.txt AC 93 ms 99092 KiB
01_random_02.txt AC 86 ms 93956 KiB
01_random_03.txt AC 87 ms 90152 KiB
01_random_04.txt AC 86 ms 89948 KiB
01_random_05.txt AC 88 ms 94440 KiB
01_random_06.txt AC 92 ms 105704 KiB
01_random_07.txt AC 83 ms 90944 KiB
01_random_08.txt AC 90 ms 95712 KiB
01_random_09.txt AC 93 ms 97984 KiB
01_random_10.txt AC 85 ms 92568 KiB
01_random_11.txt AC 91 ms 95796 KiB
01_random_12.txt AC 86 ms 88284 KiB
01_random_13.txt AC 87 ms 91636 KiB
01_random_14.txt AC 92 ms 103760 KiB
01_random_15.txt AC 108 ms 84036 KiB
02_max_00.txt AC 83 ms 93388 KiB
02_max_01.txt AC 92 ms 105780 KiB
02_max_02.txt AC 93 ms 108292 KiB
02_max_03.txt AC 92 ms 106796 KiB
02_max_04.txt AC 93 ms 106396 KiB
02_max_05.txt AC 132 ms 85312 KiB
03_small_00.txt AC 108 ms 83952 KiB