結果

問題 No.762 PDCAパス
ユーザー eQeeQe
提出日時 2020-05-05 02:54:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,106 bytes
コンパイル時間 1,364 ms
コンパイル使用メモリ 147,180 KB
実行使用メモリ 11,120 KB
最終ジャッジ日時 2023-09-07 21:58:13
合計ジャッジ時間 4,635 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,736 KB
testcase_01 AC 4 ms
6,572 KB
testcase_02 AC 4 ms
6,520 KB
testcase_03 AC 4 ms
6,800 KB
testcase_04 AC 4 ms
6,592 KB
testcase_05 AC 4 ms
6,580 KB
testcase_06 AC 4 ms
6,516 KB
testcase_07 AC 4 ms
6,600 KB
testcase_08 AC 4 ms
6,532 KB
testcase_09 AC 4 ms
6,836 KB
testcase_10 AC 4 ms
6,544 KB
testcase_11 AC 4 ms
6,524 KB
testcase_12 AC 4 ms
6,860 KB
testcase_13 AC 4 ms
6,520 KB
testcase_14 AC 5 ms
6,540 KB
testcase_15 AC 4 ms
6,520 KB
testcase_16 AC 4 ms
6,596 KB
testcase_17 AC 4 ms
6,664 KB
testcase_18 AC 4 ms
6,524 KB
testcase_19 AC 4 ms
6,608 KB
testcase_20 AC 4 ms
6,804 KB
testcase_21 AC 4 ms
6,584 KB
testcase_22 AC 45 ms
8,212 KB
testcase_23 AC 45 ms
8,192 KB
testcase_24 AC 72 ms
10,588 KB
testcase_25 AC 73 ms
10,536 KB
testcase_26 AC 45 ms
9,112 KB
testcase_27 AC 45 ms
8,868 KB
testcase_28 AC 93 ms
11,120 KB
testcase_29 AC 92 ms
10,944 KB
testcase_30 AC 86 ms
10,628 KB
testcase_31 AC 87 ms
10,568 KB
testcase_32 AC 87 ms
10,572 KB
testcase_33 AC 79 ms
10,276 KB
testcase_34 AC 77 ms
10,196 KB
testcase_35 AC 82 ms
10,428 KB
testcase_36 AC 64 ms
9,432 KB
testcase_37 AC 66 ms
9,420 KB
testcase_38 AC 65 ms
9,472 KB
testcase_39 AC 66 ms
9,408 KB
testcase_40 AC 66 ms
9,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

ll N, M;
vector<ll> g[MAX];
ll a[MAX];
ll mem[MAX];

ll dfs(ll u) {
  if(a[u]==3) return 1;
  if(mem[u]!=-1) return mem[u];
  
  ll res=0;
  for(auto v:g[u]) if(a[u]+1==a[v]) {
    moC(res, +, dfs(v));
  }
  
  return mem[u]=res;
}

int main(void) {
  ll i, j, k;
  
  cin >> N >> M;
  string s;
  cin >> s;
  
  for(i=0; i<N; i++) {
    if(s[i]=='P') a[i]=0;
    if(s[i]=='D') a[i]=1;
    if(s[i]=='C') a[i]=2;
    if(s[i]=='A') a[i]=3;
  }
  
  for(i=0; i<M; i++) {
    ll u, v;
    cin >> u >> v; u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  
  memset(mem, -1, sizeof(mem));
  
  ll ans=0;
  for(i=0; i<N; i++) if(a[i]==0) moC(ans, +, dfs(i));
  pt(ans);
  
  
}
 
 
0