結果

問題 No.1897 Sum of 2nd Max
コンテスト
ユーザー eQe
提出日時 2025-11-24 22:55:27
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 2,829 bytes
コンパイル時間 3,511 ms
コンパイル使用メモリ 286,444 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-24 22:55:34
合計ジャッジ時間 5,713 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include<atcoder/modint>
#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 of(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(1,__VA_ARGS__);i>=i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#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};}
template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};}
void lin(auto&...a){(cin>>...>>a);}
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 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 vector<V>::vector;
  ll size()const{return vector<V>::size();}
  vec mobius()const{vec v=*this;if constexpr(vectorial<V>){ }of(i,v.size()-1)v[i+1]-=v[i];return v;}
};
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>T fac(ll n){static vec<T>v{1};if(ll m=v.size();m<=n){v.resize(n+1);fo(i,m,n+1)v[i]=v[i-1]*i;}return v[n];}
template<class T>T fac_inv(ll n){static vec<T>v{1};if(ll m=v.size();m<=n){v.resize(n+1);v[n]=fac<T>(n).inv();of(i,n,m)v[i]=v[i+1]*(i+1);}return v[n];}
template<class T>T comb(ll n,ll k){
  if(n<0||k<0||n<k)return 0;
  if constexpr(modulary<T>)return fac<T>(n)*fac_inv<T>(k)*fac_inv<T>(n-k);
  else { }
}
}
namespace my{entry
void main(){
  LL(N,M);
  use_ml998244353

  // 2番目に大きい数=N-1番目に小さい数
  vec cnt(M+1,ml{});
  fo(i,1,M+1){ // N-1番目に小さい数がi以下であるものの個数.
    fo(t,N-1,N+1){
      cnt[i]+=comb<ml>(N,t)*ml(i).pow(t)*ml(M-i).pow(N-t);
    }
  }
  cnt=cnt.mobius();

  ml ans=0;
  fo(i,1,M+1)ans+=i*cnt[i];
  pp(ans);
}}
0