結果

問題 No.4 おもりと天秤
ユーザー mationaruzoumationaruzou
提出日時 2020-06-19 13:31:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 257 ms / 5,000 ms
コード長 494 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 10,968 KB
実行使用メモリ 16,036 KB
最終ジャッジ日時 2023-09-16 12:44:56
合計ジャッジ時間 2,791 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,112 KB
testcase_01 AC 16 ms
8,240 KB
testcase_02 AC 18 ms
8,276 KB
testcase_03 AC 17 ms
8,192 KB
testcase_04 AC 19 ms
8,224 KB
testcase_05 AC 164 ms
12,404 KB
testcase_06 AC 16 ms
7,780 KB
testcase_07 AC 174 ms
12,388 KB
testcase_08 AC 15 ms
8,192 KB
testcase_09 AC 257 ms
16,036 KB
testcase_10 AC 180 ms
12,856 KB
testcase_11 AC 17 ms
7,964 KB
testcase_12 AC 16 ms
7,752 KB
testcase_13 AC 15 ms
7,776 KB
testcase_14 AC 15 ms
7,844 KB
testcase_15 AC 15 ms
7,868 KB
testcase_16 AC 16 ms
8,048 KB
testcase_17 AC 16 ms
8,240 KB
testcase_18 AC 145 ms
12,136 KB
testcase_19 AC 146 ms
11,928 KB
testcase_20 AC 149 ms
11,968 KB
testcase_21 AC 137 ms
11,592 KB
testcase_22 AC 144 ms
11,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

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

s = sum(W)
if s % 2 == 1:
    print("impossible")
    exit()
ss = s//2
dp = [[False]*(s+1) for _ in range(n)]
for i in range(n):
    dp[i][0] = True
dp[0][W[0]] = True
for i in range(n-1):
    for j in range(ss+1):
        if j >= W[i+1]:
            dp[i+1][j] = dp[i][j-W[i+1]]
        if dp[i][j]:
            dp[i+1][j] = True

for i in range(n):
    if dp[i][ss]:
        print("possible")
        exit()
print("impossible")
0