結果

問題 No.762 PDCAパス
ユーザー lapilapi
提出日時 2019-04-18 20:34:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,348 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 107,988 KB
実行使用メモリ 10,432 KB
最終ジャッジ日時 2023-10-23 16:23:33
合計ジャッジ時間 5,475 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,428 KB
testcase_01 AC 4 ms
5,428 KB
testcase_02 AC 4 ms
5,428 KB
testcase_03 AC 3 ms
5,428 KB
testcase_04 AC 3 ms
5,428 KB
testcase_05 AC 4 ms
5,428 KB
testcase_06 AC 4 ms
5,428 KB
testcase_07 AC 4 ms
5,428 KB
testcase_08 AC 4 ms
5,428 KB
testcase_09 AC 3 ms
5,428 KB
testcase_10 AC 3 ms
5,428 KB
testcase_11 AC 3 ms
5,428 KB
testcase_12 AC 3 ms
5,428 KB
testcase_13 AC 4 ms
5,428 KB
testcase_14 AC 3 ms
5,428 KB
testcase_15 AC 3 ms
5,428 KB
testcase_16 AC 3 ms
5,428 KB
testcase_17 AC 4 ms
5,428 KB
testcase_18 AC 4 ms
5,428 KB
testcase_19 AC 4 ms
5,428 KB
testcase_20 AC 4 ms
5,428 KB
testcase_21 AC 4 ms
5,428 KB
testcase_22 AC 19 ms
6,652 KB
testcase_23 AC 19 ms
6,652 KB
testcase_24 AC 36 ms
10,432 KB
testcase_25 AC 36 ms
10,432 KB
testcase_26 AC 19 ms
6,892 KB
testcase_27 AC 20 ms
6,928 KB
testcase_28 AC 45 ms
10,128 KB
testcase_29 AC 47 ms
10,128 KB
testcase_30 AC 41 ms
9,296 KB
testcase_31 AC 41 ms
9,292 KB
testcase_32 AC 41 ms
9,296 KB
testcase_33 AC 37 ms
8,640 KB
testcase_34 AC 38 ms
8,636 KB
testcase_35 AC 38 ms
8,640 KB
testcase_36 AC 30 ms
7,424 KB
testcase_37 AC 31 ms
7,420 KB
testcase_38 AC 30 ms
7,424 KB
testcase_39 AC 31 ms
7,552 KB
testcase_40 AC 31 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

vector<vector<int>> V(100001);
char S[100001];

ll DCA[100001]; // DCA[i] : i番目の文字から始まるDCAの個数 i番目がD出なかったら0
ll CA[100001];

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

	int N, M; cin >> N >> M;
	for (int i = 1; i <= N; i++) cin >> S[i];
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		V[a].push_back(b);
		V[b].push_back(a);
	}

	// CAを埋める
	for (int i = 1; i <= N; i++) {
		if (S[i] == 'C') {
			for (int j = 0; j < V[i].size(); j++) {
				if (S[V[i][j]] == 'A') CA[i]++;
			}
		}
	}

	// DCAを埋める
	for (int i = 1; i <= N; i++) {
		if (S[i] == 'D') {
			for (int j = 0; j < V[i].size(); j++) {
				DCA[i] += CA[V[i][j]];
			}
		}
		//cout << DCA[i] << " ";
	}

	ll ans = 0LL;
	for (int i = 1; i <= N; i++) {
		if (S[i] == 'P') {
			for (int j = 0; j < V[i].size(); j++) {
				ans += DCA[V[i][j]];
				ans %= MOD;
			}
		}
	}

	//cout << endl;
	cout << ans << endl;

	return 0;
}
0