結果

問題 No.555 世界史のレポート
ユーザー fukafukatanifukafukatani
提出日時 2018-12-05 23:50:57
言語 Rust
(1.77.0)
結果
MLE  
実行時間 -
コード長 1,076 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 146,488 KB
実行使用メモリ 812,948 KB
最終ジャッジ日時 2023-09-29 13:28:09
合計ジャッジ時間 3,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,740 KB
testcase_06 AC 4 ms
5,624 KB
testcase_07 AC 6 ms
6,948 KB
testcase_08 AC 5 ms
8,260 KB
testcase_09 AC 6 ms
9,832 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `std::collections::*`
 --> Main.rs:1:5
  |
1 | use std::collections::*;
  |     ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: 1 warning emitted

ソースコード

diff #

use std::collections::*;

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 n: usize = read();
    let v: Vec<u64> = read_vec();
    let (c, v) = (v[0], v[1]);
    let mut dp: Vec<Vec<u64>> = vec![vec![std::u64::MAX; n + 1]; n + 1];
    dp[1][1] = c;
    for i in 1..n + 1 {
        for j in 1..n + 1 {
            if dp[i][j] == std::u64::MAX {
                continue;
            }
            let index = std::cmp::min(i + j, n);
            if dp[index][j] > dp[i][j] + v {
                dp[index][j] = dp[i][j] + v;
                dp[index][index] = std::cmp::min(dp[index][j] + c, dp[index][index]);
            }
        }
    }

    let mut ans = std::u64::MAX;
    // println!("{:?}", dp[n]);
    for j in 1..n + 1 {
        ans = std::cmp::min(ans, dp[n][j]);
    }
    println!("{:?}", ans);
}
0