結果

問題 No.762 PDCAパス
ユーザー aaaaaaiuaaaaaaiu
提出日時 2019-08-21 02:58:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 701 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 197,816 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-16 06:00:50
合計ジャッジ時間 6,453 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
6,940 KB
testcase_18 WA -
testcase_19 AC 2 ms
6,944 KB
testcase_20 WA -
testcase_21 AC 2 ms
6,944 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
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 <bits/stdc++.h>
using namespace std;
typedef long long ll;

int dfs(vector<int> g[], int v, string s, string pdca, int i, int mod) {
    ll ans=0;
    for (int u:g[v]) {
        if (s[u]==pdca[i]) {
            if (i==3) ans+=1;
            else ans=(ans+dfs(g,u,s,pdca,i+1,mod))%mod;
        }
    }
    return ans;
}

int main() {
    int n,m;
    cin>>n>>m;
    string s;cin>>s;
    vector<int> g[n];
    for (int i=0;i<m;i++) {
        int v,u;cin>>v>>u;
        v--,u--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    string pdca="PDCA";
    ll ans=0;
    int mod=1e9+7;
    for (int i=0;i<n;i++) ans=(ans+dfs(g,i,s,pdca,0,mod))%mod;
    cout<<ans<<endl;
    return 0;
}
0