結果

問題 No.762 PDCAパス
ユーザー m-44m-44
提出日時 2019-09-12 21:18:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,028 bytes
コンパイル時間 1,474 ms
コンパイル使用メモリ 173,304 KB
実行使用メモリ 9,996 KB
最終ジャッジ日時 2023-09-15 14:18:15
合計ジャッジ時間 4,628 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,752 KB
testcase_01 AC 3 ms
5,900 KB
testcase_02 AC 3 ms
5,748 KB
testcase_03 AC 3 ms
5,892 KB
testcase_04 AC 3 ms
5,828 KB
testcase_05 AC 3 ms
6,028 KB
testcase_06 AC 3 ms
5,808 KB
testcase_07 AC 3 ms
5,752 KB
testcase_08 AC 3 ms
5,696 KB
testcase_09 AC 3 ms
5,760 KB
testcase_10 AC 3 ms
5,696 KB
testcase_11 AC 3 ms
6,032 KB
testcase_12 AC 3 ms
5,748 KB
testcase_13 AC 3 ms
5,756 KB
testcase_14 AC 3 ms
6,024 KB
testcase_15 AC 3 ms
5,864 KB
testcase_16 AC 3 ms
5,692 KB
testcase_17 AC 3 ms
5,720 KB
testcase_18 AC 3 ms
5,764 KB
testcase_19 AC 3 ms
5,692 KB
testcase_20 AC 3 ms
5,704 KB
testcase_21 AC 3 ms
5,700 KB
testcase_22 AC 43 ms
5,952 KB
testcase_23 AC 44 ms
5,960 KB
testcase_24 AC 76 ms
9,996 KB
testcase_25 AC 77 ms
9,704 KB
testcase_26 AC 45 ms
6,328 KB
testcase_27 AC 45 ms
6,320 KB
testcase_28 AC 70 ms
7,576 KB
testcase_29 AC 70 ms
7,580 KB
testcase_30 AC 70 ms
7,348 KB
testcase_31 AC 70 ms
7,412 KB
testcase_32 AC 69 ms
7,364 KB
testcase_33 AC 65 ms
7,108 KB
testcase_34 AC 67 ms
7,128 KB
testcase_35 AC 66 ms
7,248 KB
testcase_36 AC 59 ms
6,624 KB
testcase_37 AC 59 ms
6,360 KB
testcase_38 AC 59 ms
6,360 KB
testcase_39 AC 59 ms
6,412 KB
testcase_40 AC 59 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, m;
string s;
vector<int> g[(int)1e5];
long long mod = 1e9 + 7;
int x[(int)1e5];
string pdca = "PDCA";

long long dfs(int cur) {
  long long ret = 0;
  if (s[cur] == 'A') {
    return 1;
  }
  for (int to: g[cur]) {
    if (x[to] == -1) {
      ret += dfs(to);
    } else {
      ret += x[to];
    }
    ret %= mod;
  }
  x[cur] = ret;
  return ret;
}

int main() {
  cin>>n>>m;
  cin>>s;
  set<int> ps;
  for (int i=0; i<m; i++) {
    int u, v;
    cin>>u>>v;
    --u;
    --v;
    int iu = pdca.find(s[u]);
    int iv = pdca.find(s[v]);
    if (iu == string::npos || iv == string::npos) {
      continue;
    }
    if (iv == iu + 1) {
      g[u].push_back(v);
      if (s[u] == 'P') {
        ps.insert(u);
      }
    } else if (iu == iv + 1) {
      g[v].push_back(u);
      if (s[v] == 'P') {
        ps.insert(v);
      }
    }
  }
  for (int i=0; i<n; i++) x[i] = -1;
  long long ans = 0;
  for (int i: ps) {
    ans += dfs(i);
    ans %= mod;
  }
  cout<<ans<<endl;
}
0