結果
問題 |
No.3040 Aoiスコア
|
ユーザー |
![]() |
提出日時 | 2025-02-28 23:15:48 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,494 bytes |
コンパイル時間 | 2,937 ms |
コンパイル使用メモリ | 289,244 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-20 21:01:21 |
合計ジャッジ時間 | 6,353 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 TLE * 1 -- * 11 |
ソースコード
//#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; ll power26(int x){ ll res = 1; for(int i = 0; i < x; i++){ res*=26; res%=MOD; } return res; } ll BFS(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 += BFS(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 += BFS(i,0,questioncnt,G,S,seen); ans%=MOD; } cout << ans << endl; return 0; }