結果

問題 No.762 PDCAパス
ユーザー yuppe19 😺yuppe19 😺
提出日時 2018-12-10 13:34:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 81,724 KB
実行使用メモリ 10,116 KB
最終ジャッジ日時 2023-10-14 22:09:38
合計ジャッジ時間 3,227 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,496 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,356 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 17 ms
4,548 KB
testcase_23 AC 18 ms
4,424 KB
testcase_24 AC 37 ms
10,116 KB
testcase_25 AC 35 ms
9,972 KB
testcase_26 AC 19 ms
4,576 KB
testcase_27 AC 18 ms
4,636 KB
testcase_28 AC 44 ms
9,424 KB
testcase_29 AC 43 ms
9,428 KB
testcase_30 AC 41 ms
8,180 KB
testcase_31 AC 41 ms
8,108 KB
testcase_32 AC 40 ms
8,216 KB
testcase_33 AC 38 ms
7,184 KB
testcase_34 AC 38 ms
7,088 KB
testcase_35 AC 38 ms
7,024 KB
testcase_36 AC 31 ms
5,228 KB
testcase_37 AC 31 ms
5,240 KB
testcase_38 AC 32 ms
5,340 KB
testcase_39 AC 31 ms
5,228 KB
testcase_40 AC 31 ms
5,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using i64 = int64_t;

vector<i64> dp;
vector<vector<int>> G;
vector<int> arr;
constexpr int mod = static_cast<int>(powl(10, 9)) + 7;

i64 rec(int v, int cur) {
  i64 &res = dp[v];
  if(cur == 3) { return 1; }
  if(res != -1) { return res; }
  res = 0;
  for(int u : G[v]) {
    if(arr[u] == cur+1) {
      res += rec(u, cur+1);
      res %= mod;
    }
  }
  return res;
}

int main(void) {
  int n, m; scanf("%d%d", &n, &m);
  string s; cin >> s;
  arr.resize(n);
  for(int i=0; i<n; ++i) {
    arr[i] = static_cast<int>(string("PDCA").find(s[i]));
  }
  G.assign(n, vector<int>());
  for(int i=0; i<m; ++i) {
    int u, v; scanf("%d%d", &u, &v);
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dp.assign(n, -1);
  i64 res = 0;
  for(int i=0; i<n; ++i) {
    if(arr[i] == 0) {
      res += rec(i, 0);
      res %= mod;
    }
  }
  printf("%ld\n", res);
  return 0;
}
0