結果
問題 | No.4 おもりと天秤 |
ユーザー | cm-kojimat |
提出日時 | 2020-11-12 14:44:56 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 98 ms / 5,000 ms |
コード長 | 688 bytes |
コンパイル時間 | 80 ms |
コンパイル使用メモリ | 10,816 KB |
実行使用メモリ | 13,692 KB |
最終ジャッジ日時 | 2023-09-30 01:14:11 |
合計ジャッジ時間 | 2,444 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
9,756 KB |
testcase_01 | AC | 34 ms
9,728 KB |
testcase_02 | AC | 37 ms
9,800 KB |
testcase_03 | AC | 33 ms
9,800 KB |
testcase_04 | AC | 34 ms
9,768 KB |
testcase_05 | AC | 66 ms
11,756 KB |
testcase_06 | AC | 33 ms
9,760 KB |
testcase_07 | AC | 66 ms
11,876 KB |
testcase_08 | AC | 33 ms
9,784 KB |
testcase_09 | AC | 98 ms
13,692 KB |
testcase_10 | AC | 69 ms
12,172 KB |
testcase_11 | AC | 34 ms
9,940 KB |
testcase_12 | AC | 34 ms
9,892 KB |
testcase_13 | AC | 34 ms
9,864 KB |
testcase_14 | AC | 34 ms
9,764 KB |
testcase_15 | AC | 35 ms
9,912 KB |
testcase_16 | AC | 34 ms
9,908 KB |
testcase_17 | AC | 34 ms
9,920 KB |
testcase_18 | AC | 65 ms
11,616 KB |
testcase_19 | AC | 61 ms
11,632 KB |
testcase_20 | AC | 62 ms
11,472 KB |
testcase_21 | AC | 59 ms
11,488 KB |
testcase_22 | AC | 61 ms
11,408 KB |
ソースコード
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")