結果

問題 No.4 おもりと天秤
ユーザー iga_xxiga_xx
提出日時 2015-11-21 18:06:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 409 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 10,464 KB
実行使用メモリ 8,276 KB
最終ジャッジ日時 2023-09-08 16:28:39
合計ジャッジ時間 1,688 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,112 KB
testcase_01 AC 15 ms
8,240 KB
testcase_02 AC 16 ms
7,856 KB
testcase_03 AC 15 ms
8,144 KB
testcase_04 AC 15 ms
8,184 KB
testcase_05 AC 45 ms
8,176 KB
testcase_06 AC 15 ms
7,836 KB
testcase_07 AC 44 ms
8,276 KB
testcase_08 AC 15 ms
8,220 KB
testcase_09 AC 37 ms
8,164 KB
testcase_10 AC 46 ms
8,208 KB
testcase_11 AC 15 ms
7,892 KB
testcase_12 AC 15 ms
7,972 KB
testcase_13 AC 15 ms
7,756 KB
testcase_14 AC 15 ms
7,916 KB
testcase_15 AC 15 ms
7,804 KB
testcase_16 AC 15 ms
8,112 KB
testcase_17 AC 15 ms
8,176 KB
testcase_18 AC 61 ms
7,884 KB
testcase_19 AC 40 ms
8,256 KB
testcase_20 AC 38 ms
8,128 KB
testcase_21 AC 41 ms
7,996 KB
testcase_22 AC 38 ms
8,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

N = int(input())
W = list(map(int,input().split()))
W2 = int(sum(W)/2)

if sum(W) % 2 == 1:
    print("impossible")
    sys.exit()

dp = [False] * (W2 + 1)
dp[0] = True
for i in W:
    for j in range(W2, -1, -1):
        if dp[j]:
            if j+i == W2:
                print("possible")
                sys.exit()
            elif j+i < W2:
                dp[j+i] = True

print("impossible")
0