結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2020-11-12 14:46:16 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 116 ms / 5,000 ms |
コード長 | 693 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 15,360 KB |
最終ジャッジ日時 | 2024-07-22 19:10:54 |
合計ジャッジ時間 | 2,190 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
from typing import List def f(n: int, ws: List[int]) -> bool: max_w = sum(ws) if max_w % 2 != 0: return False half_w = int(max_w / 2) dp = [[False] * (half_w + 1) for _ in range(0, n + 1)] dp[0][0] = True for i in range(0, n): for w in range(0, half_w + 1): dp[i + 1][w] = ( (dp[i][w - ws[i]] or dp[i][w]) if w >= ws[i] else dp[i][w] ) return dp[n][half_w] # assert f(3, [1, 2, 3]) # assert not f(5, [1, 2, 3, 4, 5]) # assert not f(15, [62, 8, 90, 2, 24, 62, 38, 64, 76, 60, 30, 76, 80, 74, 72]) n = int(input()) ws = list(map(int, input().split(" "))) print("possible" if f(n, ws) else "impossible")