結果

問題 No.762 PDCAパス
ユーザー face4face4
提出日時 2018-12-10 17:58:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 562 ms
コンパイル使用メモリ 72,064 KB
実行使用メモリ 9,348 KB
最終ジャッジ日時 2023-10-14 22:15:44
合計ジャッジ時間 3,277 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,352 KB
testcase_18 AC 1 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 1 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 39 ms
4,572 KB
testcase_23 AC 39 ms
4,348 KB
testcase_24 AC 60 ms
9,292 KB
testcase_25 AC 60 ms
9,348 KB
testcase_26 AC 39 ms
4,640 KB
testcase_27 AC 40 ms
4,596 KB
testcase_28 AC 76 ms
8,936 KB
testcase_29 AC 76 ms
9,168 KB
testcase_30 AC 72 ms
7,832 KB
testcase_31 AC 72 ms
7,824 KB
testcase_32 AC 72 ms
7,892 KB
testcase_33 AC 68 ms
6,924 KB
testcase_34 AC 69 ms
7,008 KB
testcase_35 AC 68 ms
6,920 KB
testcase_36 AC 59 ms
5,520 KB
testcase_37 AC 59 ms
5,256 KB
testcase_38 AC 59 ms
5,316 KB
testcase_39 AC 59 ms
5,336 KB
testcase_40 AC 58 ms
5,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cstring>
using namespace std;

const int mod = 1e9+7;

int main(){
    int n, m;
    string s;
    
    cin >> n >> m >> s;

    // convert to 1-indexed
    s = "X"+s;

    vector<int> path[n+1];
    
    int u, v;
    while(m-- > 0){
        cin >> u >> v;
        path[u].push_back(v);
        path[v].push_back(u);
    }

    int cnt[n+1];
    
    for(int i = 1; i <= n; i++) cnt[i] = (s[i] == 'P');

    for(int i = 0; i < 3; i++){
        for(int j = 1; j <= n; j++){
            if(s[j] != "PDCA"[i])   continue;
            for(int next : path[j]){
                if(s[next] == "PDCA"[i+1])  cnt[next] = (cnt[next]+cnt[j])%mod;
            }
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(s[i] == 'A') ans = (ans + cnt[i])%mod;
    }

    cout << ans << endl;

    return 0;
}
0