結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー ぷらぷら
提出日時 2023-06-16 22:18:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 2,272 ms
コンパイル使用メモリ 211,172 KB
実行使用メモリ 5,472 KB
最終ジャッジ日時 2023-09-06 20:25:09
合計ジャッジ時間 7,162 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 128 ms
4,980 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 145 ms
4,616 KB
testcase_09 AC 180 ms
4,724 KB
testcase_10 AC 180 ms
4,752 KB
testcase_11 AC 180 ms
4,652 KB
testcase_12 AC 180 ms
4,604 KB
testcase_13 AC 181 ms
4,532 KB
testcase_14 AC 180 ms
4,668 KB
testcase_15 AC 91 ms
4,380 KB
testcase_16 AC 167 ms
4,524 KB
testcase_17 AC 170 ms
4,596 KB
testcase_18 AC 165 ms
4,632 KB
testcase_19 AC 92 ms
4,376 KB
testcase_20 AC 162 ms
4,736 KB
testcase_21 AC 132 ms
4,560 KB
testcase_22 AC 91 ms
4,376 KB
testcase_23 AC 67 ms
4,384 KB
testcase_24 AC 171 ms
4,660 KB
testcase_25 AC 6 ms
4,384 KB
testcase_26 AC 132 ms
4,508 KB
testcase_27 AC 170 ms
4,800 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 57 ms
5,472 KB
testcase_31 AC 57 ms
5,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    map<char,vector<int>>mp;
    mp['U'],mp['F'],mp['W'],mp['P'];
    for(int i = 0; i < N; i++) {
        char S;
        int A;
        cin >> S >> A;
        mp[S].push_back(A);
    }
    long long ans = 1;
    for(auto i:mp) {
        if(i.first == 'P') {
            for(int j:i.second) {
                ans = 1ll*ans*modpow(N-1,j)%mod;
            } 
            ans = 1ll*ans*i.second.size()%mod;
        }
        else {
            long long tmp = 1;
            for(int j:i.second) {
                tmp = 1ll*tmp*modpow(N-1,j)%mod;
            }
            int sum = 0;
            for(int j:i.second) {
                sum += tmp*modpow(modpow(N-1,j),mod-2)%mod*(modpow(N-1,j)+mod-modpow(N-2,j))%mod;
                if(sum >= mod) sum -= mod;
            }
            ans = 1ll*ans*sum%mod;
        }
    }
    cout << ans << "\n";
}
0