結果

問題 No.1111 コード進行
ユーザー fukafukatanifukafukatani
提出日時 2020-10-10 11:07:34
言語 Rust
(1.77.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 2,932 ms
コンパイル使用メモリ 140,388 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 21:11:06
合計ジャッジ時間 5,430 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 30 ms
4,380 KB
testcase_29 AC 12 ms
4,376 KB
testcase_30 AC 27 ms
4,384 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 29 ms
4,376 KB
testcase_33 AC 31 ms
4,376 KB
testcase_34 AC 21 ms
4,376 KB
testcase_35 AC 26 ms
4,376 KB
testcase_36 AC 68 ms
4,376 KB
testcase_37 AC 17 ms
4,380 KB
testcase_38 AC 14 ms
4,380 KB
testcase_39 AC 49 ms
4,376 KB
testcase_40 AC 55 ms
4,376 KB
testcase_41 AC 36 ms
4,376 KB
testcase_42 AC 29 ms
4,376 KB
testcase_43 AC 31 ms
4,376 KB
testcase_44 AC 9 ms
4,376 KB
testcase_45 AC 27 ms
4,376 KB
testcase_46 AC 6 ms
4,376 KB
testcase_47 AC 166 ms
4,380 KB
testcase_48 AC 6 ms
4,376 KB
testcase_49 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused variable: `i`
 --> Main.rs:5:9
  |
5 |     for i in 0..m {
  |         ^ help: if this is intentional, prefix it with an underscore: `_i`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

ソースコード

diff #

fn main() {
    let v = read_vec::<usize>();
    let (n, m, k) = (v[0], v[1], v[2]);
    let mut codes = vec![];
    for i in 0..m {
        let v = read_vec::<usize>();
        let (p, q, c) = (v[0] - 1, v[1] - 1, v[2]);
        codes.push((p, q, c));
    }
    let mut dp = vec![vec![0i64; k + 1]; 300];

    for i in 0..300 {
        dp[i][0] = 1;
    }

    for _ in 0..n - 1 {
        let mut next = vec![vec![0i64; k + 1]; 300];

        for &(p, q, c) in &codes {
            for prev_k in 0..k + 1 {
                if prev_k + c > k {
                    continue;
                }
                next[q][prev_k + c] += dp[p][prev_k];
                next[q][prev_k + c] %= 1000000007;
            }
        }
        dp = next;
    }
    let ans = dp.iter().map(|x| x[k]).fold(0, |s, x| (s + x) % 1000000007);
    println!("{}", ans);
}

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()
}
0