結果

問題 No.4 おもりと天秤
コンテスト
ユーザー Luoto-green
提出日時 2017-07-31 19:43:05
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 107 ms / 5,000 ms
コード長 490 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 575 ms
コンパイル使用メモリ 20,704 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-03-13 02:43:40
合計ジャッジ時間 3,821 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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