結果
問題 | No.762 PDCAパス |
ユーザー |
|
提出日時 | 2019-02-22 14:26:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 838 bytes |
コンパイル時間 | 1,769 ms |
コンパイル使用メモリ | 199,524 KB |
最終ジャッジ日時 | 2025-01-06 21:21:23 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;signed main() {ios::sync_with_stdio(false); cin.tie(0);const int mod = 1e9 + 7;int n, m;cin >> n >> m;string s;cin >> s;vector<pair<int, int>> e[3];vector<int> dp(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[u] == 'P' && s[v] == 'D') {e[0].emplace_back(u, v);dp[u] = 1;}if (s[u] == 'D' && s[v] == 'C') {e[1].emplace_back(u, v);}if (s[u] == 'C' && s[v] == 'A') {e[2].emplace_back(u, v);}}for (int i = 0; i < 3; i++) {for (auto j : e[i]) {dp[j.second] += dp[j.first];dp[j.second] %= mod;}}int ans = 0;for (int i = 0; i < n; i++) {if (s[i] == 'A') {ans += dp[i];ans %= mod;}}cout << ans << endl;return 0;}