/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 34ms 17.246 MiB
#2 Wrong Answer 38ms 17.871 MiB

Code

import sys

def beautiful_permutation(N):
    # impossible small cases
    if N in (2, 3, 4, 6):
        return []
    if N == 1:
        return [1]
    if N == 5:
        # one fixed base solution for N=5
        return [5, 2, 4, 1, 3]

    ans = []
    # 1) all odd numbers >= 7
    for x in range(7, N+1, 2):
        ans.append(x)
    # 2) the fixed seed [5,1,3]
    ans.extend([5, 1, 3])
    # 3) the small evens [2,4,6]
    ans.extend([2, 4, 6])
    # 4) all remaining evens >= 8
    for x in range(8, N+1, 2):
        ans.append(x)
    return ans

def main():
    data = sys.stdin.read().strip().split()
    T = int(data[0])
    idx = 1
    out_lines = []
    for _ in range(T):
        N = int(data[idx]); idx += 1
        perm = beautiful_permutation(N)
        if not perm:
            out_lines.append("-1")
        else:
            out_lines.append(" ".join(map(str, perm)))
    sys.stdout.write("\n".join(out_lines))

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1203 D. Roy Loves Permutation
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2025-06-08 14:29:37
Judged At
2025-06-08 14:29:37
Judged By
Score
0
Total Time
38ms
Peak Memory
17.871 MiB