結果

問題 No.762 PDCAパス
ユーザー ミドリムシミドリムシ
提出日時 2018-12-10 11:52:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 876 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 65,416 KB
実行使用メモリ 12,428 KB
最終ジャッジ日時 2023-10-14 22:07:30
合計ジャッジ時間 7,459 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
12,428 KB
testcase_01 AC 3 ms
5,656 KB
testcase_02 AC 3 ms
5,668 KB
testcase_03 AC 4 ms
5,668 KB
testcase_04 AC 3 ms
5,672 KB
testcase_05 AC 3 ms
5,724 KB
testcase_06 AC 3 ms
5,672 KB
testcase_07 AC 3 ms
5,660 KB
testcase_08 AC 3 ms
5,752 KB
testcase_09 AC 3 ms
5,984 KB
testcase_10 AC 3 ms
5,728 KB
testcase_11 AC 3 ms
5,736 KB
testcase_12 AC 3 ms
5,816 KB
testcase_13 AC 3 ms
5,820 KB
testcase_14 AC 3 ms
5,652 KB
testcase_15 AC 3 ms
5,988 KB
testcase_16 AC 3 ms
5,676 KB
testcase_17 AC 3 ms
5,756 KB
testcase_18 AC 3 ms
5,740 KB
testcase_19 AC 3 ms
5,672 KB
testcase_20 AC 3 ms
5,860 KB
testcase_21 AC 3 ms
5,796 KB
testcase_22 AC 1,162 ms
6,668 KB
testcase_23 AC 1,160 ms
6,624 KB
testcase_24 AC 65 ms
10,984 KB
testcase_25 AC 65 ms
11,048 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

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 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