結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2021-03-11 07:28:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 86 ms / 5,000 ms |
コード長 | 662 bytes |
コンパイル時間 | 171 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 77,740 KB |
最終ジャッジ日時 | 2024-10-12 21:56:11 |
合計ジャッジ時間 | 2,470 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
from collections import Counter n = int(input()) W = list(map(int,input().split())) sm = sum(W) if sm%2: print('impossible') exit() cnt = Counter(W) keys = sorted(cnt.keys()) dp = [[0]*(sm//2+1) for _ in range(len(keys)+1)] for i in range(len(keys)+1): dp[i][0] = 1 for i in range(1,len(keys)+1): for s in range(sm//2+1): now = dp[i-1][s] k = min(s//keys[i-1],cnt[keys[i-1]]) #print(keys[i-1],k) for j in range(1,k+1): now |= dp[i-1][s-j*keys[i-1]] dp[i][s] = now for i in range(len(keys)+1): if dp[i][sm//2]: print('possible') exit() print('impossible')