結果

問題 No.4 おもりと天秤
ユーザー piconic_X
提出日時 2016-08-21 01:29:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 602 bytes
コンパイル時間 202 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-06-26 09:58:07
合計ジャッジ時間 1,618 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(N, ws, A):
    accs = set([0])
    for w in ws:
        if w > A:
            return False
        accs_ = set(accs)
        for a in accs:
            na = w + a
            if na == A:
                return True
            elif na < A:
                accs_.add(na)
        accs = accs_
    return False

def main():
    N = int(input())
    ws = list(map(int, input().split()))
    Sum = sum(ws)
    if Sum % 2 == 0:
        A = Sum // 2
        if solve(N, ws, A):
            print('possible')
        else:
            print('impossible')
    else:
        print('impossible')

main()
0