結果
| 問題 |
No.3040 Aoiスコア
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2025-03-01 07:00:56 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 1,000 ms |
| コード長 | 1,266 bytes |
| コンパイル時間 | 2,886 ms |
| コンパイル使用メモリ | 282,056 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 21:02:13 |
| 合計ジャッジ時間 | 3,887 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
V<int> G[6060];
const int MOD=998244353;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
V<ll> P(6060);
P[0]=1;
for(int i=1;i<6060;i++) P[i]=P[i-1]*26%MOD;
int n,m;
cin>>n>>m;
string s;
cin>>s;
ll cnt=0;
rep(i,n) if(s[i]=='?') cnt++;
rep(i,m){
int a,b;
cin>>a>>b;
a--,b--;
G[a].push_back(b);
G[b].push_back(a);
}
ll ans=0;
rep(i,n){
ll ca=0,ci=0,cq=0;
for(auto v:G[i]){
if(s[v]=='a') ca++;
else if(s[v]=='i') ci++;
else if(s[v]=='?') cq++;
}
if(s[i]=='o'){
ans=(ans+ca*ci%MOD*P[cnt]%MOD)%MOD;
if(cq) ans=(ans+ca*cq%MOD*P[cnt-1]%MOD)%MOD;
if(cq) ans=(ans+cq*ci%MOD*P[cnt-1]%MOD)%MOD;
if(cq>1) ans=(ans+cq*(cq-1)%MOD*P[cnt-2]%MOD)%MOD;
}
else if(s[i]=='?'){
ans=(ans+ca*ci%MOD*P[cnt-1]%MOD)%MOD;
if(cq) ans=(ans+ca*cq%MOD*P[cnt-2]%MOD)%MOD;
if(cq) ans=(ans+cq*ci%MOD*P[cnt-2]%MOD)%MOD;
if(cq>1) ans=(ans+cq*(cq-1)%MOD*P[cnt-3]%MOD)%MOD;
}
}
cout<<ans<<endl;
return 0;
}
umezo