結果

問題 No.762 PDCAパス
ユーザー kk
提出日時 2020-08-15 05:13:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 200,724 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-04-18 23:38:10
合計ジャッジ時間 4,112 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,760 KB
testcase_01 AC 3 ms
6,016 KB
testcase_02 AC 3 ms
5,888 KB
testcase_03 AC 4 ms
5,888 KB
testcase_04 AC 3 ms
5,888 KB
testcase_05 AC 3 ms
5,888 KB
testcase_06 AC 3 ms
5,888 KB
testcase_07 AC 3 ms
6,016 KB
testcase_08 AC 4 ms
5,760 KB
testcase_09 AC 4 ms
6,016 KB
testcase_10 AC 4 ms
6,016 KB
testcase_11 AC 3 ms
6,016 KB
testcase_12 AC 3 ms
5,760 KB
testcase_13 AC 3 ms
6,016 KB
testcase_14 AC 3 ms
5,888 KB
testcase_15 AC 3 ms
6,016 KB
testcase_16 AC 3 ms
5,888 KB
testcase_17 AC 3 ms
5,888 KB
testcase_18 AC 3 ms
6,016 KB
testcase_19 AC 3 ms
5,888 KB
testcase_20 AC 3 ms
6,016 KB
testcase_21 AC 3 ms
5,888 KB
testcase_22 AC 18 ms
6,528 KB
testcase_23 AC 20 ms
6,528 KB
testcase_24 AC 42 ms
9,856 KB
testcase_25 AC 39 ms
9,984 KB
testcase_26 AC 18 ms
6,912 KB
testcase_27 AC 18 ms
6,784 KB
testcase_28 AC 39 ms
9,472 KB
testcase_29 AC 46 ms
9,472 KB
testcase_30 AC 40 ms
8,960 KB
testcase_31 AC 38 ms
9,088 KB
testcase_32 AC 39 ms
8,960 KB
testcase_33 AC 44 ms
8,448 KB
testcase_34 AC 38 ms
8,448 KB
testcase_35 AC 39 ms
8,448 KB
testcase_36 AC 28 ms
7,552 KB
testcase_37 AC 33 ms
7,552 KB
testcase_38 AC 30 ms
7,552 KB
testcase_39 AC 31 ms
7,552 KB
testcase_40 AC 33 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const int MOD = 1e9 + 7;
const string t = "PDCA";
int n, m;
string s;
vector<int> edges[100000];
long long w[100000];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> m >> s;
  REP (i, m) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }

  queue<int> q;
  REP (i, n) if (s[i] == 'P') {
    q.push(i);
    w[i] = 1;
  }
  long long ret = 0;

  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (s[v] == 'A') {
      ret += w[v];
      ret %= MOD;
    } else {
      char nxt = t[t.find(s[v]) + 1];
      for (int u: edges[v]) {
        if (s[u] == nxt) {
          if (!w[u])
            q.push(u);
          w[u] += w[v];
        }
      }
    }
  }
    
  cout << ret << endl;
  
  return 0;
}
0