結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー hiryuNhiryuN
提出日時 2024-04-05 23:04:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 150,268 KB
最終ジャッジ日時 2024-04-05 23:04:16
合計ジャッジ時間 7,797 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 40 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 36 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 36 ms
53,460 KB
testcase_10 AC 57 ms
66,676 KB
testcase_11 AC 57 ms
66,672 KB
testcase_12 AC 56 ms
66,676 KB
testcase_13 AC 56 ms
66,676 KB
testcase_14 AC 57 ms
66,672 KB
testcase_15 AC 163 ms
139,876 KB
testcase_16 AC 174 ms
147,848 KB
testcase_17 AC 137 ms
120,304 KB
testcase_18 AC 177 ms
148,380 KB
testcase_19 AC 158 ms
134,708 KB
testcase_20 AC 130 ms
115,756 KB
testcase_21 AC 178 ms
148,624 KB
testcase_22 AC 148 ms
127,156 KB
testcase_23 AC 138 ms
122,408 KB
testcase_24 AC 128 ms
115,008 KB
testcase_25 AC 180 ms
150,268 KB
testcase_26 AC 181 ms
150,268 KB
testcase_27 AC 184 ms
150,268 KB
testcase_28 AC 178 ms
150,268 KB
testcase_29 AC 177 ms
150,268 KB
testcase_30 AC 176 ms
150,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
mid=list(range(1,n+1))
if n==1:
    print(-1)
    exit()
if n==2:
    print(1,6,2,4,3,5)
    exit()
if n==5:
    print(11,8,13,5,15,1,2,3,4,6,10,9,12,7,14)
    exit()
m=sum(mid)
A=list(range(n+1,3*n+1,2))
B=list(range(n+2,3*n+1,2))
if m%2==1:
    mid[-1],A[0]=A[0],mid[-1]
for i in reversed(range(n)):
    if mid[i]%2==0:
        A[0],A[i]=A[i],A[0]
        B[0],B[i]=B[i],B[0]
        key=i
        break
ax=[]
for i in range(n):
    if i==key and m%2==1:
        ax.append(mid[i]*2)
    else:
        ax.append(mid[i])
ax.sort()
ay=sum(ax)
ay//=2
S={0}
zz=0
for i in ax:
    if zz<ay:
        zz+=i
        S.add(i)
    else:
        break
daiv=zz-ay
if daiv!=0:
  for i in range(2):
    if daiv-i in S:
        S.remove(i)
        S.remove(daiv-i)
        break

for i in range(n):
    if mid[i] in S:
        A[i],B[i]=B[i],A[i]

#print(S)      
#print(ax,ay)        
#print(mid,A,B)
a=0
b=0
for i in range(n):
    a+=mid[i]*A[i]
    b+=mid[i]*B[i]
#print(a,b)
print(*(A+mid+B))
0