結果
問題 | No.3040 Aoiスコア |
ユーザー |
![]() |
提出日時 | 2025-03-01 06:19:52 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,508 bytes |
コンパイル時間 | 3,816 ms |
コンパイル使用メモリ | 289,048 KB |
実行使用メモリ | 13,632 KB |
最終ジャッジ日時 | 2025-03-01 06:20:00 |
合計ジャッジ時間 | 7,405 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 TLE * 1 -- * 9 |
ソースコード
//#define _GLIBCXX_DEBUG#include <bits/stdc++.h>using namespace std;#define rep(i, n) for (int i = 0; i < (ll)(n); i++)#define all(a) (a).begin(), (a).end()using ll = long long;const int INF32 = 2e9;const ll INF64 = 4e18;const ll MOD = 998244353;vector<ll> P26={1};ll power26(int x){while(P26.size()<=x){P26.push_back(P26[P26.size()-1]*26%MOD);}return P26[x];}ll DFS(ll now, int depth, int questioncnt,vector<vector<int>> G,string S, set<int> seen){seen.insert(now);if(depth==0&&!(S[now]=='a'||S[now]=='?')){return 0;}if(depth==1&&!(S[now]=='o'||S[now]=='?')){return 0;}if(depth==2&&!(S[now]=='i'||S[now]=='?')){return 0;}if(S[now]=='?')questioncnt--;if(depth==2){return power26(questioncnt);}ll res = 0;for(auto p: G[now]){if(seen.count(p))continue;res += DFS(p,depth+1,questioncnt,G,S,seen);res%=MOD;}return res;}int main() {int N, M;string S;cin >> N >> M >> S;vector<vector<int>> G(N,vector<int>(0));int questioncnt = 0;rep(i,N){if(S[i]=='?')questioncnt++;}rep(i,M){int Ai, Bi;cin >> Ai >> Bi;Ai--;Bi--;G[Ai].push_back(Bi);G[Bi].push_back(Ai);}ll ans = 0;rep(i,N){set<int> seen;seen.insert(i);ans += DFS(i,0,questioncnt,G,S,seen);ans%=MOD;}cout << ans << endl;return 0;}