結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー lgswdn
提出日時 2023-06-16 22:09:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,944 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 196,388 KB
最終ジャッジ日時 2025-02-14 06:00:07
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:59:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |     scanf("%s%lld",t,&a[i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~

ソースコード

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