結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー とりゐとりゐ
提出日時 2021-05-20 17:51:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 792 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 403 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 167,744 KB
最終ジャッジ日時 2023-08-20 22:30:53
合計ジャッジ時間 16,485 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,236 KB
testcase_01 AC 73 ms
71,172 KB
testcase_02 AC 72 ms
71,264 KB
testcase_03 AC 73 ms
71,204 KB
testcase_04 AC 74 ms
71,232 KB
testcase_05 AC 76 ms
71,276 KB
testcase_06 AC 76 ms
71,060 KB
testcase_07 AC 75 ms
71,276 KB
testcase_08 AC 74 ms
70,972 KB
testcase_09 AC 73 ms
71,192 KB
testcase_10 AC 73 ms
71,296 KB
testcase_11 AC 72 ms
71,192 KB
testcase_12 AC 70 ms
71,384 KB
testcase_13 AC 74 ms
71,296 KB
testcase_14 AC 81 ms
76,324 KB
testcase_15 AC 73 ms
71,052 KB
testcase_16 AC 74 ms
71,200 KB
testcase_17 AC 73 ms
71,332 KB
testcase_18 AC 74 ms
71,296 KB
testcase_19 AC 73 ms
71,172 KB
testcase_20 AC 73 ms
71,472 KB
testcase_21 AC 75 ms
71,576 KB
testcase_22 AC 74 ms
71,064 KB
testcase_23 AC 73 ms
71,364 KB
testcase_24 AC 75 ms
71,276 KB
testcase_25 AC 74 ms
71,188 KB
testcase_26 AC 74 ms
71,204 KB
testcase_27 AC 74 ms
71,392 KB
testcase_28 AC 74 ms
71,276 KB
testcase_29 AC 74 ms
71,052 KB
testcase_30 AC 74 ms
71,248 KB
testcase_31 AC 74 ms
71,056 KB
testcase_32 AC 73 ms
71,492 KB
testcase_33 AC 74 ms
71,248 KB
testcase_34 AC 74 ms
71,184 KB
testcase_35 AC 75 ms
71,248 KB
testcase_36 AC 73 ms
71,200 KB
testcase_37 AC 583 ms
167,616 KB
testcase_38 AC 792 ms
167,296 KB
testcase_39 AC 703 ms
167,492 KB
testcase_40 AC 497 ms
159,564 KB
testcase_41 AC 505 ms
159,592 KB
testcase_42 AC 562 ms
167,496 KB
testcase_43 AC 78 ms
71,212 KB
testcase_44 AC 530 ms
126,888 KB
testcase_45 AC 589 ms
152,108 KB
testcase_46 AC 364 ms
76,932 KB
testcase_47 AC 195 ms
115,728 KB
testcase_48 AC 790 ms
167,388 KB
testcase_49 AC 535 ms
119,632 KB
testcase_50 AC 73 ms
71,252 KB
testcase_51 AC 750 ms
167,744 KB
testcase_52 AC 767 ms
167,504 KB
testcase_53 AC 747 ms
167,440 KB
testcase_54 AC 770 ms
167,468 KB
testcase_55 AC 756 ms
167,704 KB
testcase_56 AC 757 ms
167,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#おそらく正しい解法
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k in a:
  print('Yes')
  exit()
d={}
cnt=0
if k==0:
  cnt+=2**n
for i in range(2**n):
  tmp=0
  for j in range(n):
    if (i>>j)&1:
      tmp+=a[j]
  if tmp==k:
    cnt-=2**(n-bin(i).count('1'))
  if tmp==-k:
    cnt-=2**(n-bin(i).count('1'))
  if tmp in d:
    d[tmp]+=1
  else:
    d[tmp]=1
for i in d.keys():
  if i+k in d.keys():
    cnt+=d[i]*d[i+k]
if cnt>0:
  print('Yes')
else:
  print('No')
0