Submission #3456310
Source Code Expand
#include<bits/stdc++.h> #define IL inline #define RG register #define LL long long #define Upd(a) (a)>=mod?(a)-=mod:1 using namespace std; int n, k; const int _ =2001, mod = 924844033; bool Use[_<<1]; LL dp[_<<1][_][2], pre=0, pg=0; LL jc[_], g[_]; IL int Add (RG int now) { if (now<=n) { if (now+k>n) return -1; return now+k+n; } else { if (now+k-n>n) return -1; return now+k-n; } } IL void work (RG int now) { for (RG int i=0; i<=n; ++i) dp[pre+1][i][0]=dp[pre][i][0]+dp[pre][i][1], Upd(dp[pre+1][i][0]); ++pre; Use[now]=1; for (RG int i=Add(now); ~i; i=Add(i)) { Use[i]=1; for (RG int j=1; j<=n; ++j) { dp[pre+1][j][1]=dp[pre][j-1][0]; } for (RG int j=0; j<=n; ++j) { dp[pre+1][j][0]=dp[pre][j][1]+dp[pre][j][0]; Upd(dp[pre+1][j][0]); } ++pre; } } int main () { cin>>n>>k; dp[0][0][0]=1; for (RG int i=1; i<=n; ++i) { if (!Use[i]) work (i); if (!Use[i+n]) work (i+n); } jc[0]=1; for (RG int i=1; i<=n; ++i) jc[i]=1LL*jc[i-1]*i%mod; for (RG int i=0; i<=n; ++i) g[i]=1LL*(dp[n*2][i][0]+dp[n*2][i][1])%mod*jc[n-i]%mod; for (RG int i=1, j=1; i<=n; ++i, j=-j) g[0]-=1LL*g[i]*j%mod, g[0]=(g[0]+mod)%mod; cout<<g[0]; }
Submission Info
Submission Time | |
---|---|
Task | D - ~K Perm Counting |
User | PH_2002 |
Language | C++14 (GCC 5.4.1) |
Score | 900 |
Code Size | 1216 Byte |
Status | AC |
Exec Time | 56 ms |
Memory | 125312 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 | 7 ms | 25472 KB |
handmade0 | AC | 1 ms | 256 KB |
handmade1 | AC | 56 ms | 125312 KB |
handmade2 | AC | 36 ms | 125312 KB |
handmade3 | AC | 52 ms | 119040 KB |
handmade4 | AC | 32 ms | 114944 KB |
handmade5 | AC | 55 ms | 125312 KB |
handmade6 | AC | 56 ms | 125312 KB |
maxrand0 | AC | 36 ms | 121088 KB |
maxrand1 | AC | 41 ms | 121088 KB |
maxrand2 | AC | 43 ms | 125184 KB |
maxrand3 | AC | 52 ms | 121088 KB |
maxrand4 | AC | 34 ms | 121088 KB |
rand0 | AC | 50 ms | 125184 KB |
rand1 | AC | 10 ms | 38016 KB |
rand2 | AC | 11 ms | 44288 KB |
rand3 | AC | 2 ms | 4736 KB |
rand4 | AC | 33 ms | 112896 KB |
small0 | AC | 5 ms | 19200 KB |
small1 | AC | 3 ms | 10880 KB |
small2 | AC | 4 ms | 15104 KB |
supersmall0 | AC | 1 ms | 256 KB |
supersmall1 | AC | 1 ms | 256 KB |
supersmall2 | AC | 1 ms | 256 KB |