結果

問題 No.4 おもりと天秤
ユーザー mationaruzoumationaruzou
提出日時 2020-06-19 13:27:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 502 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 16,032 KB
最終ジャッジ日時 2023-09-16 12:44:50
合計ジャッジ時間 2,779 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,120 KB
testcase_01 AC 17 ms
8,108 KB
testcase_02 AC 19 ms
8,212 KB
testcase_03 AC 16 ms
8,140 KB
testcase_04 AC 20 ms
8,164 KB
testcase_05 AC 165 ms
12,340 KB
testcase_06 AC 17 ms
7,824 KB
testcase_07 AC 163 ms
12,520 KB
testcase_08 AC 15 ms
8,120 KB
testcase_09 AC 279 ms
16,032 KB
testcase_10 AC 187 ms
12,940 KB
testcase_11 AC 17 ms
7,984 KB
testcase_12 AC 16 ms
7,868 KB
testcase_13 AC 16 ms
7,800 KB
testcase_14 AC 16 ms
7,784 KB
testcase_15 AC 15 ms
7,872 KB
testcase_16 WA -
testcase_17 AC 15 ms
8,240 KB
testcase_18 AC 147 ms
12,140 KB
testcase_19 AC 148 ms
11,904 KB
testcase_20 AC 153 ms
11,824 KB
testcase_21 AC 137 ms
11,636 KB
testcase_22 AC 140 ms
11,876 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