/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 36ms 17.316 MiB
#2 Accepted 47ms 18.398 MiB

Code

import sys

def solve():
    try:
        t_str = sys.stdin.readline()
        if not t_str:
            return
        t = int(t_str)
        for _ in range(t):
            n = int(sys.stdin.readline())
            p = list(range(1, n + 1))

            if n % 2 == 0:
                for i in range(0, n, 2):
                    p[i], p[i+1] = p[i+1], p[i]
            else:
                if n == 3:
                    p = [2, 3, 1]
                else:
                    for i in range(0, n - 3, 2):
                        p[i], p[i+1] = p[i+1], p[i]
                    
                    last_three_idx = n - 3
                    original_p_n_minus_2 = p[last_three_idx]
                    
                    p[last_three_idx] = p[last_three_idx + 1]
                    p[last_three_idx + 1] = p[last_three_idx + 2]
                    p[last_three_idx + 2] = original_p_n_minus_2

            print(*p)
    except (IOError, ValueError):
        return

solve()

Information

Submit By
Type
Submission
Problem
P1210 A. Smallest Permutation
Contest
Educational Round 1
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2025-07-14 17:56:30
Judged At
2025-07-14 17:56:30
Judged By
Score
100
Total Time
47ms
Peak Memory
18.398 MiB