結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー eQe
提出日時 2025-09-09 23:03:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 588 ms / 2,000 ms
コード長 3,615 bytes
コンパイル時間 5,188 ms
コンパイル使用メモリ 319,660 KB
実行使用メモリ 45,304 KB
最終ジャッジ日時 2025-09-09 23:03:48
合計ジャッジ時間 21,788 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include<atcoder/modint>
#include<atcoder/lazysegtree>
#include<atcoder/convolution>
#endif
using namespace std;
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define binary_operator(op,type) auto operator op(const type&rhs)const{auto copy=*this;return copy op##=rhs;}
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
#define use_ml998244353 using ml=atcoder::modint998244353;
namespace my{
auto&operator<<(ostream&o,const atcoder::modint998244353&x){return o<<(int)x.val();}
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
template<class T>concept modulary=requires(T t){t.mod();};
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
void lin(auto&...a){(cin>>...>>a);}
auto cinen(const string&b){char c;lin(c);return b.find_first_of(c);}
auto min(auto...a){return min(initializer_list<common_type_t<decltype(a)...>>{a...});}
template<class A,class B=A>struct pair{
  A a;B b;
  pair()=default;
  pair(A aa,B bb):a(aa),b(bb){}
  auto operator<=>(const pair&)const=default;
};
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class T>struct core_t_helper{using type=T;};
template<class T>using core_t=core_t_helper<T>::type;
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
  using C=core_t<V>;
  using vector<V>::vector;
  vec(const vector<V>&v):vector<V>(v){}
  ll size()const{return vector<V>::size();}
  auto fold(const auto&f)const{
    pair<C,bool>r{};
    fe(*this,e){
      if constexpr(!vectorial<V>){
        if(r.b)f(r.a,e);
        else r={e,1};
      }else { }

    }
    return r;
  }
  auto sum()const{return fold([](auto&a,const auto&b){a+=b;}).a;}
  auto max()const{return fold([](auto&a,auto b){if(a<b)a=b;}).a;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
namespace my{
template<class T>struct formal_power_series:vec<T>{
  using vec<T>::vec;
  using fps=formal_power_series;
  static fps mul(const fps&a,const fps&b){
    if constexpr(!modulary<T>){ }
    else if constexpr(is_same_v<T,atcoder::modint998244353>)return atcoder::convolution(a,b);
    else { }
  }
  fps&operator*=(const fps&g){return*this=(this->size()&&g.size()?mul(*this,g):fps{});}
  binary_operator(*,fps)
};
template<class T>using fps=formal_power_series<T>;
}
namespace my{entry
void main(){
  LL(N);
  vec<ll>s(N),a(N);
  fo(i,N){
    s[i]=cinen("UFWP");
    lin(a[i]);
  }

  use_ml998244353
  ll su=a.sum();
  ll M=min(su,a.max()*4)+1;
  vec<fps<ml>>f(4,fps<ml>(M));
  fo(i,N){
    if(s[i]<3){
      f[s[i]][a[i]]+=ml(N-1).pow(a[i])-ml(N-2).pow(a[i]);
    }else{
      f[s[i]][a[i]]+=ml(N-1).pow(a[i]);
    }
  }

  auto g=f[0]*f[1]*f[2]*f[3];

  ml ans=0;
  fo(i,M)ans+=g[i]*ml(N-1).pow(su-i);
  pp(ans);
}}
0