結果

問題 No.1538 引きこもりさんは引き算が得意。
ユーザー gew1fw
提出日時 2025-06-12 20:40:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 832 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 685,052 KB
最終ジャッジ日時 2025-06-12 20:41:14
合計ジャッジ時間 9,893 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 WA * 9 MLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def main():
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    
    if K in A:
        print("Yes")
        return
    
    # Compute GCD
    current_gcd = A[0]
    for num in A[1:]:
        current_gcd = math.gcd(current_gcd, abs(num))
    if current_gcd == 0:
        current_gcd = abs(A[0])
    
    if K % current_gcd != 0:
        print("No")
        return
    
    # Now, check if K can be expressed as a sum of subset with +/- signs
    target = K
    possible = {0}
    for num in A:
        temp = set()
        for p in possible:
            temp.add(p + num)
            temp.add(p - num)
        possible.update(temp)
    
    if target in possible:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()
0