結果

問題 No.472 平均順位
ユーザー fukafukatanifukafukatani
提出日時 2018-11-02 23:28:17
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 1,457 bytes
コンパイル時間 5,817 ms
コンパイル使用メモリ 142,312 KB
実行使用メモリ 295,224 KB
最終ジャッジ日時 2023-08-12 23:01:44
合計ジャッジ時間 7,035 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 19 ms
9,796 KB
testcase_10 AC 14 ms
6,684 KB
testcase_11 AC 59 ms
26,748 KB
testcase_12 AC 45 ms
19,276 KB
testcase_13 AC 178 ms
67,132 KB
testcase_14 AC 513 ms
242,704 KB
testcase_15 AC 175 ms
67,144 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 36 ms
19,088 KB
testcase_19 AC 89 ms
33,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v:Vec<usize> = read_vec();
    let (n, p) = (v[0], v[1]);
    let mut a = vec![0i32; n];
    let mut b = vec![0i32; n];
    let mut c = vec![0i32; n];

    for i in 0..n {
        let v:Vec<i32> = read_vec();
        a[i] = v[0];
        b[i] = v[1];
        c[i] = v[2];
    }

    let mut dp = vec![vec![std::i32::MAX; p + 1]; n + 1];
    dp[0][0] = 0;

    for ni in 0..n {
        for pi in 0..p + 1{
            if dp[ni][pi] == std::i32::MAX {
                continue;
            }
            if pi + 0 <= p {
                dp[ni + 1][pi + 0] = std::cmp::min(dp[ni + 1][pi + 0], dp[ni][pi] + a[ni]);
            }
            if pi + 1 <= p {
                dp[ni + 1][pi + 1] = std::cmp::min(dp[ni + 1][pi + 1], dp[ni][pi] + b[ni]);
            }
            if pi + 2 <= p {
                dp[ni + 1][pi + 2] = std::cmp::min(dp[ni + 1][pi + 2], dp[ni][pi] + c[ni]);
            }
            if pi + 3 <= p {
                dp[ni + 1][pi + 3] = std::cmp::min(dp[ni + 1][pi + 3], dp[ni][pi] + 1);
            }
        }
    }
    // println!("{:?}", dp);
    println!("{:?}", dp[n][p] as f32 / n as f32);
}
0