結果

問題 No.4 おもりと天秤
ユーザー HIROPON87069639HIROPON87069639
提出日時 2016-03-09 21:55:36
言語 Python2
(2.7.18)
結果
AC  
実行時間 52 ms / 5,000 ms
コード長 393 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 6,620 KB
実行使用メモリ 6,196 KB
最終ジャッジ日時 2023-09-08 16:36:22
合計ジャッジ時間 1,903 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,120 KB
testcase_01 AC 12 ms
5,924 KB
testcase_02 AC 12 ms
6,132 KB
testcase_03 AC 12 ms
6,120 KB
testcase_04 AC 13 ms
5,940 KB
testcase_05 AC 47 ms
6,096 KB
testcase_06 AC 11 ms
5,984 KB
testcase_07 AC 47 ms
6,172 KB
testcase_08 AC 11 ms
5,988 KB
testcase_09 AC 51 ms
6,168 KB
testcase_10 AC 52 ms
6,160 KB
testcase_11 AC 12 ms
6,060 KB
testcase_12 AC 11 ms
6,076 KB
testcase_13 AC 11 ms
6,120 KB
testcase_14 AC 11 ms
6,056 KB
testcase_15 AC 12 ms
6,084 KB
testcase_16 AC 11 ms
5,984 KB
testcase_17 AC 12 ms
6,132 KB
testcase_18 AC 39 ms
6,100 KB
testcase_19 AC 43 ms
6,052 KB
testcase_20 AC 43 ms
6,184 KB
testcase_21 AC 41 ms
6,172 KB
testcase_22 AC 42 ms
6,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
#input
N = input()
W = map(int, raw_input().split())
if sum(W) % 2 == 1:
    print "impossible"
    exit()
sumhalf = sum(W) / 2

# dynamic programming
DP = [0] * (sumhalf + 100)
DP[0] = 1
for w in W:
    for i in reversed(range(sumhalf)):
        if DP[i] == 1:
            DP[i + w] = 1

# output
if DP[sumhalf] == 1:
    print "possible"
else:
    print "impossible"
0