結果

問題 No.844 split game
ユーザー phspls
提出日時 2022-12-01 02:36:03
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 12,447 ms
コンパイル使用メモリ 402,532 KB
実行使用メモリ 9,652 KB
最終ジャッジ日時 2024-10-07 22:47:53
合計ジャッジ時間 16,737 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 56
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> src/main.rs:22:9
   |
22 |     for i in 0..=n {
   |         ^ help: if this is intentional, prefix it with an underscore: `_i`
   |
   = note: `#[warn(unused_variables)]` on by default

ソースコード

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 areas = (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<_>>();

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