結果

問題 No.762 PDCAパス
ユーザー Mr.SpockMr.Spock
提出日時 2020-12-26 19:15:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,279 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 173,032 KB
実行使用メモリ 15,388 KB
最終ジャッジ日時 2023-10-25 03:40:13
合計ジャッジ時間 4,597 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 58 ms
15,300 KB
testcase_25 AC 62 ms
15,388 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vector<int>edge_p[n];
	vector<int>edge_d[n];
	vector<int>edge_c[n];
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		if (s[u] > s[v])swap(u, v);
		if (s[v] == 'P' && s[u] == 'D') {
			edge_p[u].push_back(v);
			edge_p[v].push_back(u);
		}
		else if (s[u] == 'C' && s[v] == 'D') {
			edge_d[u].push_back(v);
			edge_d[v].push_back(u);
		}
		else if (s[u] == 'A' && s[v] == 'C') {
			edge_c[u].push_back(v);
			edge_c[v].push_back(u);
		}
	}
	vector<int>dp(n, 0);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'P')dp[i] = 1;
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == 'P') {
			for (auto k : edge_p[i]) {
				dp[k] += dp[i];
				dp[k] %= mod;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == 'D') {
			for (auto k : edge_d[i]) {
				dp[k] += dp[i];
				dp[k] %= mod;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == 'C') {
			for (auto k : edge_c[i]) {
				dp[k] = dp[i];
				dp[k] %= mod;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'A') {
			ans += dp[i];
			ans %= mod;
		}
	}
	cout << ans << endl;
}
0