結果

問題 No.2982 Logic Battle
コンテスト
ユーザー Yukino DX.
提出日時 2024-12-28 13:11:16
言語 Rust
(1.99.0 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1,098 ms / 2,000 ms
+ 88µs
コード長 1,253 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,748 ms
コンパイル使用メモリ 190,072 KB
実行使用メモリ 9,924 KB
最終ジャッジ日時 2026-10-22 05:33:00
合計ジャッジ時間 29,342 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: use of deprecated constant `std::i64::MAX`: replaced by the `MAX` associated constant on this type
 --> src/main.rs:9:32
  |
9 |     const INF: i64 = std::i64::MAX;
  |                                ^^^
  |
  = note: `#[warn(deprecated)]` on by default

ソースコード

diff #
raw source code

use proconio::input;

fn main() {
    input! {
        n:usize,
        a:[[usize;3];n],
    }
    const M: usize = 5000;
    const INF: i64 = std::i64::MAX;

    let mut dp = vec![vec![0; 3]; M + 1];
    for i in 1..=M {
        for j in 0..3 {
            dp[i][j] = -INF;
        }
    }
    for i in 0..n {
        let mut ndp = vec![vec![-INF; 3]; M + 1];
        for j in 0..=M {
            for k in 0..3 {
                if dp[j][k] == -INF {
                    continue;
                }
                for l in 0..3 {
                    if k == l {
                        continue;
                    }

                    let atk = j + a[i][l] as usize;
                    if M < atk {
                        let over = (atk - M) * (n - i);
                        ndp[M - 1][l] = ndp[M - 1][l].max(dp[j][k] + M as i64 + over as i64);
                    } else {
                        let nj = atk.saturating_sub(1);
                        ndp[nj][l] = ndp[nj][l].max(dp[j][k] + atk as i64);
                    }
                }
            }
        }
        dp = ndp;
    }

    let mut ans = 0;
    for i in 0..=M {
        for j in 0..3 {
            ans = ans.max(dp[i][j]);
        }
    }

    println!("{}", ans);
}
0