結果
| 問題 |
No.3040 Aoiスコア
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-01 07:27:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,344 bytes |
| コンパイル時間 | 1,769 ms |
| コンパイル使用メモリ | 206,456 KB |
| 実行使用メモリ | 16,064 KB |
| 最終ジャッジ日時 | 2025-06-20 21:02:16 |
| 合計ジャッジ時間 | 4,331 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 TLE * 1 -- * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include<atcoder/modint>
using mint=atcoder::modint998244353;
int n,m;
string s;
int hate=0;
mint ans=0;
string word="aoi";
vector<mint>tw={1};
void DFS(int now,int deepth,int used,vector<bool>&visited,vector<vector<int>>&connect){
if (deepth==2){
mint cnt=tw[hate-used];
ans+=cnt;
}
for(auto to:connect[now]){
if(s[to]==word[deepth+1] || s[to]=='?'){
if(!visited[to]){
visited[to]=true;
if(s[to]=='?')DFS(to,deepth+1,used+1,visited,connect);
else DFS(to,deepth+1,used,visited,connect);
visited[to]=false;
}
}
}
}
int main(){
cin>>n>>m;
cin>>s;
for(int i=0;i<7000;i++){
tw.push_back(tw[tw.size()-1]*26);
}
vector<vector<int>>connect(n);
for(int i=0;i<n;i++)if(s[i]=='?')hate++;
for(int i=0;i<m;i++){
int a,b;cin>>a>>b;
a--;b--;
connect[a].push_back(b);
connect[b].push_back(a);
}
for(int start=0;start<n;start++){
vector<bool>visited(n,false);
if (s[start]=='a'||s[start]=='?'){
visited[start]=true;
if (s[start]=='?')DFS(start,0,1,visited,connect);
else DFS(start,0,0,visited,connect);
}
}
cout<<ans.val()<<endl;
}