結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー AEnAEn
提出日時 2022-11-20 17:09:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 84,876 KB
最終ジャッジ日時 2023-10-21 15:00:15
合計ジャッジ時間 5,384 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,440 KB
testcase_01 AC 38 ms
53,440 KB
testcase_02 AC 38 ms
53,440 KB
testcase_03 AC 42 ms
53,440 KB
testcase_04 AC 37 ms
53,440 KB
testcase_05 AC 38 ms
53,440 KB
testcase_06 AC 38 ms
53,440 KB
testcase_07 AC 37 ms
53,440 KB
testcase_08 AC 38 ms
53,440 KB
testcase_09 AC 40 ms
53,440 KB
testcase_10 AC 39 ms
53,440 KB
testcase_11 AC 39 ms
53,440 KB
testcase_12 AC 38 ms
53,440 KB
testcase_13 AC 38 ms
53,440 KB
testcase_14 AC 44 ms
59,780 KB
testcase_15 AC 38 ms
53,440 KB
testcase_16 AC 38 ms
53,440 KB
testcase_17 AC 38 ms
53,440 KB
testcase_18 AC 38 ms
53,440 KB
testcase_19 AC 39 ms
53,440 KB
testcase_20 AC 39 ms
53,440 KB
testcase_21 AC 41 ms
53,440 KB
testcase_22 AC 39 ms
53,440 KB
testcase_23 AC 39 ms
53,440 KB
testcase_24 AC 39 ms
53,440 KB
testcase_25 AC 39 ms
53,440 KB
testcase_26 AC 38 ms
53,440 KB
testcase_27 AC 38 ms
53,440 KB
testcase_28 AC 41 ms
53,440 KB
testcase_29 AC 38 ms
53,440 KB
testcase_30 AC 39 ms
53,440 KB
testcase_31 AC 39 ms
53,440 KB
testcase_32 AC 38 ms
53,440 KB
testcase_33 AC 38 ms
53,440 KB
testcase_34 AC 39 ms
53,440 KB
testcase_35 AC 39 ms
53,440 KB
testcase_36 AC 38 ms
53,440 KB
testcase_37 AC 85 ms
75,596 KB
testcase_38 AC 86 ms
75,600 KB
testcase_39 AC 88 ms
75,588 KB
testcase_40 AC 82 ms
75,476 KB
testcase_41 AC 83 ms
75,476 KB
testcase_42 AC 87 ms
75,596 KB
testcase_43 AC 38 ms
53,440 KB
testcase_44 AC 41 ms
53,440 KB
testcase_45 AC 87 ms
75,612 KB
testcase_46 AC 83 ms
75,384 KB
testcase_47 AC 75 ms
77,676 KB
testcase_48 AC 110 ms
84,876 KB
testcase_49 AC 83 ms
75,456 KB
testcase_50 AC 38 ms
53,440 KB
testcase_51 AC 111 ms
84,872 KB
testcase_52 AC 108 ms
84,872 KB
testcase_53 AC 102 ms
84,872 KB
testcase_54 AC 108 ms
84,872 KB
testcase_55 AC 106 ms
84,872 KB
testcase_56 AC 109 ms
84,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
A = list(map(int, input().split()))
if K in A:
    exit(print('Yes'))

p, q = A[:N//2],A[N//2:]
P = [set() for _ in range(3)]
Q = [set() for _ in range(3)]

def cal(p, P):
    for i in range(1,1<<len(p)):
        s = []
        for j in range(len(p)):
            if i&(1<<j):
                s.append(p[j])
        for j in range(1<<len(s)):
            sm = 0
            cp, cn = 0,0
            for k in range(len(s)):
                if j&(1<<k):
                    cp += 1
                    sm += s[k]
                else:
                    cn += 1
                    sm -= s[k]
            if cp>=1 and cn>=1:
                if sm==K:
                    exit(print('Yes'))
                P[0].add(sm)
            elif cp>=1:
                P[1].add(sm)
            else:
                P[2].add(sm)

cal(p,P)
cal(q,Q)
for n1 in P[0]:
    for i in range(3):
        if K-n1 in Q[i]:
            exit(print('Yes'))
for n1 in P[1]:
    if (K-n1 in Q[0]) or (K-n1 in Q[2]):
        exit(print('Yes'))
for n1 in P[2]:
    if (K-n1 in Q[0]) or (K-n1 in Q[1]):
        exit(print('Yes'))
print('No')
0