結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー HIcoderHIcoder
提出日時 2023-07-16 23:15:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,533 bytes
コンパイル時間 1,088 ms
コンパイル使用メモリ 117,592 KB
実行使用メモリ 15,072 KB
最終ジャッジ日時 2023-10-17 21:07:40
合計ジャッジ時間 9,554 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 226 ms
15,072 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 227 ms
15,072 KB
testcase_09 AC 239 ms
15,072 KB
testcase_10 AC 239 ms
15,072 KB
testcase_11 AC 240 ms
15,072 KB
testcase_12 AC 241 ms
15,072 KB
testcase_13 AC 239 ms
15,072 KB
testcase_14 AC 238 ms
15,072 KB
testcase_15 AC 120 ms
9,512 KB
testcase_16 AC 223 ms
14,856 KB
testcase_17 AC 227 ms
14,928 KB
testcase_18 AC 219 ms
14,816 KB
testcase_19 AC 122 ms
9,524 KB
testcase_20 AC 214 ms
14,768 KB
testcase_21 AC 174 ms
10,380 KB
testcase_22 AC 122 ms
9,516 KB
testcase_23 AC 88 ms
5,964 KB
testcase_24 AC 227 ms
14,920 KB
testcase_25 AC 8 ms
4,348 KB
testcase_26 AC 175 ms
10,376 KB
testcase_27 AC 226 ms
14,912 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 227 ms
15,072 KB
testcase_31 AC 229 ms
15,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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,2
        ans*=cnt2[i];
        ans%=MOD;
    }
    ans*=cntP%MOD;
    ans%=MOD;

    ans*=mod_pow(N-1,cntAll,MOD);
    ans%=MOD;

    cout<<ans<<endl;







}
0