結果

問題 No.762 PDCAパス
ユーザー fine
提出日時 2018-12-12 18:49:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,021 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 173,316 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-09-25 03:39:50
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    string s;
    cin >> n >> m >> s;
    vector< vector<int> > g(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    vector<ll> cntp(n, 0);
    for (int i = 0; i < n; i++) {
        if (s[i] != 'P') continue;
        for (int j : g[i]) {
            cntp[j] += (s[j] == 'D');
        }
    }

    vector<ll> cnta(n, 0);
    for (int i = 0; i < n; i++) {
        if (s[i] != 'C') continue;
        for (int j : g[i]) {
            cnta[i] += (s[j] == 'A');
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] != 'D') continue;
        for (int j : g[i]) {
            if (s[j] != 'C') continue;
            (ans += cntp[i] * cnta[j] % MOD) %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}
0