結果

問題 No.844 split game
ユーザー phsplsphspls
提出日時 2022-12-01 02:36:03
言語 Rust
(1.77.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 2,879 ms
コンパイル使用メモリ 169,088 KB
実行使用メモリ 9,648 KB
最終ジャッジ日時 2024-04-16 20:14:33
合計ジャッジ時間 5,378 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
5,248 KB
testcase_01 AC 21 ms
7,752 KB
testcase_02 AC 40 ms
6,148 KB
testcase_03 AC 32 ms
7,616 KB
testcase_04 AC 15 ms
5,376 KB
testcase_05 AC 43 ms
8,400 KB
testcase_06 AC 14 ms
5,376 KB
testcase_07 AC 15 ms
6,748 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 30 ms
5,376 KB
testcase_10 AC 45 ms
7,684 KB
testcase_11 AC 45 ms
9,184 KB
testcase_12 AC 30 ms
5,376 KB
testcase_13 AC 19 ms
5,376 KB
testcase_14 AC 21 ms
6,172 KB
testcase_15 AC 50 ms
9,516 KB
testcase_16 AC 51 ms
9,524 KB
testcase_17 AC 50 ms
9,644 KB
testcase_18 AC 49 ms
9,636 KB
testcase_19 AC 50 ms
9,648 KB
testcase_20 AC 50 ms
9,644 KB
testcase_21 AC 48 ms
9,648 KB
testcase_22 AC 50 ms
9,640 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 4 ms
5,376 KB
testcase_30 AC 4 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 5 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 5 ms
5,376 KB
testcase_36 AC 4 ms
5,376 KB
testcase_37 AC 9 ms
5,376 KB
testcase_38 AC 10 ms
5,376 KB
testcase_39 AC 21 ms
5,376 KB
testcase_40 AC 10 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 1 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 1 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 0 ms
5,376 KB
testcase_57 AC 1 ms
5,376 KB
testcase_58 AC 1 ms
5,376 KB
testcase_59 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
  --> 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

warning: 1 warning emitted

ソースコード

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