結果
問題 | No.324 落ちてた閉路グラフ |
ユーザー |
|
提出日時 | 2020-10-19 08:52:57 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
RE
|
実行時間 | - |
コード長 | 856 bytes |
コンパイル時間 | 123 ms |
コンパイル使用メモリ | 12,416 KB |
実行使用メモリ | 44,612 KB |
最終ジャッジ日時 | 2024-07-21 07:47:47 |
合計ジャッジ時間 | 21,289 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 RE * 5 |
ソースコード
import numpy as np N, M = map(int, input().split()) W = tuple(map(int, input().split())) MAX = 1_000_000 def dp(last, non_last): for w in W[:-1]: new_last = np.full(M + 1, -MAX) new_last[1:] = np.maximum(last[:-1] + w, non_last[:-1]) new_non_last = np.maximum(last, non_last) last, non_last = new_last, new_non_last return last, non_last # dp[i] = iコの点を打ち終えている # 一番目の点を含む dp_last = np.full(M + 1, -MAX) dp_non_last = np.full(M + 1, -MAX) dp_last[1] = 0 dp_last, dp_non_last = dp(dp_last, dp_non_last) ans = max(dp_last[-1] + W[-1], dp_non_last[-1]) # 一番目の点を含まない dp_last = np.full(M + 1, -MAX) dp_non_last = np.full(M + 1, -MAX) dp_non_last[0] = 0 dp_last, dp_non_last = dp(dp_last, dp_non_last) ans = max(ans, dp_last[-1], dp_non_last[-1]) print(ans)