結果

問題 No.844 split game
ユーザー phsplsphspls
提出日時 2022-12-14 11:24:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,210 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 176,744 KB
実行使用メモリ 9,652 KB
最終ジャッジ日時 2024-04-25 15:46:39
合計ジャッジ時間 3,685 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
6,812 KB
testcase_01 AC 19 ms
7,620 KB
testcase_02 AC 39 ms
6,944 KB
testcase_03 AC 31 ms
7,676 KB
testcase_04 AC 15 ms
6,940 KB
testcase_05 AC 43 ms
8,144 KB
testcase_06 AC 14 ms
6,944 KB
testcase_07 AC 14 ms
6,940 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 29 ms
6,944 KB
testcase_10 AC 42 ms
7,688 KB
testcase_11 AC 42 ms
9,304 KB
testcase_12 AC 27 ms
6,944 KB
testcase_13 AC 18 ms
6,940 KB
testcase_14 AC 20 ms
6,940 KB
testcase_15 AC 44 ms
9,644 KB
testcase_16 AC 44 ms
9,620 KB
testcase_17 AC 45 ms
9,648 KB
testcase_18 AC 46 ms
9,652 KB
testcase_19 AC 46 ms
9,652 KB
testcase_20 AC 46 ms
9,652 KB
testcase_21 AC 45 ms
9,652 KB
testcase_22 AC 46 ms
9,644 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 4 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 3 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 4 ms
6,944 KB
testcase_30 AC 4 ms
6,940 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 4 ms
6,940 KB
testcase_34 AC 3 ms
6,940 KB
testcase_35 AC 5 ms
6,940 KB
testcase_36 AC 3 ms
6,944 KB
testcase_37 AC 8 ms
6,944 KB
testcase_38 AC 9 ms
6,940 KB
testcase_39 AC 19 ms
6,944 KB
testcase_40 AC 9 ms
6,940 KB
testcase_41 AC 1 ms
6,940 KB
testcase_42 AC 1 ms
6,940 KB
testcase_43 AC 1 ms
6,944 KB
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 1 ms
6,944 KB
testcase_46 AC 0 ms
6,940 KB
testcase_47 AC 1 ms
6,944 KB
testcase_48 AC 1 ms
6,944 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 0 ms
6,940 KB
testcase_51 AC 1 ms
6,940 KB
testcase_52 AC 1 ms
6,940 KB
testcase_53 AC 1 ms
6,940 KB
testcase_54 AC 1 ms
6,944 KB
testcase_55 AC 1 ms
6,944 KB
testcase_56 AC 1 ms
6,944 KB
testcase_57 AC 1 ms
6,940 KB
testcase_58 AC 1 ms
6,944 KB
testcase_59 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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