結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー kumakumakumakuma
提出日時 2023-05-14 05:18:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,762 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 210,980 KB
実行使用メモリ 11,420 KB
最終ジャッジ日時 2023-08-19 22:42:17
合計ジャッジ時間 8,170 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const double PI = 3.141592653589793238462643383279;

//UFWPの表記に違和感がある
//それ以降は訪れた街にある扉のうちどれか一つを用いて->今要る街
//扉の行先の組合せは全部で (N−1) A all通りあります->ほんと?
//扉の行き先を決められる事が明記されてなくて読みづらい
//扉1と扉2は区別するのか

ll mod = 998244353;
map<pll, ll> mp;
//=============modpow============================
ll modpow(ll a, ll n)
{
    if (mp.find({a, n}) != mp.end()) {
      return mp[{a, n}];
    }
    ll res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    mp[{a, n}] = res;
    return res;
}
//=================================================

//=============modinv============================
ll modinv(ll a, ll m = mod) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//=================================================


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<vector<ll>> num(4);
  ll N;
  cin >> N;
  ll sum = 0;
  for (ll i = 0; i < N; ++i) {
    char S;
    ll A;
    cin >> S >> A;
    sum += A;
    if (S == 'U') {
      num.at(0).push_back(A);
    }
    else if (S == 'F') {
      num.at(1).push_back(A);
    }
    else if (S == 'W') {
      num.at(2).push_back(A);
    }
    else {
      num.at(3).push_back(A);
    }
  }
  ll ans = 0;
  ll all = modpow(N - 1, sum);
  for (ll i = 0; i < num.at(0).size(); ++i) {
    ll a = (modinv(modpow(N - 1, num.at(0).at(i))) % mod) * (modpow(N - 1, num.at(0).at(i)) - modpow(N - 2, num.at(0).at(i)) + mod) % mod;
    for (ll j = 0; j < num.at(1).size(); ++j) {
      ll b = (modinv(modpow(N - 1, num.at(1).at(j))) % mod) * (modpow(N - 1, num.at(1).at(j)) - modpow(N - 2, num.at(1).at(j)) + mod) % mod;
      for (ll k = 0; k < num.at(2).size(); ++k) {
        ll c = (modinv(modpow(N - 1, num.at(2).at(k))) % mod) * (modpow(N - 1, num.at(2).at(k)) - modpow(N - 2, num.at(2).at(k)) + mod) % mod;
        ans += (((all * a % mod) * b % mod) * c  % mod) * (ll)num.at(3).size() % mod;
        ans %= mod;
      }
    }
  }
  cout << ans << "\n";
}
0