結果

問題 No.762 PDCAパス
ユーザー t33f
提出日時 2018-12-10 20:31:30
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 71,424 KB
実行使用メモリ 12,112 KB
最終ジャッジ日時 2024-09-16 15:56:54
合計ジャッジ時間 3,669 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#define M 1000000007
using namespace std;
int main(int argc, char** argv) {
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector<int> adj[100100];

    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        adj[x].push_back(y); adj[y].push_back(x);
    }
    long long dp[4][100100] = {};
    const string target = "ACDP";
    for (int j = 1; j <= n; j++) if (s[j-1] == 'A') dp[0][j] = 1;
    for (int i = 1; i < 4; i++)
        for (int j = 1; j <= n; j++) {
            if (s[j-1] == target[i])
                for (int k : adj[j]) dp[i][j] += dp[i-1][k];
            dp[i][j] %= M;
        }
    long long ans = 0;
    for (int j = 1; j <= n; j++) ans += dp[3][j];
    cout << ans % M << endl;
}
0