結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー lgswdnlgswdn
提出日時 2023-06-16 22:09:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 1,944 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 202,836 KB
実行使用メモリ 13,516 KB
最終ジャッジ日時 2023-09-06 20:07:31
合計ジャッジ時間 6,139 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,560 KB
testcase_01 AC 1 ms
5,592 KB
testcase_02 AC 2 ms
5,576 KB
testcase_03 AC 1 ms
5,536 KB
testcase_04 AC 109 ms
10,404 KB
testcase_05 AC 2 ms
5,780 KB
testcase_06 AC 1 ms
5,580 KB
testcase_07 AC 2 ms
5,664 KB
testcase_08 AC 119 ms
10,268 KB
testcase_09 AC 139 ms
10,220 KB
testcase_10 AC 139 ms
10,216 KB
testcase_11 AC 140 ms
10,236 KB
testcase_12 AC 140 ms
10,388 KB
testcase_13 AC 138 ms
10,392 KB
testcase_14 AC 135 ms
10,276 KB
testcase_15 AC 68 ms
7,612 KB
testcase_16 AC 126 ms
9,992 KB
testcase_17 AC 139 ms
9,992 KB
testcase_18 AC 129 ms
10,236 KB
testcase_19 AC 67 ms
7,760 KB
testcase_20 AC 121 ms
10,000 KB
testcase_21 AC 101 ms
8,664 KB
testcase_22 AC 67 ms
7,712 KB
testcase_23 AC 51 ms
6,856 KB
testcase_24 AC 135 ms
10,032 KB
testcase_25 AC 5 ms
5,748 KB
testcase_26 AC 99 ms
8,664 KB
testcase_27 AC 128 ms
10,024 KB
testcase_28 AC 2 ms
5,528 KB
testcase_29 AC 2 ms
5,580 KB
testcase_30 AC 63 ms
13,516 KB
testcase_31 AC 60 ms
11,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=3e5+5,mod=998244353;
int n,s[N],a[N],ans;
char t[2];
vi f[4];

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

int ksm(int x,int y,int r=1) {
  for(;y;y>>=1,x=x*x%mod) if(y&1) r=r*x%mod;
  return r;
}

signed main() {
  n=read(); ans=1;
  rep(i,1,n) {
    scanf("%s%lld",t,&a[i]);
    s[i]=convert(t[0]);
    f[s[i]].eb(a[i]);
  }
  ans=f[3].size();
  for(int a:f[3]) ans=ans*ksm(n-1,a)%mod;
  rep(i,0,2) {
    int res=0;
    for(int a:f[i]) {
      int w=ksm(n-2,a)*ksm(ksm(n-1,a),mod-2)%mod;
      res=(res+1+mod-w)%mod;
    }
    for(int a:f[i]) res=res*ksm(n-1,a)%mod;
    ans=ans*res%mod;
  }
  printf("%lld\n",ans);
  return 0;
}
0