結果

問題 No.1017 Reiwa Sequence
ユーザー titiatitia
提出日時 2020-04-03 23:19:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,717 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 135,704 KB
最終ジャッジ日時 2023-09-16 04:50:09
合計ジャッジ時間 23,747 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,656 KB
testcase_01 AC 93 ms
71,564 KB
testcase_02 AC 92 ms
71,632 KB
testcase_03 AC 103 ms
77,516 KB
testcase_04 AC 94 ms
71,812 KB
testcase_05 AC 95 ms
71,464 KB
testcase_06 AC 94 ms
71,500 KB
testcase_07 AC 97 ms
71,756 KB
testcase_08 AC 107 ms
71,544 KB
testcase_09 AC 132 ms
77,748 KB
testcase_10 AC 113 ms
77,716 KB
testcase_11 AC 116 ms
77,908 KB
testcase_12 AC 132 ms
77,464 KB
testcase_13 AC 123 ms
77,616 KB
testcase_14 AC 149 ms
77,672 KB
testcase_15 AC 248 ms
77,696 KB
testcase_16 AC 144 ms
77,600 KB
testcase_17 AC 257 ms
77,704 KB
testcase_18 AC 149 ms
77,472 KB
testcase_19 AC 255 ms
77,676 KB
testcase_20 AC 255 ms
77,652 KB
testcase_21 AC 254 ms
77,712 KB
testcase_22 AC 253 ms
77,444 KB
testcase_23 AC 253 ms
77,608 KB
testcase_24 AC 252 ms
77,684 KB
testcase_25 AC 258 ms
77,624 KB
testcase_26 AC 255 ms
77,620 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 134 ms
77,684 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 155 ms
77,644 KB
testcase_39 WA -
testcase_40 AC 290 ms
112,980 KB
testcase_41 AC 291 ms
112,896 KB
testcase_42 AC 285 ms
109,732 KB
testcase_43 AC 319 ms
109,816 KB
testcase_44 AC 338 ms
112,976 KB
testcase_45 AC 335 ms
112,960 KB
testcase_46 AC 328 ms
110,064 KB
testcase_47 AC 334 ms
109,596 KB
testcase_48 WA -
testcase_49 AC 246 ms
135,704 KB
testcase_50 WA -
testcase_51 AC 95 ms
71,392 KB
testcase_52 WA -
testcase_53 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
A=[abs(a) for a in A]

from collections import Counter
C=Counter(A)

x=0
for c in C:
    if C[c]>1:
        x=c
        break

if x!=0:
    flag=0

    ANS=[]
    for a in A:
        if a!=x or flag==2:
            ANS.append(a)
        else:
            if flag==0:
                ANS.append(x)
                flag+=1
            elif flag==1:
                ANS.append(-x)
                flag+=1
                
    print("Yes")
    print(*ANS)
    sys.exit()

import heapq
B=[(-A[i],i) for i in range(N)]
S=set(A)
ANS=[0]*N
heapq.heapify(B)
while len(B)>=2:
    x,ind1=heapq.heappop(B)
    y,ind2=heapq.heappop(B)

    x=-x
    y=-y

    ANS[ind1]=x
    ANS[ind2]=-y

    S.remove(x)
    S.remove(y)

    if C[x-y] in S:
        fin=x-y

        for i in range(N):
            if A[i]==fin:
                ANS[i]=-fin

            print("Yes")
            print(*ANS)
            sys.exit()

    S.add(x-y)


M=min(12,N)
from itertools import product
ITER=product([-1,0,1],repeat=M)
SET=set(A[M:])

for ite in ITER:
    if max(ite)==min(ite)==0:
        continue
    S=0
    for i in range(M):
        S+=A[i]*ite[i]

    if S==0:
        ANS=[]
        for i in range(M):
            ANS.append(ite[i]*A[i])
        ANS+=[0]*abs(N-M)
        print("Yes")
        print(*ANS)
        break
    
    if S in SET:
        ANS=[]
        for i in range(M):
            ANS.append(ite[i]*A[i])
        ANS+=[0]*abs(N-M)

        for i in range(N):
            if A[i]==S:
                ANS[i]=-S
                break
        print("Yes")
        print(*ANS)
        break
                     
else:
    print("No")
    

0