結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー Ricky_ponRicky_pon
提出日時 2023-06-17 01:58:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 4,041 bytes
コンパイル時間 1,686 ms
コンパイル使用メモリ 139,068 KB
実行使用メモリ 5,120 KB
最終ジャッジ日時 2023-09-07 01:03:11
合計ジャッジ時間 6,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 150 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 165 ms
4,420 KB
testcase_09 AC 173 ms
4,696 KB
testcase_10 AC 172 ms
4,376 KB
testcase_11 AC 173 ms
4,412 KB
testcase_12 AC 173 ms
4,380 KB
testcase_13 AC 173 ms
4,380 KB
testcase_14 AC 172 ms
4,472 KB
testcase_15 AC 86 ms
4,376 KB
testcase_16 AC 160 ms
4,408 KB
testcase_17 AC 165 ms
4,440 KB
testcase_18 AC 158 ms
4,680 KB
testcase_19 AC 88 ms
4,376 KB
testcase_20 AC 153 ms
4,608 KB
testcase_21 AC 125 ms
4,380 KB
testcase_22 AC 88 ms
4,380 KB
testcase_23 AC 63 ms
4,376 KB
testcase_24 AC 164 ms
4,376 KB
testcase_25 AC 6 ms
4,376 KB
testcase_26 AC 126 ms
4,380 KB
testcase_27 AC 164 ms
4,508 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 107 ms
5,116 KB
testcase_31 AC 106 ms
5,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <ciso646>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME
#define REP3(i, l, r, s)                                               \
    for (int i = int(l), rep3_r = int(r), rep3_s = int(s); i < rep3_r; \
         i += rep3_s)
#define REP2(i, l, r) REP3(i, l, r, 1)
#define REP1(i, n) REP2(i, 0, n)
#define rep(...) REP_OVERLOAD(__VA_ARGS__, REP3, REP2, REP1, )(__VA_ARGS__)
#define repin(i, l, r) for (int i = int(l), repin_r = int(r); i <= repin_r; ++i)

#define RREP_OVERLOAD(arg1, arg2, arg3, arg4, NAME, ...) NAME
#define RREP3(i, l, r, s)                                                      \
    for (int i = int(r) - 1, rrep3_l = int(l), rrep3_s = int(s); i >= rrep3_l; \
         i -= rrep3_s)
#define RREP2(i, l, r) RREP3(i, l, r, 1)
#define RREP1(i, n) RREP2(i, 0, n)
#define rrep(...) RREP_OVERLOAD(__VA_ARGS__, RREP3, RREP2, RREP1, )(__VA_ARGS__)
#define rrepin(i, l, r) \
    for (int i = int(r), rrepin_l = int(l); i >= rrepin_l; --i)

#include <atcoder/modint>

#include <algorithm>
#include <cassert>
#include <vector>

namespace rklib {

// a <- max(a, b)
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// a <- min(a, b)
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

// if a < 0: a <- b
// else: a <- min(a, b)
template <class T>
bool chmin_non_negative(T &a, const T &b) {
    if (a < 0 || a > b) {
        a = b;
        return true;
    }
    return false;
}

// floor(num / den)
template <class T>
T div_floor(T num, T den) {
    if (den < 0) num = -num, den = -den;
    return num >= 0 ? num / den : (num + 1) / den - 1;
}

// ceil(num / den)
template <class T>
T div_ceil(T num, T den) {
    if (den < 0) num = -num, den = -den;
    return num <= 0 ? num / den : (num - 1) / den + 1;
}

namespace internal {

template <class T>
T remainder_count(T r, T b, T m) {
    return r / m * b + std::min(b, r % m);
}

}  // namespace internal

// Number of integer x s.t.
// - x in [l, r)
// - x mod m in [a, b)
template <class T>
T remainder_count(T l, T r, T a, T b, T m) {
    assert(l >= 0);
    assert(m >= 1);

    if (l >= r || a >= b) return 0;
    if (m <= a || b < 0) return 0;
    chmax(a, T(0));
    chmin(b, m);

    auto res = internal::remainder_count(r, b, m);
    if (l >= 1) res -= internal::remainder_count(l, b, m);
    if (a >= 1) res -= internal::remainder_count(r, a, m);
    if (l >= 1 && a >= 1) res += internal::remainder_count(l, a, m);

    return res;
}

}  // namespace rklib


using namespace std;
using namespace rklib;

using lint = long long;
using pii = pair<int, int>;
using pll = pair<lint, lint>;

using mint = atcoder::modint998244353;

int char_to_int(char c) {
    if (c == 'U')
        return 0;
    else if (c == 'F')
        return 1;
    else if (c == 'W')
        return 2;
    else
        return 3;
}

int main() {
    int n;
    cin >> n;
    vector<int> num(4, 0);
    vector<lint> sum(4, 0);
    vector<int> vs[4];
    rep(i, n) {
        char c;
        int a;
        cin >> c >> a;

        auto k = char_to_int(c);
        ++num[k];
        sum[k] += a;
        vs[k].push_back(a);
    }

    mint ans = mint(n - 1).pow(sum[3]) * num[3];
    rep(i, 3) {
        mint tmp = 0;

        for (auto a : vs[i]) {
            tmp += mint(n - 1).pow(sum[i] - a) *
                   (mint(n - 1).pow(a) - mint(n - 2).pow(a));
        }

        ans *= tmp;
    }
    cout << ans.val() << "\n";
}
0