結果

問題 No.844 split game
ユーザー phspls
提出日時 2022-12-14 11:24:31
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,210 bytes
コンパイル時間 14,229 ms
コンパイル使用メモリ 379,304 KB
実行使用メモリ 9,776 KB
最終ジャッジ日時 2024-11-08 02:53:43
合計ジャッジ時間 16,804 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: isize = 1isize << 60;

fn main() {
    let mut nma = String::new();
    std::io::stdin().read_line(&mut nma).ok();
    let nma: Vec<usize> = nma.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nma[0];
    let m = nma[1];
    let a = nma[2] as isize;
    let mut lines = (0..m).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            (temp[0]-1, temp[1], temp[2] as isize)
        })
        .collect::<Vec<_>>();

    lines.sort();
    let mut dp = vec![vec![-INF; 2]; n+1];
    for i in 0..=n { dp[i][0] = 0; }
    dp[0][1] = 0;
    let mut lidx = 0usize;
    for &(l, r, p) in lines.iter() {
        while lidx < l {
            lidx += 1;
            dp[lidx][0] = dp[lidx][0].max(dp[lidx-1][0]).max(dp[lidx-1][1]);
        }
        let lcost = if l == 0 { 0 } else { a };
        let rcost = if r == n { 0 } else { a };
        dp[r][1] = dp[r][1].max(dp[l][0] + p - lcost - rcost).max(dp[l][1] + p - rcost);
    }
    println!("{}", dp.iter().map(|v| v.iter().max().unwrap()).max().unwrap());
}
0