結果

問題 No.762 PDCAパス
ユーザー phsplsphspls
提出日時 2020-07-12 23:05:21
言語 Rust
(1.77.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,443 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 160,640 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-04-24 00:17:50
合計ジャッジ時間 3,655 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 18 ms
5,376 KB
testcase_23 AC 18 ms
5,376 KB
testcase_24 AC 44 ms
12,544 KB
testcase_25 AC 42 ms
12,544 KB
testcase_26 AC 18 ms
5,376 KB
testcase_27 AC 19 ms
5,376 KB
testcase_28 AC 47 ms
12,032 KB
testcase_29 AC 44 ms
12,032 KB
testcase_30 AC 38 ms
9,984 KB
testcase_31 AC 38 ms
9,984 KB
testcase_32 AC 39 ms
9,984 KB
testcase_33 AC 35 ms
8,064 KB
testcase_34 AC 35 ms
8,064 KB
testcase_35 AC 36 ms
8,192 KB
testcase_36 AC 29 ms
5,504 KB
testcase_37 AC 30 ms
5,504 KB
testcase_38 AC 30 ms
5,504 KB
testcase_39 AC 28 ms
5,504 KB
testcase_40 AC 29 ms
5,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const DIVISOR: usize = 1_000_000_007;
const NAME: &str = "PDCA";

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s: Vec<char> = s.trim().chars().collect();
    let mut dp: Vec<Vec<usize>> = vec![vec![0; n]; 4];
    let mut path: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..m {
        let mut uv = String::new();
        std::io::stdin().read_line(&mut uv).ok();
        let uv: Vec<usize> = uv.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let u = uv[0] - 1;
        let v = uv[1] - 1;
        path[u].push(v);
        path[v].push(u);
    }

    for i in 0..4 {
        let charactor: char = NAME.chars().nth(3-i).unwrap();
        for j in 0..n {
            if i == 0 {
                dp[i][j] = if s[j] == charactor { 1 } else { 0 };
            } else {
                if dp[i-1][j] > 0 {
                    path[j].iter()
                        .filter(|&node| s[*node] == charactor)
                        .for_each(|&node| {
                            dp[i][node] += dp[i-1][j];
                        });
                }
            }
        }
    }
    println!("{}", dp[3].iter().map(|i| i % DIVISOR).sum::<usize>() % DIVISOR);
}
0