結果
| 問題 |
No.2633 Subsequence Combination Score
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2024-02-11 13:42:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,527 bytes |
| コンパイル時間 | 1,969 ms |
| コンパイル使用メモリ | 196,224 KB |
| 最終ジャッジ日時 | 2025-02-19 05:03:24 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 RE * 34 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
struct mint{
static constexpr int m = 998244353;
int x;
mint() : x(0){}
mint(ll x_):x(x_%m){if(x<0)x+=m;}
mint &operator+=(mint b){if((x+=b.x)>=m)x-=m; return *this;}
mint &operator-=(mint b){if((x-=b.x)<0)x+=m; return *this;}
mint &operator*=(mint b){x=ll(x)*b.x%m; return *this;}
mint pow(ll e) const {
mint r = 1,b =*this;
while(e){
if(e&1) r*=b;
b*=b;
e>>=1;
}
return r;
}
mint inv(){return pow(m-2);}
mint &operator/=(mint b){return *this*=b.pow(m-2);}
friend mint operator+(mint a,mint b){return a+=b;}
friend mint operator-(mint a,mint b){return a-=b;}
friend mint operator/(mint a,mint b){return a/=b;}
friend mint operator*(mint a,mint b){return a*=b;}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin>>N;
vector<ll> A(N);
rep(i,0,N) cin>>A[i];
int L=(1<<20);
vector<mint> fact(L,1),fact_inv(L,1);
rep(i,1,L) fact[i]=fact[i-1]*i;
fact_inv[L-1]=fact[L-1].inv();
for(int i=L-1;i>0;i--) fact_inv[i-1]=fact_inv[i]*i;
auto comb=[&](ll a,ll b) -> mint {
if(a<0||a<b) return 0;
return fact[a]*fact_inv[b]*fact_inv[a-b];
};
assert(N<=20);
mint ans=0;
rep(i,1,1<<N){
mint tmp=1;
ll B=-1;
rep(j,0,N){
if(i&(1<<j)){
if(B!=-1){
tmp*=comb(B,A[j]);
}
B=A[j];
}
}
ans+=tmp;
}
cout<<ans.x<<"\n";
}
potato167