結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー flygon
提出日時 2024-04-06 14:13:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 82,988 KB
実行使用メモリ 131,324 KB
最終ジャッジ日時 2024-10-01 03:50:28
合計ジャッジ時間 7,381 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n = int(input())
if n == 1:
    print(-1)
    exit()
elif n == 2:
    print(*[5,2,3,6,1,4])
    exit()
a = []
b = [i+1 for i in range(n)]
c = []
for i in range(n):
    x,y = n+2*i+1, n+2*i+2
    a.append(x)
    c.append(y)


if n % 4 == 1 or n % 4 == 2:
    a[-1], c[-2] = c[-2], a[-1]
    g = (n*(n+1)//2 + 2*n - 1)//2
else:
    g = (n*(n+1)//2)//2
now = 0
for i in range(n)[::-1]:
    x,y = a[i],c[i]
    if abs(b[i]*(a[i]-c[i]))+now <= g:
        now += abs(b[i]*(a[i]-c[i]))
        a[i] = min(x,y)
        c[i] = max(x,y)
    else:
        a[i] = max(x,y)
        c[i] = min(x,y)
ans = a+b+c

print(*ans)



0