結果
| 問題 | No.3169 [Cherry 7th Tune] Desire for Approval |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-10 19:39:37 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 3,081 ms / 7,000 ms |
| コード長 | 18,452 bytes |
| 記録 | |
| コンパイル時間 | 3,386 ms |
| コンパイル使用メモリ | 238,172 KB |
| 実行使用メモリ | 35,840 KB |
| 最終ジャッジ日時 | 2026-01-10 19:40:48 |
| 合計ジャッジ時間 | 66,008 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
ソースコード
// BEGIN: main.cpp
#line 1 "main.cpp"
#include<bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())
using ll=long long;
using u32=unsigned int;
using u64=unsigned long long;
using i128=__int128;
using u128=unsigned __int128;
using f128=__float128;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<typename T> using vc=vector<T>;
template<typename T> using vvc=vc<vc<T>>;
template<typename T> using vvvc=vc<vvc<T>>;
using vi=vc<int>;
using vll=vc<ll>;
using vvi=vc<vi>;
using vvll=vc<vll>;
#define vv(type,name,n,...) \
vector<vector<type>> name(n,vector<type>(__VA_ARGS__))
#define vvv(type,name,n,m,...) \
vector<vector<vector<type>>> name(n,vector<vector<type>>(m,vector<type>(__VA_ARGS__)))
template<typename T> using min_heap=priority_queue<T,vector<T>,greater<T>>;
template<typename T> using max_heap=priority_queue<T>;
// https://trap.jp/post/1224/
#define rep1(n) for(ll i=0; i<(ll)(n); ++i)
#define rep2(i,n) for(ll i=0; i<(ll)(n); ++i)
#define rep3(i,a,b) for(ll i=(ll)(a); i<(ll)(b); ++i)
#define rep4(i,a,b,c) for(ll i=(ll)(a); i<(ll)(b); i+=(c))
#define cut4(a,b,c,d,e,...) e
#define rep(...) cut4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define per1(n) for(ll i=((ll)n)-1; i>=0; --i)
#define per2(i,n) for(ll i=((ll)n)-1; i>=0; --i)
#define per3(i,a,b) for(ll i=((ll)a)-1; i>=(ll)(b); --i)
#define per4(i,a,b,c) for(ll i=((ll)a)-1; i>=(ll)(b); i-=(c))
#define per(...) cut4(__VA_ARGS__,per4,per3,per2,per1)(__VA_ARGS__)
#define rep_subset(i,s) for(ll i=(s); i>=0; i=(i==0?-1:(i-1)&(s)))
template<typename T, typename S> constexpr T ifloor(const T a, const S b){return a/b-(a%b&&(a^b)<0);}
template<typename T, typename S> constexpr T iceil(const T a, const S b){return ifloor(a+b-1,b);}
template<typename T>
void sort_unique(vector<T> &vec){
sort(vec.begin(),vec.end());
vec.resize(unique(vec.begin(),vec.end())-vec.begin());
}
template<typename T, typename S> constexpr bool chmin(T &a, const S b){if(a>b) return a=b,true; return false;}
template<typename T, typename S> constexpr bool chmax(T &a, const S b){if(a<b) return a=b,true; return false;}
template<typename T, typename S> istream& operator >> (istream& i, pair<T,S> &p){return i >> p.first >> p.second;}
template<typename T, typename S> ostream& operator << (ostream& o, const pair<T,S> &p){return o << p.first << ' ' << p.second;}
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(unordered_set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 777771449
#endif
template<typename T> void print(vector<T> x){for(auto i: x) cout << i << ' ';cout << "\n";}
template<typename T> void print(set<T> x){for(auto i: x) cout << i << ' ';cout << "\n";}
template<typename T> void print(unordered_set<T> x){for(auto i: x) cout << i << ' ';cout << "\n";}
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}
template<typename T> istream& operator >> (istream& i, vector<T> &vec){for(auto &x: vec) i >> x; return i;}
vvi read_graph(int n, int m, int base=1){
vvi adj(n);
for(int i=0,u,v; i<m; ++i){
cin >> u >> v,u-=base,v-=base;
adj[u].pb(v),adj[v].pb(u);
}
return adj;
}
vvi read_tree(int n, int base=1){return read_graph(n,n-1,base);}
template<typename T, typename S> pair<T,S> operator + (const pair<T,S> &a, const pair<T,S> &b){return {a.first+b.first,a.second+b.second};}
template<typename T> constexpr T inf=0;
template<> constexpr int inf<int> = 0x3f3f3f3f;
template<> constexpr ll inf<ll> = 0x3f3f3f3f3f3f3f3f;
template<typename T> vector<T> operator += (vector<T> &a, int val){for(auto &i: a) i+=val; return a;}
template<typename T> T isqrt(const T &x){T y=sqrt(x+2); while(y*y>x) y--; return y;}
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
//#include<atcoder/all>
//using namespace atcoder;
//using mint=modint998244353;
//using mint=modint1000000007;
// BEGIN: library/mod/modint.hpp
#line 1 "library/mod/modint.hpp"
// BEGIN: library/nt/extgcd.hpp
#line 1 "library/nt/extgcd.hpp"
// ax + by = gcd(a,b), {gcd(a,b),x,y}
template<typename T>
array<T,3> extgcd(T a, T b){
T x1=1,y1=0,x2=0,y2=1;
while(b!=0){
T q=a/b;
a%=b;
swap(a,b);
T x3=x1-x2*q,y3=y1-y2*q;
x1=x2,y1=y2,x2=x3,y2=y3;
}
return {a,x1,y1};
}
template<typename T>
T modinv(T x, T m){
auto [g,val1,val2]=extgcd<T>(x,m);
assert(g==1);
if(val1<0) val1+=m;
return val1;
}// END: library/nt/extgcd.hpp
#line 4 "library/mod/modint.hpp"
template<int64_t m, bool is_prime, typename word, typename dword>
struct Modint{
using mint=Modint;
static word get_mod(){
return m;
}
word x;
Modint():x(0){}
Modint(int64_t _x):x((_x%m+m)%m){}
mint operator += (const mint &o){
x+=o.x;
if(x>=m) x-=m;
return *this;
}
mint operator -= (const mint &o){
x-=o.x;
if(x<0) x+=m;
return *this;
}
mint operator *= (const mint &o){
x=((dword)x)*o.x%m;
return *this;
}
mint operator /= (const mint &o){
return (*this)*=o.inv();
}
mint operator + (const mint &o) const {return mint(*this)+=o;}
mint operator - (const mint &o) const {return mint(*this)-=o;}
mint operator * (const mint &o) const {return mint(*this)*=o;}
mint operator / (const mint &o) const {return mint(*this)/=o;}
mint operator - () const {return mint(0)-*this;}
mint pow(int64_t n) const {
assert(n>=0);
mint res=1,b=*this;
for(; n; n>>=1,b*=b) if(n&1) res*=b;
return res;
}
inline mint inv1() const {
return pow(m-2);
}
inline mint inv2() const {
auto [g,val1,val2]=extgcd<word>(x,m);
assert(g==1);
return mint(val1);
}
mint inv() const {
if(is_prime) return inv1();
return inv2();
}
bool operator == (const mint &o) const {
return x==o.x;
}
bool operator != (const mint &o) const {
return x!=o.x;
}
friend istream& operator >> (istream& is, mint &b){
int64_t y;
is >> y;
b=mint(y);
return is;
}
friend ostream& operator << (ostream& os, const mint &b){
return os << b.x;
}
// v2(m-1), 2^(v2(m-1))-th root
static constexpr pair<int,int> ntt_data(){
if(m==998244353) return {23,31};
return {-1,-1};
}
};
template<int64_t m, bool is_prime=true> using modint=Modint<m,is_prime,int32_t,int64_t>;
template<int64_t m, bool is_prime=true> using modint_64=Modint<m,is_prime,int64_t,__int128>;// END: library/mod/modint.hpp
#line 113 "main.cpp"
// BEGIN: library/mod/modint_basic.hpp
#line 1 "library/mod/modint_basic.hpp"
template<typename mint>
mint fac(int n){
static const int mod=mint::get_mod();
static vector<mint> res={1,1};
if(n>=mod) return 0;
assert(n>=0);
while(n>=(int)res.size()) res.push_back(res.back()*res.size());
return res[n];
}
template<typename mint>
mint inv(int n){
static const int mod=mint::get_mod();
static vector<mint> res={0,1};
assert(n>=0&&n<mod);
while(n>=(int)res.size()) res.push_back(res[mod%res.size()]*(mod-mod/res.size()));
return res[n];
}
template<typename mint>
mint ifac(int n){
static const int mod=mint::get_mod();
static vector<mint> res={1,1};
if(n>=mod) return 0;
assert(n>=0);
while(n>=(int)res.size()) res.push_back(res.back()*inv<mint>(res.size()));
return res[n];
}
template<typename mint>
mint C(int n, int m){
if(m<0||m>n) return 0;
return fac<mint>(n)*ifac<mint>(m)*ifac<mint>(n-m);
}
template<typename mint>
mint stars_and_bars(int n, int m){
if(n<0||m<0) return 0;
if(n==0){
if(m==0) return 1;
return 0;
}
return C<mint>(m+n-1,n-1);
}// END: library/mod/modint_basic.hpp
#line 114 "main.cpp"
using mint=modint<998244353>;
// BEGIN: library/poly/poly.hpp
#line 1 "library/poly/poly.hpp"
#line 4 "library/poly/poly.hpp"
// BEGIN: library/poly/convolution.hpp
#line 1 "library/poly/convolution.hpp"
// BEGIN: library/poly/ntt.hpp
#line 1 "library/poly/ntt.hpp"
template<typename mint>
struct NTT{
static constexpr int m=mint::get_mod(),N=mint::ntt_data().first,g=mint::ntt_data().second;
mint w[N+1];
NTT(){
w[N]=g;
for(int i=N-1; i>=0; --i) w[i]=w[i+1]*w[i+1];
}
void trans(vector<mint> &a, int k, bool inv=false){
for(int i=1,j=0; i<(1<<k); ++i){
for(int t=1<<(k-1); (j^=t)<t; t>>=1);
if(i<j) swap(a[i],a[j]);
}
for(int L=1,step=2; L<=k; ++L,step<<=1){
for(int i=0; i<(1<<k); i+=step){
mint cur(1),dw=w[L];
for(int j=i,j2=i+(step>>1); j<i+(step>>1); ++j,++j2,cur*=dw){
mint tmp=a[j2]*cur;
a[j2]=a[j]-tmp;
a[j]+=tmp;
}
}
}
if(inv){
reverse(a.begin()+1,a.end());
mint inv=mint(1<<k).inv();
for(int i=0; i<(1<<k); ++i) a[i]*=inv;
}
}
};// END: library/poly/ntt.hpp
#line 4 "library/poly/convolution.hpp"
template<typename mint>
vector<mint> convolution_naive(vector<mint> a, vector<mint> b){
if(a.empty()||b.empty()) return {};
int n=((int)a.size())+((int)b.size())-1;
vector<mint> res(n);
for(int i=0; i<((int)a.size()); ++i) for(int j=0; j<((int)b.size()); ++j){
res[i+j]+=a[i]*b[j];
}
return res;
}
template<typename mint>
vector<mint> convolution_ntt(vector<mint> a, vector<mint> b){
if(a.empty()||b.empty()) return {};
static NTT<mint> ntt;
int n=((int)a.size())+((int)b.size())-1;
int m=1,k=0;
while(m<n) m<<=1,k++;
a.resize(m),b.resize(m);
ntt.trans(a,k),ntt.trans(b,k);
for(int i=0; i<m; ++i) a[i]*=b[i];
ntt.trans(a,k,true);
a.resize(n);
return a;
}
template<typename mint>
vector<mint> convolution(vector<mint> a, vector<mint> b){
if(a.empty()||b.empty()) return {};
int n=((int)a.size())+((int)b.size())-1;
if(mint::ntt_data().first<0||n<49||min((int)a.size(),(int)b.size())<=5) return convolution_naive(a,b);
return convolution_ntt(a,b);
}// END: library/poly/convolution.hpp
#line 5 "library/poly/poly.hpp"
template<typename mint>
struct poly: vector<mint>{
using vector<mint>::vector;
poly(const vector<mint> &v):vector<mint>(v){}
poly operator += (const poly &o){
if(o.size()>this->size()) this->resize(o.size());
for(int i=0; i<(int)o.size(); ++i) (*this)[i]+=o[i];
return *this;
}
poly operator += (const mint &o){
if(this->empty()) this->resize(1);
(*this)[0]+=o;
return *this;
}
poly operator -= (const poly &o){
if(o.size()>this->size()) this->resize(o.size());
for(int i=0; i<(int)o.size(); ++i) (*this)[i]-=o[i];
return *this;
}
poly operator -= (const mint &o){
if(this->empty()) this->resize(1);
(*this)[0]-=o;
return *this;
}
poly operator *= (const poly &o){
return *this=convolution<mint>(*this,o);
}
poly operator *= (const mint &o){
for(int i=0; i<(int)this->size(); ++i) (*this)[i]*=o;
return *this;
}
poly operator + (const poly &o) const {return poly(*this)+=o;}
poly operator + (const mint &o) const {return poly(*this)+=o;}
poly operator - (const poly &o) const {return poly(*this)-=o;}
poly operator - (const mint &o) const {return poly(*this)-=o;}
poly operator * (const poly &o) const {return poly(*this)*=o;}
poly operator * (const mint &o) const {return poly(*this)*=o;}
poly operator - () const {return poly()-*this;}
poly interval(int l, int r){
assert(l<=r&&r<=(int)this->size());
poly res(this->begin()+l,this->begin()+r);
return res;
}
poly inverse(){
int n=this->size();
assert((*this)[0]!=0);
poly res(1,(*this)[0].inv());
poly b=*this;
for(int m=1; m<n; m<<=1){
if(n<m*2) b.resize(m*2);
poly v1=b.interval(0,m*2),v2=res;
v1*=v2;
v1.resize(m*2);
v1*=v2;
res.resize(m*2);
for(int i=0; i<m; ++i) res[i]+=res[i];
for(int i=0; i<m*2; ++i) res[i]-=v1[i];
}
res.resize(n);
return res;
}
poly derivative(){
int n=this->size();
poly res(n-1);
for(int i=0; i<n-1; ++i) res[i]=(*this)[i+1]*mint(i+1);
return res;
}
poly integral(){
int n=this->size();
poly res(n+1);
for(int i=0; i<n; ++i) res[i+1]=(*this)[i]*(inv<mint>(i+1));
return res;
}
poly ln(){
// a[0] = 1
int n=this->size();
if(n==1) return poly({0});
poly d=derivative();
poly b=*this;
b.pop_back();
poly res=d*b.inverse();
res.resize(n-1);
return res.integral();
}
poly exp(){
// a[0] = 0
int n=this->size();
poly q(1,1);
poly b=*this;
b[0]+=1;
for(int m=1; m<n; m<<=1){
if(n<m*2) b.resize(m*2);
poly g=b.interval(0,m*2),h=q;
h.resize(m*2),h=h.ln();
g-=h;
q*=g;
q.resize(m*2);
}
q.resize(n);
return q;
}
poly pow_naive(ll k){
int n=this->size();
poly b=*this,res={1};
for(; k; b*=b,k>>=1,b.resize(n)) if(k&1) res*=b,res.resize(n);
return res;
}
int low(){
int n=this->size(),m=0;
while(m<n&&(*this)[m]==0) m++;
if(m>=n) return -1;
return m;
}
poly shift(int n){
poly res(n,0);
res.insert(res.end(),this->begin(),this->end());
return res;
}
poly pow(ll k){ // 0^0 = 1
int n=this->size();
if(k==0){
poly res(n);
return res[0]=1,res;
}
int m=low();
if(m){
if(m==-1||k>=n||k*m>=n) return poly(n);
int lft=n-k*m;
poly b=interval(m,m+lft);
b=b.pow(k);
b=b.shift(k*m);
return b;
}
poly b=*this;
mint base=b[0].pow(k),inv=b[0].inv();
b*=inv;
b=b.ln();
if(b.empty()) b.pb(0);
b*=k;
b=b.exp();
b*=base;
return b;
}
poly pow_sparse(int k, int n){ // 0^0 = 1
if(k==0){
poly res(n);
return res[0]=1,res;
}
int t=this->size(),m=low();
if(m){
if(m==-1||k>=n||1ll*k*m>=n) return poly(n);
int lft=n-k*m;
poly b=interval(m,t);
b=b.pow_sparse(k,lft);
b=b.shift(k*m);
return b;
}
poly res(n,0);
res[0]=(*this)[0].pow(k);
mint inv_a0=(*this)[0].inv();
for(int i=1; i<n; ++i){
for(int j=1; j<t; ++j){
if(i-j>=0) res[i]-=res[i-j]*(i-j)*(*this)[j];
}
for(int j=1; j<t; ++j){
if(i-j>=0) res[i]+=res[i-j]*(*this)[j]*j*k;
}
res[i]*=inv_a0*inv<mint>(i);
}
return res;
}
friend ostream& operator << (ostream& os, const poly &P){
int n=P.size();
for(int i=0; i<n; ++i){
os << P[i];
if(i+1<n) os << ' ';
}
os << "\n";
return os;
}
};// END: library/poly/poly.hpp
#line 116 "main.cpp"
struct term{
mint k;
poly<mint> P;
term operator += (const term &o){
assert(k==o.k);
P+=o.P;
return *this;
}
term operator *= (const term &o){
k+=o.k;
P*=o.P;
return *this;
}
term operator + (const term &o){return term(*this)+=o;}
term operator * (const term &o){return term(*this)*=o;}
term derivative(){
term res=*this;
if(k==mint(0)){
res.P=res.P.derivative();
return res;
}
res.P=res.P*k+res.P.derivative();
return res;
}
term integral(){
term res=*this;
if(k==mint(0)){
res.P=res.P.integral();
return res;
}
per(i,sz(res.P)){
res.P[i]/=k;
if(i>0) res.P[i-1]-=res.P[i]*mint(i);
}
return res;
}
};
term one(){
term one;
one.k=0,one.P={1};
return one;
}
term one_times_x(){
term one;
one.k=0,one.P={0,1};
return one;
}
term get_pdf(int k, int a){
term tmp;
mint lambda=mint(a).inv();
tmp.k=-lambda;
tmp.P.resize(k);
tmp.P[k-1]=lambda.pow(k)*ifac<mint>(k-1);
return tmp;
}
term get_cdf_term(int k, int a){
mint lambda=mint(a).inv();
term tmp;
tmp.k=-lambda;
tmp.P.resize(k);
rep(k){
tmp.P[i]=lambda.pow(i)*ifac<mint>(i);
}
return tmp;
}
void mango(){
int n; cin >> n;
vi k(n),a(n);
rep(n) cin >> k[i] >> a[i];
vc<term> pdf(n),cdf_term(n);
rep(n){
pdf[i]=get_pdf(k[i],a[i]),cdf_term[i]=get_cdf_term(k[i],a[i]);
}
vc<term> precalc(1<<n);
precalc[0]=one();
rep(s,1,1<<n){
rep(n) if(s>>i&1){
precalc[s]=precalc[s-(1<<i)]*cdf_term[i];
break;
}
}
vc<mint> res(n);
rep(s,1,1<<n){
term cur=precalc[s];
cur=cur.derivative();
cur*=one_times_x();
cur=cur.integral();
if(cur.P.empty()) continue;
int m=__builtin_popcount(s)-1;
rep(j,m+1){
res[j]+=(-cur.P[0])*C<mint>(m,j)*((m-j)&1?mint(1):mint(-1));
}
}
rep(n){
cout << res[n-1-i] << ' ';
}
cout << "\n";
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cout << fixed << setprecision(20);
int t=1;
//cin >> t;
while(t--) mango();
}
// END: main.cpp