Submission #1440428
Source Code Expand
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
char t=getchar();
bool neg=false;
x=0;
for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
if(t=='-')neg=true,t=getchar();
for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
if(x<0)putchar('-'),x=-x;
short a[20]= {},sz=0;
while(x>0)a[sz++]=x%10,x/=10;
if(sz==0)putchar('0');
for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);
const int mod=924844033;
int f[2333],n,k,ans,t;
int dp[2333][2333][2][2],g[2333],tmp[2333];
int main()
{
f[0]=1;
for(int i=1;i<2333;i++)
f[i]=1ll*i*f[i-1]%mod;
get2(n,k);t=n/k+1;
dp[1][0][1][0]=1;
for(int i=1;i<=t;i++)for(int j=0;j<=i;j++)
for(int l1=0;l1<2;l1++)for(int l2=0;l2<2;l2++)
{
//a[i]!=i-1,a[i]!=i+1
dp[i+1][j][l2][0]+=dp[i][j][l1][l2];if(dp[i+1][j][l2][0]>=mod)dp[i+1][j][l2][0]-=mod;
//a[i]=i-1
if(l1==0)dp[i+1][j+1][l2][0]+=dp[i][j][l1][l2];if(dp[i+1][j+1][l2][0]>=mod)dp[i+1][j+1][l2][0]-=mod;
//a[i]=i+1
dp[i+1][j+1][l2][1]+=dp[i][j][l1][l2];if(dp[i+1][j+1][l2][1]>=mod)dp[i+1][j+1][l2][1]-=mod;
}
g[0]=1;
for(int i=0;i<n%k;i++)
{
memset(tmp,0,sizeof(tmp));
for(int j=0;j<=n;j++)for(int k=0;k<=t;k++)
tmp[j+k]=(tmp[j+k]+1ll*g[j]*(dp[t+1][k][0][0]+dp[t+1][k][1][0]))%mod;
memcpy(g,tmp,sizeof(g));
}
for(int i=n%k;i<k;i++)
{
memset(tmp,0,sizeof(tmp));
for(int j=0;j<=n;j++)for(int k=0;k<t;k++)
tmp[j+k]=(tmp[j+k]+1ll*g[j]*(dp[t][k][0][0]+dp[t][k][1][0]))%mod;
memcpy(g,tmp,sizeof(g));
}
for(int i=0;i<=n;i++)if(i%2==0)ans=(ans+1ll*g[i]*f[n-i])%mod;else ans=(ans-1ll*g[i]*f[n-i]%mod+mod)%mod;
printendl(ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
D - ~K Perm Counting |
User |
OhWeOnFire |
Language |
C++14 (GCC 5.4.1) |
Score |
900 |
Code Size |
2428 Byte |
Status |
AC |
Exec Time |
75 ms |
Memory |
72192 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 |
2 ms |
256 KB |
example4 |
AC |
2 ms |
256 KB |
handmade0 |
AC |
1 ms |
256 KB |
handmade1 |
AC |
75 ms |
72192 KB |
handmade2 |
AC |
24 ms |
256 KB |
handmade3 |
AC |
67 ms |
68096 KB |
handmade4 |
AC |
20 ms |
256 KB |
handmade5 |
AC |
12 ms |
512 KB |
handmade6 |
AC |
12 ms |
512 KB |
maxrand0 |
AC |
19 ms |
256 KB |
maxrand1 |
AC |
15 ms |
256 KB |
maxrand2 |
AC |
15 ms |
256 KB |
maxrand3 |
AC |
11 ms |
2560 KB |
maxrand4 |
AC |
21 ms |
256 KB |
rand0 |
AC |
14 ms |
256 KB |
rand1 |
AC |
3 ms |
256 KB |
rand2 |
AC |
4 ms |
256 KB |
rand3 |
AC |
1 ms |
256 KB |
rand4 |
AC |
17 ms |
256 KB |
small0 |
AC |
1 ms |
256 KB |
small1 |
AC |
1 ms |
256 KB |
small2 |
AC |
2 ms |
256 KB |
supersmall0 |
AC |
1 ms |
256 KB |
supersmall1 |
AC |
1 ms |
256 KB |
supersmall2 |
AC |
1 ms |
256 KB |