結果

問題 No.4 おもりと天秤
ユーザー Luoto-green
提出日時 2017-07-31 19:43:05
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 490 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-06-26 10:21:53
合計ジャッジ時間 1,958 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = [int(i)for i in input().split()]
def solve(n,A):
    s = sum(A)
    B = set([0])
    h = s//2
    if s&1:
        return False
    else:
        for i in A:
            nB = set(B)
            for j in B:
                ij = i + j
                if ij == h:
                    return True
                if ij < h:
                    nB.add(ij)
            B = nB
        return False
if solve(n,A):
    print("possible")
else:
    print("impossible")
            
0