Submission #49547369
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << ": " << x << endl
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define rep(x,start,end) for(int x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int MOD=998244353;
ll qexp(ll b,ll p,int m){
ll res=1;
while (p){
if (p&1) res=(res*b)%m;
b=(b*b)%m;
p>>=1;
}
return res;
}
ll inv(ll i){
return qexp(i,MOD-2,MOD);
}
ll fix(ll i){
i%=MOD;
if (i<0) i+=MOD;
return i;
}
ll fac[1000005];
ll ifac[1000005];
ll nCk(int i,int j){
if (i<j) return 0;
return fac[i]*ifac[j]%MOD*ifac[i-j]%MOD;
}
int n,m;
int arr[5005];
int memo[2][5005];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
fac[0]=1;
rep(x,1,1000005) fac[x]=fac[x-1]*x%MOD;
ifac[1000004]=inv(fac[1000004]);
rep(x,1000005,1) ifac[x-1]=ifac[x]*x%MOD;
cin>>n>>m;
rep(x,1,n+1) cin>>arr[x];
int a=0,b=1;
memo[a][0]=1;
rep(x,1,n+1){
memset(memo[b],0,sizeof(memo[b]));
if (arr[x]==0){
rep(y,0,x){
memo[b][y]=(memo[b][y]+memo[a][y]*y)%MOD;
memo[b][y+1]=(memo[b][y+1]+memo[a][y]*(m-y))%MOD;
}
}
else{
rep(y,0,x){
memo[b][y+1]=memo[a][y];
}
}
swap(a,b);
}
int ans=0;
rep(x,0,min(n+1,m+2)) ans=(ans+memo[a][x])%MOD;
cout<<ans<<endl;
}
Submission Info
| Submission Time |
|
| Task |
C - Prefix Mex Sequence |
| User |
errorgorn |
| Language |
C++ 20 (gcc 12.2) |
| Score |
600 |
| Code Size |
1843 Byte |
| Status |
AC |
| Exec Time |
56 ms |
| Memory |
19344 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_01.txt |
AC |
14 ms |
19144 KiB |
| 00_sample_02.txt |
AC |
14 ms |
19088 KiB |
| 01_test_01.txt |
AC |
14 ms |
19060 KiB |
| 01_test_02.txt |
AC |
14 ms |
19136 KiB |
| 01_test_03.txt |
AC |
56 ms |
19192 KiB |
| 01_test_04.txt |
AC |
56 ms |
19272 KiB |
| 01_test_05.txt |
AC |
25 ms |
19344 KiB |
| 01_test_06.txt |
AC |
41 ms |
19204 KiB |
| 01_test_07.txt |
AC |
40 ms |
19216 KiB |
| 01_test_08.txt |
AC |
41 ms |
19216 KiB |
| 01_test_09.txt |
AC |
41 ms |
19220 KiB |
| 01_test_10.txt |
AC |
40 ms |
19216 KiB |
| 01_test_11.txt |
AC |
16 ms |
19172 KiB |
| 01_test_12.txt |
AC |
22 ms |
19168 KiB |
| 01_test_13.txt |
AC |
17 ms |
19176 KiB |
| 01_test_14.txt |
AC |
25 ms |
19120 KiB |
| 01_test_15.txt |
AC |
38 ms |
19212 KiB |
| 01_test_16.txt |
AC |
25 ms |
19192 KiB |
| 01_test_17.txt |
AC |
41 ms |
19212 KiB |
| 01_test_18.txt |
AC |
40 ms |
19204 KiB |
| 01_test_19.txt |
AC |
41 ms |
19268 KiB |
| 01_test_20.txt |
AC |
41 ms |
19220 KiB |
| 01_test_21.txt |
AC |
35 ms |
19152 KiB |
| 01_test_22.txt |
AC |
27 ms |
19268 KiB |
| 01_test_23.txt |
AC |
40 ms |
19272 KiB |
| 01_test_24.txt |
AC |
26 ms |
19208 KiB |
| 01_test_25.txt |
AC |
37 ms |
19184 KiB |