結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー SSRS
提出日時 2023-06-16 22:04:06
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 174,688 KB
実行使用メモリ 7,048 KB
最終ジャッジ日時 2024-06-24 14:18:30
合計ジャッジ時間 6,848 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
string s = "UFWP";
long long modpow(long long a, long long b){
  long long ans = 1;
  while (b > 0){
    if (b % 2 == 1){
      ans *= a;
      ans %= MOD;
    }
    a *= a;
    a %= MOD;
    b /= 2;
  }
  return ans;
}
int main(){
  int N;
  cin >> N;
  vector<char> S(N);
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> S[i] >> A[i];
  }
  vector<vector<int>> B(4);
  for (int i = 0; i < N; i++){
    int p = find(s.begin(), s.end(), S[i]) - s.begin();\
    B[p].push_back(A[i]);
  }
  long long ans = 1;
  for (int i = 0; i < 3; i++){
    int M = B[i].size();
    long long C = 0;
    for (int j = 0; j < M; j++){
      C += B[i][j];
    }
    long long mul = 0;
    for (int j = 0; j < M; j++){
      mul += modpow(N - 1, C - B[i][j]) * (modpow(N - 1, B[i][j]) - modpow(N - 2, B[i][j]) + MOD) % MOD;
      mul %= MOD;
    }
    ans *= mul;
    ans %= MOD;
  }
  int M = B[3].size();
  long long C = 0;
  for (int i = 0; i < M; i++){
    C += B[3][i];
  }
  ans *= modpow(N - 1, C);
  ans %= MOD;
  ans *= M;
  ans %= MOD;
  cout << ans << endl;
}
0