結果

問題 No.4 おもりと天秤
ユーザー YamaKasaYamaKasa
提出日時 2018-10-16 00:29:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 212 ms / 5,000 ms
コード長 409 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 16,116 KB
最終ジャッジ日時 2023-08-02 20:26:26
合計ジャッジ時間 3,276 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,376 KB
testcase_01 AC 17 ms
8,200 KB
testcase_02 AC 36 ms
9,320 KB
testcase_03 AC 30 ms
9,088 KB
testcase_04 AC 37 ms
9,432 KB
testcase_05 AC 210 ms
15,960 KB
testcase_06 AC 18 ms
8,336 KB
testcase_07 AC 212 ms
15,972 KB
testcase_08 AC 16 ms
8,220 KB
testcase_09 AC 151 ms
16,000 KB
testcase_10 AC 212 ms
16,036 KB
testcase_11 AC 25 ms
8,812 KB
testcase_12 AC 20 ms
8,372 KB
testcase_13 AC 20 ms
8,364 KB
testcase_14 AC 21 ms
8,528 KB
testcase_15 AC 21 ms
8,456 KB
testcase_16 AC 28 ms
8,916 KB
testcase_17 AC 25 ms
8,816 KB
testcase_18 AC 178 ms
16,100 KB
testcase_19 AC 204 ms
15,996 KB
testcase_20 AC 196 ms
16,072 KB
testcase_21 AC 193 ms
16,116 KB
testcase_22 AC 201 ms
16,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
W = list(map(int,input().split()))

sum = sum(W)
if sum % 2 != 0:
    print("impossible")
    exit()

dp = [[0] * 10001 for i in range(N + 1)]
dp[0][0] = 1
idx = 0

for w in W:
    for i in range(10000):
        if dp[idx][i] == 1:
            dp[idx + 1][i + w] = 1
            dp[idx + 1][i] = 1
    idx += 1

if dp[N][int(sum / 2)] == 1:
    print("possible")
else:
    print("impossible")
0