結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー matsup10matsup10
提出日時 2023-06-17 01:36:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 5,889 ms
コンパイル使用メモリ 319,892 KB
実行使用メモリ 8,500 KB
最終ジャッジ日時 2023-09-07 00:45:47
合計ジャッジ時間 12,503 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 179 ms
5,700 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 199 ms
5,644 KB
testcase_09 AC 204 ms
5,660 KB
testcase_10 AC 203 ms
5,640 KB
testcase_11 AC 203 ms
5,636 KB
testcase_12 AC 203 ms
5,692 KB
testcase_13 AC 202 ms
5,648 KB
testcase_14 AC 203 ms
5,704 KB
testcase_15 AC 102 ms
4,380 KB
testcase_16 AC 188 ms
5,796 KB
testcase_17 AC 191 ms
5,592 KB
testcase_18 AC 185 ms
5,724 KB
testcase_19 AC 104 ms
4,380 KB
testcase_20 AC 182 ms
5,704 KB
testcase_21 AC 151 ms
4,852 KB
testcase_22 AC 103 ms
4,460 KB
testcase_23 AC 74 ms
4,380 KB
testcase_24 AC 193 ms
6,112 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 147 ms
4,972 KB
testcase_27 AC 191 ms
5,640 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 110 ms
8,500 KB
testcase_31 AC 110 ms
7,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,a,b) for(int i=a;i<=int(b);i++)
#define ALL(x) x.begin(),x.end()
#define INF INT_MAX
#define INFL LLONG_MAX / 4
using namespace atcoder;
using mint = modint998244353;
template<typename T> void chmin(T& a, T b) { a = min(a, b); }
template<typename T> void chmax(T& a, T b) { a = max(a, b); }
#define PR(x) cerr << #x << "=" << x << endl
using i128 = __int128_t;

template<typename T>
T mod_pow(T x, long long n, const T &p = 998244353) {
  T ret = 1;
  x %= p;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret % p;
}

int main() {
  ll n;
  cin >> n;;
  vector<vector<ll>> as(4);
  ll a_all = 0;
  REP(i, n) {
    char c;
    ll a;
    cin >> c >> a;
    a_all += a;
    if(c=='U')as[0].push_back(a);
    if(c=='F')as[1].push_back(a);
    if(c=='W')as[2].push_back(a);
    if(c=='P')as[3].push_back(a);
  }
  mint ans = 1;
  
  REP(i, 3) {
    mint ta = 0;
    REP(j, as[i].size()) {
      mint x = (mod_pow(n-1, as[i][j]) - mod_pow(n-2, as[i][j]));
      x /= mod_pow(n-1, as[i][j]);
      ta += x;
    }
    ans *= ta;
  }

  ans *= as[3].size();
  ans *= mod_pow(n-1, a_all);

  cout << ans.val();
  return 0;
}
0