結果
問題 | No.2356 Back Door Tour in Four Seasons |
ユーザー |
|
提出日時 | 2023-07-16 23:15:32 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 219 ms / 2,000 ms |
コード長 | 1,533 bytes |
コンパイル時間 | 1,054 ms |
コンパイル使用メモリ | 113,804 KB |
最終ジャッジ日時 | 2025-02-15 15:21:16 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 28 |
ソースコード
#include<iostream>#include<set>#include<algorithm>#include<vector>#include<string>#include<set>#include<map>#include<numeric>#include<queue>#include<cmath>#include <unordered_set>using namespace std;typedef long long ll;const ll INF=1LL<<60;typedef pair<ll,ll> P;typedef pair<int,P> PP;const ll MOD=998244353;ll mod_pow(ll x,ll y,ll mod){ll res=1;x%=mod;while(y>0){if(y&1){res*=x;res%=mod;}x*=x;x%=mod;y/=2;}return res;}int main(){int N;cin>>N;vector<pair<char,ll>> SA;vector<char> S(N);vector<int> A(N);ll cntP=0;ll cntAll=0;for(int i=0;i<N;i++){cin>>S[i]>>A[i];SA.emplace_back(S[i],A[i]);if(S[i]=='P') cntP++;cntAll+=A[i];}vector<ll> cnt2(3,0);for(int i=0;i<N;i++){auto [s,a]=SA[i];ll t=(mod_pow(N-1,a,MOD) - mod_pow(N-2,a,MOD)+MOD)%MOD;ll u=mod_pow(mod_pow(N-1,a,MOD),MOD-2,MOD);ll c=t*u%MOD;if(s=='U'){cnt2[0]+=c;cnt2[0]%=MOD;}if(s=='F'){cnt2[1]+=c;cnt2[1]%=MOD;}if(s=='W'){cnt2[2]+=c;cnt2[2]%=MOD;}}ll ans=1;for(int i=0;i<3;i++){//i=0,1,2ans*=cnt2[i];ans%=MOD;}ans*=cntP%MOD;ans%=MOD;ans*=mod_pow(N-1,cntAll,MOD);ans%=MOD;cout<<ans<<endl;}