結果

問題 No.762 PDCAパス
ユーザー SSRSSSRS
提出日時 2020-11-26 07:11:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 77,592 KB
実行使用メモリ 12,556 KB
最終ジャッジ日時 2023-10-01 03:13:40
合計ジャッジ時間 3,836 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 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,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 37 ms
4,572 KB
testcase_23 AC 37 ms
4,388 KB
testcase_24 AC 67 ms
12,548 KB
testcase_25 AC 67 ms
12,556 KB
testcase_26 AC 38 ms
4,564 KB
testcase_27 AC 38 ms
4,556 KB
testcase_28 AC 82 ms
12,372 KB
testcase_29 AC 86 ms
12,412 KB
testcase_30 AC 82 ms
10,144 KB
testcase_31 AC 81 ms
10,440 KB
testcase_32 AC 79 ms
10,180 KB
testcase_33 AC 70 ms
8,348 KB
testcase_34 AC 71 ms
8,336 KB
testcase_35 AC 75 ms
8,424 KB
testcase_36 AC 60 ms
5,452 KB
testcase_37 AC 58 ms
5,488 KB
testcase_38 AC 59 ms
5,516 KB
testcase_39 AC 56 ms
5,440 KB
testcase_40 AC 57 ms
5,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
const long long MOD = 1000000007;
int main(){
	int N, M;
	cin >> N >> M;
	string S;
	cin >> S;
	vector<vector<int>> E(N);
	for (int i = 0; i < M; i++){
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	string T = "PDCA";
	vector<vector<long long>> dp(4, vector<long long>(N, 0));
	for (int i = 0; i < N; i++){
		if (S[i] == T[0]){
			dp[0][i] = 1;
		}
	}
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < N; j++){
			if (S[j] == T[i]){
				for (int k : E[j]){
					if (S[k] == T[i + 1]){
						dp[i + 1][k] += dp[i][j];
						dp[i + 1][k] %= MOD;
					}
				}
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < N; i++){
		ans += dp[3][i];
	}
	ans %= MOD;
	cout << ans << endl;
}
0