結果

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

ソースコード

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())
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