Submission #1862659
Source Code Expand
#include <cstdio>
#include <cstring>
#define MAXN 2010
#define LL long long
const LL P=924844033;
struct Poly{
LL a[MAXN];
int len;
}g[MAXN][2],res;
int n,k;
LL fac[MAXN];
void add(Poly &x,Poly &y){
if(x.len>y.len) y.len=x.len;
for(int i=0;i<=x.len;i++) y.a[i]=(y.a[i]+x.a[i])%P;
}
void add2(Poly &x,Poly &y){
if(x.len+1>y.len) y.len=x.len+1;
for(int i=0;i<=x.len;i++) y.a[i+1]=(y.a[i+1]+x.a[i])%P;
}
void mul(Poly &x,Poly &y){
static LL temp[MAXN];
for(int i=0;i<=x.len+y.len;i++) temp[i]=0;
for(int i=0;i<=x.len;i++)
for(int j=0;j<=y.len;j++)
temp[i+j]=(temp[i+j]+x.a[i]*y.a[j])%P;
y.len+=x.len;
for(int i=0;i<=y.len;i++)
y.a[i]=temp[i];
}
void gao(int x){
int p1=x,p2=x+(n-x)/(2*k)*(2*k);
bool flag1=(p1-k>=1),flag2=(p2+k<=n);
g[p2][1].len=1;
g[p2][1].a[1]=1;
if(flag2){
g[p2][0].len=1;
g[p2][0].a[0]=g[p2][0].a[1]=1;
}else{
g[p2][0].len=0;
g[p2][0].a[0]=1;
}
for(int i=p2-2*k;i>=p1;i-=2*k){
int i2=i+2*k;
add(g[i2][0],g[i][0]);
add2(g[i2][0],g[i][0]);
add2(g[i2][0],g[i][1]);
add(g[i2][1],g[i][0]);
add2(g[i2][1],g[i][1]);
}
if(flag1) add(g[p1][1],g[p1][0]);
}
int main(){
#ifdef DEBUG
freopen("D.in","r",stdin);
#endif
fac[0]=1;
for(int i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%P;
scanf("%d%d",&n,&k);
res.a[0]=1;
for(int i=1;i<=2*k && i<=n;i++){
gao(i);
mul(g[i][0],res);
}
LL ans=0;
for(int i=0;i<=n;i++){
LL delta=(i&1)?(-1):1;
ans=(ans+delta*res.a[i]*fac[n-i])%P;
}
ans=(ans+P)%P;
printf("%lld\n",ans);
}
Submission Info
Submission Time
2017-12-10 22:38:03+0900
Task
D - ~K Perm Counting
User
ez_zjt
Language
C++14 (GCC 5.4.1)
Score
900
Code Size
1562 Byte
Status
AC
Exec Time
25 ms
Memory
61440 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:66:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&k);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
900 / 900
Status
Set Name
Test Cases
Sample
example0, example1, example2, example3, example4
All
example0, example1, example2, example3, example4, handmade0, handmade1, handmade2, handmade3, handmade4, handmade5, handmade6, maxrand0, maxrand1, maxrand2, maxrand3, maxrand4, rand0, rand1, rand2, rand3, rand4, small0, small1, small2, supersmall0, supersmall1, supersmall2
Case Name
Status
Exec Time
Memory
example0
AC
1 ms
256 KB
example1
AC
1 ms
256 KB
example2
AC
1 ms
256 KB
example3
AC
1 ms
256 KB
example4
AC
3 ms
12928 KB
handmade0
AC
1 ms
256 KB
handmade1
AC
25 ms
61440 KB
handmade2
AC
12 ms
60416 KB
handmade3
AC
23 ms
59008 KB
handmade4
AC
12 ms
57984 KB
handmade5
AC
17 ms
60544 KB
handmade6
AC
17 ms
60544 KB
maxrand0
AC
15 ms
60032 KB
maxrand1
AC
20 ms
60160 KB
maxrand2
AC
19 ms
60160 KB
maxrand3
AC
17 ms
60160 KB
maxrand4
AC
13 ms
60032 KB
rand0
AC
20 ms
60416 KB
rand1
AC
5 ms
19072 KB
rand2
AC
5 ms
21120 KB
rand3
AC
1 ms
2688 KB
rand4
AC
14 ms
55936 KB
small0
AC
2 ms
8832 KB
small1
AC
2 ms
4736 KB
small2
AC
2 ms
6784 KB
supersmall0
AC
1 ms
256 KB
supersmall1
AC
1 ms
256 KB
supersmall2
AC
1 ms
256 KB