結果

問題 No.3040 Aoiスコア
ユーザー 北杜
提出日時 2025-02-28 22:59:27
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,501 bytes
コンパイル時間 3,698 ms
コンパイル使用メモリ 335,480 KB
実行使用メモリ 13,188 KB
最終ジャッジ日時 2025-06-20 21:00:05
合計ジャッジ時間 6,724 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 2 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#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, vector<bool> seen){
    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[p])continue;
        seen[p]=true;
        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){
        vector<bool> seen(N,false);
        seen[i]=true;
        ans += BFS(i,0,questioncnt,G,S,seen);
        ans%=MOD;
    }
    cout << ans << endl;
    return 0;
}
0