Submission #1817564
Source Code Expand
#include"bits/stdc++.h"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int maxn = 4010;
const int mod = 924844033;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}
int n,K,ans,t;
int f[maxn][maxn][2];
int fac[maxn],Is[maxn];
void Work(){
fac[0]=1;
REP(i,1,n)fac[i]=1ll*fac[i-1]*i%mod;
for(int i=0,j=1;i<=n;i++,j=-j)ans=(1ll*j*(f[n*2][i][0]+f[n*2][i][1])*fac[n-i]%mod+ans+mod)%mod;
iout(ans);
}
void Init(){
read(n,K);
REP(i,1,K)REP(j,0,1){
int x=i;
while(x<=n){
t++;x+=K;
}
Is[t]=1;
}
f[1][0][0]=1;
REP(i,1,n*2-1)REP(j,0,n){
f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%mod;
if(!Is[i])f[i+1][j+1][1]=f[i][j][0];
}
}
int main(){
Init();
Work();
return 0;
}
Submission Info
Submission Time |
|
Task |
D - ~K Perm Counting |
User |
yanQval |
Language |
C++14 (GCC 5.4.1) |
Score |
900 |
Code Size |
2178 Byte |
Status |
AC |
Exec Time |
52 ms |
Memory |
124672 KB |
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 |
9 ms |
27392 KB |
handmade0 |
AC |
1 ms |
256 KB |
handmade1 |
AC |
52 ms |
124672 KB |
handmade2 |
AC |
49 ms |
124672 KB |
handmade3 |
AC |
49 ms |
118144 KB |
handmade4 |
AC |
44 ms |
116096 KB |
handmade5 |
AC |
52 ms |
124672 KB |
handmade6 |
AC |
52 ms |
124672 KB |
maxrand0 |
AC |
47 ms |
120192 KB |
maxrand1 |
AC |
49 ms |
120192 KB |
maxrand2 |
AC |
50 ms |
124416 KB |
maxrand3 |
AC |
49 ms |
120192 KB |
maxrand4 |
AC |
46 ms |
120192 KB |
rand0 |
AC |
51 ms |
124416 KB |
rand1 |
AC |
13 ms |
37632 KB |
rand2 |
AC |
15 ms |
43904 KB |
rand3 |
AC |
3 ms |
4608 KB |
rand4 |
AC |
43 ms |
112000 KB |
small0 |
AC |
6 ms |
19072 KB |
small1 |
AC |
4 ms |
10880 KB |
small2 |
AC |
5 ms |
14976 KB |
supersmall0 |
AC |
1 ms |
256 KB |
supersmall1 |
AC |
1 ms |
256 KB |
supersmall2 |
AC |
1 ms |
256 KB |