結果

問題 No.762 PDCAパス
ユーザー 特命ログイン特命ログイン
提出日時 2018-12-10 04:23:29
言語 Rust
(1.77.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,391 bytes
コンパイル時間 3,522 ms
コンパイル使用メモリ 144,064 KB
実行使用メモリ 8,364 KB
最終ジャッジ日時 2023-10-14 22:05:29
合計ジャッジ時間 4,403 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,356 KB
testcase_06 AC 0 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 1 ms
4,356 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,368 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,372 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 7 ms
4,352 KB
testcase_23 AC 6 ms
4,348 KB
testcase_24 AC 18 ms
8,332 KB
testcase_25 AC 16 ms
8,364 KB
testcase_26 AC 7 ms
4,348 KB
testcase_27 AC 8 ms
4,368 KB
testcase_28 AC 16 ms
7,852 KB
testcase_29 AC 17 ms
8,088 KB
testcase_30 AC 15 ms
7,020 KB
testcase_31 AC 15 ms
7,020 KB
testcase_32 AC 14 ms
7,072 KB
testcase_33 AC 14 ms
6,292 KB
testcase_34 AC 14 ms
6,204 KB
testcase_35 AC 14 ms
6,240 KB
testcase_36 AC 12 ms
4,856 KB
testcase_37 AC 11 ms
4,856 KB
testcase_38 AC 12 ms
4,916 KB
testcase_39 AC 11 ms
4,924 KB
testcase_40 AC 11 ms
4,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{Read, stdin};

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tok = buf.split_whitespace();
    let mut get = || tok.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(usize));
    }
    let md = 1_000_000_007;
    let n = get!();
    let m = get!();
    let s = get().as_bytes();
    let mut graph = vec![vec![]; n];
    let mut count = vec![0_u64; n];
    for _ in 0..m {
        let u = get!()-1;
        let v = get!()-1;
        let gu = s[u];
        let gv = s[v];
        match (gu, gv) {
        (b'C',b'A') => count[u] += 1,
        (b'A',b'C') => count[v] += 1,
        (b'D',b'C')|(b'P',b'D') => graph[v].push(u),
        (b'C',b'D')|(b'D',b'P') => graph[u].push(v),
        _ => {},
        }
    }
    for i in 0..s.len(){
        if s[i] == b'C' {
            for &j in graph[i].iter() {
                count[j] += count[i];
                count[j] %= md;
            }
        }
    }
    for i in 0..s.len(){
        if s[i] == b'D' {
            for &j in graph[i].iter() {
                count[j] += count[i];
                count[j] %= md;
            }
        }
    }
    let mut ans = 0;
    for i in 0..s.len(){
        if s[i] == b'P' {
            ans += count[i];
            ans %= md;
        }
    }
    println!("{}", ans);
}
0