結果

問題 No.762 PDCAパス
ユーザー totori_nyaatotori_nyaa
提出日時 2019-07-17 19:58:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 1,549 ms
コンパイル使用メモリ 169,868 KB
実行使用メモリ 9,832 KB
最終ジャッジ日時 2023-08-24 20:18:53
合計ジャッジ時間 5,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,292 KB
testcase_01 AC 4 ms
6,288 KB
testcase_02 AC 4 ms
6,376 KB
testcase_03 AC 3 ms
6,228 KB
testcase_04 AC 3 ms
6,364 KB
testcase_05 AC 4 ms
6,416 KB
testcase_06 AC 4 ms
6,352 KB
testcase_07 AC 4 ms
6,348 KB
testcase_08 AC 4 ms
6,356 KB
testcase_09 AC 4 ms
6,448 KB
testcase_10 AC 4 ms
6,288 KB
testcase_11 AC 3 ms
6,220 KB
testcase_12 AC 4 ms
6,380 KB
testcase_13 AC 3 ms
6,356 KB
testcase_14 AC 4 ms
6,368 KB
testcase_15 AC 4 ms
6,312 KB
testcase_16 AC 5 ms
6,380 KB
testcase_17 AC 4 ms
6,376 KB
testcase_18 AC 4 ms
6,288 KB
testcase_19 AC 4 ms
6,220 KB
testcase_20 AC 4 ms
6,448 KB
testcase_21 AC 4 ms
6,672 KB
testcase_22 AC 19 ms
7,632 KB
testcase_23 AC 18 ms
7,496 KB
testcase_24 AC 36 ms
9,832 KB
testcase_25 AC 36 ms
9,636 KB
testcase_26 AC 20 ms
7,800 KB
testcase_27 AC 21 ms
7,788 KB
testcase_28 AC 41 ms
9,552 KB
testcase_29 AC 42 ms
9,408 KB
testcase_30 AC 40 ms
9,136 KB
testcase_31 AC 40 ms
9,116 KB
testcase_32 AC 40 ms
9,096 KB
testcase_33 AC 38 ms
8,592 KB
testcase_34 AC 36 ms
8,768 KB
testcase_35 AC 37 ms
8,568 KB
testcase_36 AC 31 ms
8,008 KB
testcase_37 AC 30 ms
8,048 KB
testcase_38 AC 30 ms
8,052 KB
testcase_39 AC 29 ms
8,040 KB
testcase_40 AC 30 ms
8,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

}
0