Submission #4019243
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
const int MAX_COMB = 5000;
const LL mod = 998244353;
LL fct[MAX_COMB+1];
LL invfct[MAX_COMB+1];
void build(){
fct[0] = fct[1] = 1;
repp(i,2,MAX_COMB+1){
fct[i] = fct[i-1] * i % mod;
}
LL x = fct[MAX_COMB];
invfct[MAX_COMB] = 1;
for(int i = mod - 2 ; i > 0 ; i >>= 1){
if(i % 2 == 1) (invfct[MAX_COMB] *= x) %= mod;
(x *= x) %= mod;
}
repm(i,MAX_COMB,0){
invfct[i-1] = invfct[i] * i % mod;
}
}
LL comb(int x , int y){
if(x < 0 || y < 0 || x < y) return 0;
return fct[x] * invfct[y] % mod * invfct[x-y] % mod;
}
int main(){
build();
int K,N; cin >> K >> N;
vector<LL> ans(2*K+1,0);
vector<LL> dp(N+1,0);
dp[0] = 1;
repp(i,2,K+2){
if(i&1){
vector<LL> nx(N+1,0);
LL s = 0;
repp(j,0,N+1){
nx[j] = (s+dp[j])%mod;
s = (s+2*dp[j])%mod;
}
swap(dp,nx);
repp(j,0,N+1) (ans[i] += dp[j]*comb(N-j+K-i,N-j)) %= mod;
if(i == K+1) ans[i] = dp[N];
} else {
repp(j,0,N) (ans[i] += dp[j]*(comb(N-j+K-i,N-j)+comb(N-j+K-i-1,N-j-1))) %= mod;
(ans[i] += dp[N]) %= mod;
if(i == K+1) ans[i] = (dp[N-1]+dp[N])%mod;
}
ans[2*K+2-i] = ans[i];
}
repp(i,2,2*K+1) cout << ans[i] << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Stop. Otherwise... |
User |
PIandS |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
1406 Byte |
Status |
AC |
Exec Time |
57 ms |
Memory |
384 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
s1.txt, s2.txt, s3.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, s1.txt, s2.txt, s3.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
AC |
57 ms |
384 KB |
02.txt |
AC |
51 ms |
384 KB |
03.txt |
AC |
36 ms |
384 KB |
04.txt |
AC |
1 ms |
384 KB |
05.txt |
AC |
8 ms |
384 KB |
06.txt |
AC |
41 ms |
384 KB |
07.txt |
AC |
56 ms |
384 KB |
08.txt |
AC |
20 ms |
384 KB |
09.txt |
AC |
1 ms |
384 KB |
10.txt |
AC |
6 ms |
384 KB |
11.txt |
AC |
8 ms |
384 KB |
12.txt |
AC |
1 ms |
384 KB |
13.txt |
AC |
6 ms |
384 KB |
14.txt |
AC |
37 ms |
384 KB |
15.txt |
AC |
44 ms |
384 KB |
16.txt |
AC |
45 ms |
384 KB |
17.txt |
AC |
1 ms |
384 KB |
18.txt |
AC |
1 ms |
256 KB |
19.txt |
AC |
1 ms |
384 KB |
20.txt |
AC |
1 ms |
256 KB |
s1.txt |
AC |
1 ms |
256 KB |
s2.txt |
AC |
1 ms |
384 KB |
s3.txt |
AC |
2 ms |
384 KB |