結果

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

ソースコード

diff #

def solve(n, w_list):
    total = sum(w_list)
    if total % 2 != 0:
        return "impossible"
    half = total // 2
    dp = [0 for i in range(half + 1)]
    dp[0] = 1
    for w in sorted(w_list):
        for i in range(len(dp) - 1, -1, -1):
            if dp[i] and i + w < len(dp):
                dp[i + w] = 1

    return "possible" if dp[half] != 0 else "impossible"


def main():
    n = int(input())
    w_list = list(map(int, input().split()))
    print(solve(n, w_list))


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