結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2023-06-16 22:12:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 3,049 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 203,248 KB
実行使用メモリ 5,340 KB
最終ジャッジ日時 2023-09-06 20:10:48
合計ジャッジ時間 7,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 170 ms
5,084 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 182 ms
4,628 KB
testcase_09 AC 195 ms
4,808 KB
testcase_10 AC 196 ms
4,576 KB
testcase_11 AC 194 ms
4,976 KB
testcase_12 AC 195 ms
4,848 KB
testcase_13 AC 194 ms
4,576 KB
testcase_14 AC 195 ms
4,804 KB
testcase_15 AC 98 ms
4,376 KB
testcase_16 AC 178 ms
4,704 KB
testcase_17 AC 184 ms
4,508 KB
testcase_18 AC 177 ms
4,832 KB
testcase_19 AC 100 ms
4,384 KB
testcase_20 AC 177 ms
4,740 KB
testcase_21 AC 143 ms
4,428 KB
testcase_22 AC 99 ms
4,380 KB
testcase_23 AC 71 ms
4,380 KB
testcase_24 AC 185 ms
4,580 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 143 ms
4,376 KB
testcase_27 AC 184 ms
4,608 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 110 ms
5,336 KB
testcase_31 AC 109 ms
5,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
const string seasons = "UFWP";
const long long MD = 998244353;
template<long long MOD=MD> struct mdint {
    int d=0;
    mdint () {d=0;}
    mdint (long long _d) : d(_d%MOD){
        if(d<0) d+=MOD;
    };
    friend mdint& operator+=(mdint& a, const mdint& o) {
        a.d+=o.d; if(a.d>=MOD) a.d-=MOD;
        return a;
    }
    friend mdint& operator-=(mdint& a, const mdint& o) {
        a.d-=o.d; if(a.d<0) a.d+=MOD;
        return a;
    }
    friend mdint& operator*=(mdint& a, const mdint& o) {
        return a = mdint((ll)a.d*o.d);
    }
    mdint operator*(const mdint& o) const {
        mdint res = *this;
        res*=o;
        return res;
    }
    mdint operator+(const mdint& o) const {
        mdint res = *this;
        res+=o;
        return res;
    }
    mdint operator-(const mdint& o) const {
        mdint res = *this;
        res-=o;
        return res;
    }
    mdint operator^(long long b) const {
        mdint tmp = 1;
        mdint power = *this;
        while(b) {
            if(b&1) {
                tmp = tmp*power;
            }
            power = power*power;
            b/=2;
        }
        return tmp;
    }
    friend mdint operator/=(mdint& a, const mdint& o) {
        a *= (o^(MOD-2));
        return a;
    }
    mdint operator/(const mdint& o) {
        mdint res = *this;
        res/=o;
        return res;
    }
    bool operator==(const mdint& o) { return d==o.d;}
    bool operator!=(const mdint& o) { return d!=o.d;}
    friend istream& operator>>(istream& c, mdint& a) {return c >> a.d;}
    friend ostream& operator<<(ostream& c, const mdint& a) {return c << a.d;}
};
using  mint = mdint<MD>;
int main() {
    int n; cin >> n;
    if(n<=3) {
        cout << "0\n";
        exit(0);
    }
    vi a[4] = {};
    for(int i=0;i<n;++i) {
        char c; cin >> c;
        int b; cin >> b;
        a[seasons.find(c)].push_back(b);
    }
    // voor elk van die dingen:
    // boeit niet waar je vandaan kwam.
    mint res=1;
    for(int i=0;i<4;++i) {
        auto v= a[i];
        ll sm=accumulate(all(v),0LL);
        if(i==3) {
            res*=(mint(n-1)^(sm))*v.size();
            break;
        }
        mint cur=0;
        for(auto x : v) {
            mint good = (mint(n-1)^x) - (mint(n-2)^x);
            cur+= (mint(n-1)^(sm-x))*good;

        }
        res*=cur;
    }
    cout << res << '\n';
}
0