結果

問題 No.762 PDCAパス
ユーザー oxyshoweroxyshower
提出日時 2019-02-27 18:02:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 1,538 ms
コンパイル使用メモリ 169,124 KB
実行使用メモリ 9,980 KB
最終ジャッジ日時 2023-09-05 09:24:03
合計ジャッジ時間 5,103 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,504 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 18 ms
5,128 KB
testcase_23 AC 19 ms
5,128 KB
testcase_24 AC 43 ms
9,428 KB
testcase_25 AC 42 ms
9,424 KB
testcase_26 AC 19 ms
5,488 KB
testcase_27 AC 19 ms
5,432 KB
testcase_28 AC 57 ms
9,948 KB
testcase_29 AC 55 ms
9,980 KB
testcase_30 AC 56 ms
8,852 KB
testcase_31 AC 55 ms
8,924 KB
testcase_32 AC 54 ms
8,892 KB
testcase_33 AC 46 ms
7,800 KB
testcase_34 AC 46 ms
7,904 KB
testcase_35 AC 43 ms
7,860 KB
testcase_36 AC 32 ms
6,528 KB
testcase_37 AC 32 ms
6,596 KB
testcase_38 AC 32 ms
6,592 KB
testcase_39 AC 32 ms
6,428 KB
testcase_40 AC 32 ms
6,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MOD = 1e9+7;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,m; cin >> n >> m;
  string s; cin >> s;
  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<int> dp(n,0);
  string PDCA = "PDCA";
  for(int i = 0; i < n; i++){
    if(s[i] == 'P') dp[i]++;
  }
  for(int j = 0; j < 3; j++){
    for(int i = 0; i < n; i++){
      for(int v : G[i]){
        if(s[i] == PDCA[j] && s[v] == PDCA[j+1]){
          dp[v] += dp[i];
          dp[v] %= MOD;
        }
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'A'){
      ans += dp[i];
      ans %= MOD;
    }
  }
  cout << ans << endl;

  return 0;
}
0