結果

問題 No.762 PDCAパス
ユーザー ミドリムシミドリムシ
提出日時 2018-12-10 11:54:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 63,696 KB
実行使用メモリ 10,988 KB
最終ジャッジ日時 2023-10-14 22:07:35
合計ジャッジ時間 3,335 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,820 KB
testcase_01 AC 3 ms
5,692 KB
testcase_02 AC 3 ms
5,792 KB
testcase_03 AC 3 ms
5,668 KB
testcase_04 AC 3 ms
5,660 KB
testcase_05 AC 3 ms
5,816 KB
testcase_06 AC 3 ms
5,696 KB
testcase_07 AC 3 ms
5,640 KB
testcase_08 AC 3 ms
5,812 KB
testcase_09 AC 3 ms
5,676 KB
testcase_10 AC 3 ms
5,700 KB
testcase_11 AC 3 ms
5,980 KB
testcase_12 AC 4 ms
5,692 KB
testcase_13 AC 3 ms
5,768 KB
testcase_14 AC 3 ms
5,700 KB
testcase_15 AC 3 ms
5,640 KB
testcase_16 AC 3 ms
5,700 KB
testcase_17 AC 3 ms
5,696 KB
testcase_18 AC 3 ms
5,672 KB
testcase_19 AC 3 ms
5,840 KB
testcase_20 AC 3 ms
5,676 KB
testcase_21 AC 3 ms
5,660 KB
testcase_22 AC 41 ms
6,716 KB
testcase_23 AC 42 ms
6,780 KB
testcase_24 AC 65 ms
10,988 KB
testcase_25 AC 66 ms
10,928 KB
testcase_26 AC 42 ms
6,964 KB
testcase_27 AC 42 ms
6,812 KB
testcase_28 AC 79 ms
10,652 KB
testcase_29 AC 81 ms
10,756 KB
testcase_30 AC 75 ms
9,728 KB
testcase_31 AC 77 ms
9,664 KB
testcase_32 AC 76 ms
9,852 KB
testcase_33 AC 70 ms
8,900 KB
testcase_34 AC 71 ms
8,612 KB
testcase_35 AC 71 ms
8,532 KB
testcase_36 AC 61 ms
7,244 KB
testcase_37 AC 61 ms
7,324 KB
testcase_38 AC 61 ms
7,368 KB
testcase_39 AC 62 ms
7,352 KB
testcase_40 AC 62 ms
7,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

string S;
vector<vector<int>> roads;

long dp[100010][3];

long move(int now, int PDCA){
    if(PDCA == 3){
        return 1;
    }else if(dp[now][PDCA] != -1){
        return dp[now][PDCA];
    }
    long ans = 0;
    for(int i: roads[now]){
        if(S[i] == "PDCA"[PDCA + 1]){
            ans += move(i, PDCA + 1);
        }
    }
    return dp[now][PDCA] = ans % long(1e9 + 7);
}

int main(){
    int N, M;
    cin >> N >> M >> S;
    roads.resize(N);
    for(int i = 0; i < M; i++){
        int u, v;
        cin >> u >> v;
        roads[u - 1].push_back(v - 1);
        roads[v - 1].push_back(u - 1);
    }
    memset(dp, -1, sizeof(dp));
    long ans = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == 'P'){
            ans += move(i, 0);
        }
    }
    cout << ans % long(1e9 + 7) << endl; 
}
0