結果
| 問題 | No.762 PDCAパス | 
| コンテスト | |
| ユーザー |  totori_nyaa | 
| 提出日時 | 2019-07-17 19:58:38 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 54 ms / 2,000 ms | 
| コード長 | 831 bytes | 
| コンパイル時間 | 1,727 ms | 
| コンパイル使用メモリ | 172,232 KB | 
| 実行使用メモリ | 9,984 KB | 
| 最終ジャッジ日時 | 2024-12-23 06:03:12 | 
| 合計ジャッジ時間 | 4,824 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 38 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
vector<vector<int>> v(111111);
string s;
int n,m;
string pdca="PDCA";
vector<ll> cnt(111111,1);
ll calc(int a,int p){
    ll ret=0;
    for(auto i:v[p]){
        if(s[i]==pdca[a+1]){
            ret+=cnt[i];
            ret%=mod;
        }
    }
    return ret;
}
signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cin>>n>>m;
    cin>>s;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    ll ans=0;
    for(int i=2;i>=0;i--){
        for(int j=0;j<n;j++){
            if(pdca[i]==s[j]){
                cnt[j]=calc(i,j);
                if(i==0) ans+=cnt[j];
                ans%=mod;
            }
        }
    }
    cout<<ans<<endl;
}
            
            
            
        