結果

問題 No.472 平均順位
ユーザー fukafukatanifukafukatani
提出日時 2018-11-02 23:28:17
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 1,457 bytes
コンパイル時間 15,635 ms
コンパイル使用メモリ 399,732 KB
実行使用メモリ 295,168 KB
最終ジャッジ日時 2024-04-30 18:01:13
合計ジャッジ時間 14,873 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 0 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 16 ms
9,728 KB
testcase_10 AC 12 ms
6,944 KB
testcase_11 AC 54 ms
26,752 KB
testcase_12 AC 38 ms
19,328 KB
testcase_13 AC 157 ms
67,200 KB
testcase_14 AC 452 ms
242,688 KB
testcase_15 AC 159 ms
67,200 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 32 ms
18,944 KB
testcase_19 AC 77 ms
33,024 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