結果

問題 No.1017 Reiwa Sequence
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-29 19:28:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 1,067 bytes
コンパイル時間 933 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 150,912 KB
最終ジャッジ日時 2023-09-08 04:37:10
合計ジャッジ時間 21,571 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,120 KB
testcase_01 AC 75 ms
71,212 KB
testcase_02 AC 73 ms
71,216 KB
testcase_03 AC 78 ms
75,876 KB
testcase_04 AC 73 ms
71,148 KB
testcase_05 AC 74 ms
71,080 KB
testcase_06 AC 75 ms
71,380 KB
testcase_07 AC 74 ms
71,212 KB
testcase_08 AC 73 ms
71,236 KB
testcase_09 AC 79 ms
76,256 KB
testcase_10 AC 80 ms
76,624 KB
testcase_11 AC 78 ms
76,444 KB
testcase_12 AC 79 ms
76,680 KB
testcase_13 AC 79 ms
76,252 KB
testcase_14 AC 79 ms
76,624 KB
testcase_15 AC 81 ms
76,468 KB
testcase_16 AC 81 ms
76,488 KB
testcase_17 AC 84 ms
77,788 KB
testcase_18 AC 81 ms
76,488 KB
testcase_19 AC 271 ms
140,512 KB
testcase_20 AC 268 ms
140,544 KB
testcase_21 AC 263 ms
140,484 KB
testcase_22 AC 267 ms
140,500 KB
testcase_23 AC 263 ms
140,632 KB
testcase_24 AC 272 ms
140,484 KB
testcase_25 AC 277 ms
140,516 KB
testcase_26 AC 266 ms
140,676 KB
testcase_27 AC 204 ms
113,996 KB
testcase_28 AC 225 ms
124,652 KB
testcase_29 AC 83 ms
77,340 KB
testcase_30 AC 87 ms
79,088 KB
testcase_31 AC 102 ms
86,580 KB
testcase_32 AC 175 ms
107,752 KB
testcase_33 AC 84 ms
76,716 KB
testcase_34 AC 181 ms
107,772 KB
testcase_35 AC 73 ms
70,928 KB
testcase_36 AC 76 ms
75,788 KB
testcase_37 AC 177 ms
107,800 KB
testcase_38 AC 72 ms
71,396 KB
testcase_39 AC 175 ms
107,640 KB
testcase_40 AC 306 ms
150,608 KB
testcase_41 AC 310 ms
150,884 KB
testcase_42 AC 306 ms
150,788 KB
testcase_43 AC 301 ms
150,648 KB
testcase_44 AC 112 ms
94,856 KB
testcase_45 AC 304 ms
150,640 KB
testcase_46 AC 305 ms
150,912 KB
testcase_47 AC 298 ms
150,672 KB
testcase_48 AC 135 ms
107,672 KB
testcase_49 AC 129 ms
107,228 KB
testcase_50 AC 130 ms
107,704 KB
testcase_51 AC 74 ms
71,380 KB
testcase_52 AC 267 ms
140,484 KB
testcase_53 AC 126 ms
97,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a=list(map(int,input().split()))
"""
1<=n<=150000
1<=ai<=150000
n<=sum(a)<=1.5^2*10^10
とりうる部分和は2^n-1
2^n-1<sum(a)なら鳩の巣原理より
ある数値kがあり部分和がkとなるaの部分列の取り方が複数ある。
nが十分大ならYes
->22以上ならOKなのでaを小さく取って全探索
"""
if n==1:
  print('No')
elif n==2:
  if a[0]==a[1]:
    print('Yes')
    print(a[0],-a[1])
  else:
    print('No')
else:
  b=[a[0],a[1]]
  sumb=a[0]+a[1]
  for x in a[2:]:
    if sumb<pow(2,len(b))-1:break
    b.append(x)
    sumb+=x
  d={}
  m=len(b)
  for i in range(1<<m):
    key=0
    for j in range(m):
      if (i>>j)&1:
        key+=a[j]
    if key in d:
      sub0=d[key]
      sub1=i
      u=sub0&sub1
      sub0-=u
      sub1-=u
      ans=[]
      for j in range(m):
        if (sub0>>j)&1:
          ans.append(a[j])
        elif (sub1>>j)&1:
          ans.append(-a[j])
        else:
          ans.append(0)
      ans+=[0]*(n-m)
      print('Yes')
      print(*ans)
      exit()
    d[key]=i
  print('No')



0