結果

問題 No.762 PDCAパス
ユーザー m-44m-44
提出日時 2019-09-12 19:26:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,037 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 167,388 KB
実行使用メモリ 8,580 KB
最終ジャッジ日時 2023-09-15 14:16:40
合計ジャッジ時間 5,468 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,744 KB
testcase_01 AC 2 ms
5,756 KB
testcase_02 AC 3 ms
5,680 KB
testcase_03 AC 3 ms
5,700 KB
testcase_04 AC 3 ms
5,756 KB
testcase_05 AC 3 ms
5,672 KB
testcase_06 AC 3 ms
5,720 KB
testcase_07 AC 3 ms
5,680 KB
testcase_08 AC 3 ms
5,704 KB
testcase_09 AC 3 ms
5,768 KB
testcase_10 AC 3 ms
5,820 KB
testcase_11 AC 3 ms
5,972 KB
testcase_12 WA -
testcase_13 AC 3 ms
5,736 KB
testcase_14 AC 3 ms
5,708 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 3 ms
5,744 KB
testcase_18 WA -
testcase_19 AC 3 ms
5,688 KB
testcase_20 WA -
testcase_21 AC 3 ms
5,656 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 62 ms
8,508 KB
testcase_25 AC 61 ms
8,580 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
  vector<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.push_back(u);
      }
    } else if (iu == iv + 1) {
      g[v].push_back(u);
      if (s[v] == 'P') {
        ps.push_back(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