結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2021-07-11 12:32:49 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 158 ms / 5,000 ms |
コード長 | 1,218 bytes |
コンパイル時間 | 84 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 15,360 KB |
最終ジャッジ日時 | 2024-07-02 03:02:34 |
合計ジャッジ時間 | 2,471 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#!/usr/bin/env python3 from sys import setrecursionlimit, stdin from typing import Dict, Iterable, Set INF: int = 2**62 MOD: int = 10**9 + 7 setrecursionlimit(10**6) def inputs(type_=int): ins = input().split(' ') ins = [x for x in ins if x != ''] if isinstance(type_, Iterable): return [t(x) for t, x in zip(type_, ins)] else: return list(map(type_, ins)) def input_(type_=int): a, = inputs(type_) return a inputi = input_ def inputstr(): return input_(str) # b/aの切り上げ def ceil(b, a): return (a + b - 1) // a def answer(res) -> None: print(res) exit() def compute(): return def main(): n = inputi() ws = inputs() if sum(ws) %2 == 1: print('impossible') exit() target = sum(ws) // 2 ws = [0] + ws n += 1 dp = [[False] * (target+1) for _ in range(n)] dp[0][0] = True for i in range(1, n): for j in range(target + 1): dp[i][j] = dp[i-1][j] if 0 <= j - ws[i] <= target: dp[i][j] |= dp[i - 1][j-ws[i]] if dp[-1][target]: print('possible') else: print('impossible') if __name__ == '__main__': main()