結果
| 問題 |
No.324 落ちてた閉路グラフ
|
| コンテスト | |
| ユーザー |
maspy
|
| 提出日時 | 2020-03-04 13:43:36 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 656 ms / 5,000 ms |
| コード長 | 1,116 bytes |
| コンパイル時間 | 156 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 44,392 KB |
| 最終ジャッジ日時 | 2024-10-14 00:12:14 |
| 合計ジャッジ時間 | 24,517 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 34 |
ソースコード
#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# %%
import numpy as np
INF = 10 ** 9
# %%
N, M, *W = map(int, read().split())
# %%
dp00 = np.full(N + 2, -INF, np.int64)
dp01 = np.full(N + 2, -INF, np.int64)
dp10 = np.full(N + 2, -INF, np.int64)
dp11 = np.full(N + 2, -INF, np.int64)
dp00[0] = 0
dp11[1] = 0
for x in W:
newdp00 = np.full_like(dp00, -INF)
newdp01 = np.full_like(dp00, -INF)
newdp10 = np.full_like(dp00, -INF)
newdp11 = np.full_like(dp00, -INF)
np.maximum(newdp00, dp00, out=newdp00)
np.maximum(newdp00, dp01, out=newdp00)
np.maximum(newdp01[1:], dp00[:-1], out=newdp01[1:])
np.maximum(newdp01[1:], dp01[:-1] + x, out=newdp01[1:])
np.maximum(newdp10, dp10, out=newdp10)
np.maximum(newdp10, dp11, out=newdp10)
np.maximum(newdp11[1:], dp10[:-1], out=newdp11[1:])
np.maximum(newdp11[1:], dp11[:-1] + x, out=newdp11[1:])
dp00 = newdp00
dp01 = newdp01
dp10 = newdp10
dp11 = newdp11
# %%
answer = max(dp00[M], dp11[M + 1])
print(answer)
maspy