結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-14 21:09:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 5,000 ms |
| コード長 | 514 bytes |
| コンパイル時間 | 340 ms |
| コンパイル使用メモリ | 82,988 KB |
| 実行使用メモリ | 59,976 KB |
| 最終ジャッジ日時 | 2024-06-23 03:13:23 |
| 合計ジャッジ時間 | 1,990 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
def balance(weights: list) -> str:
total_weight = sum(weights)
if total_weight % 2 != 0:
return "impossible"
half_weight = total_weight // 2
possible = [False] * (half_weight + 1)
possible[0] = True
for weight in weights:
for i in range(half_weight, weight - 1, -1):
if possible[i - weight]:
possible[i] = True
return "possible" if possible[half_weight] else "impossible"
N = int(input())
W = list(map(int, input().split()))
print(balance(W))