Submission #2105585
Source Code Expand
#include <cstdio>
#include <cstring>
using namespace std;
const int Max_N(2050);
const int MOD(924844033);
typedef long long int LL;
inline int Mult(const int &a, const int &b)
{
return static_cast<int>(static_cast<LL>(a) * static_cast<LL>(b) % static_cast<LL>(MOD));
}
inline void update(int &a, const int &b)
{
((a += b) >= MOD) ? (a -= MOD) : 0;
}
int N, K, Ans[Max_N], ANS, Fac[Max_N];
int M, V[Max_N], F[Max_N][Max_N][2][2];
//考虑容斥
//强制选一些点不合法
//在mod K意义下dp
//F[i][j][a][b]表示dp到第i个数,选了j个不合法,V[i]是否可用,V[i + 1]是否可用
int main()
{
scanf("%d%d", &N, &K);
Fac[0] = 1;
for (int i = 1;i <= N;++i)
Fac[i] = Mult(Fac[i - 1], i);
Ans[0] = 1;
for (int m = 1;m <= K;++m)
{
M = 0;
for (int i = m;i <= N;i += K)
V[++M] = i;
memset(F[1], 0, sizeof(F[1]));
if (M == 1)
F[1][0][1][0] = 1;
else
{
F[1][0][1][1] = 1;
F[1][1][1][0] = 1;
for (int i = 2;i <= M;++i)
{
memset(F[i], 0, sizeof(F[i]));
for (int j = 0;j <= i - 1;++j)
for (int a = 0;a <= 1;++a)
for (int b = 0;b <= 1;++b)
{
update(F[i][j][b][(i + 1) <= M], F[i - 1][j][a][b]);
if (a)
update(F[i][j + 1][b][(i + 1) <= M], F[i - 1][j][a][b]);
if (i + 1 <= M)
update(F[i][j + 1][b][0], F[i - 1][j][a][b]);
}
}
}
for (int j = N;j >= 0;--j)
for (int k = 1;k <= M && k <= j;++k)
{
int Ret(0);
for (int a = 0;a <= 1;++a)
update(Ret, F[M][k][a][0]);
update(Ans[j], Mult(Ans[j - k], Ret));
}
}
for (int i = 0;i <= N;++i)
{
Ans[i] = Mult(Ans[i], Fac[N - i]);
if (i & 1)
update(ANS, (-Ans[i] % MOD + MOD) % MOD);
else
update(ANS, Ans[i]);
}
printf("%d", ANS);
return 0;
}
Submission Info
Submission Time
2018-02-17 23:16:40+0900
Task
D - ~K Perm Counting
User
Created_equal
Language
C++14 (GCC 5.4.1)
Score
900
Code Size
1832 Byte
Status
AC
Exec Time
83 ms
Memory
65664 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:31:23: 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
2 ms
512 KB
handmade0
AC
1 ms
256 KB
handmade1
AC
83 ms
65664 KB
handmade2
AC
20 ms
256 KB
handmade3
AC
74 ms
61568 KB
handmade4
AC
17 ms
256 KB
handmade5
AC
31 ms
1408 KB
handmade6
AC
31 ms
1408 KB
maxrand0
AC
20 ms
256 KB
maxrand1
AC
25 ms
256 KB
maxrand2
AC
25 ms
256 KB
maxrand3
AC
29 ms
4224 KB
maxrand4
AC
18 ms
256 KB
rand0
AC
28 ms
384 KB
rand1
AC
3 ms
256 KB
rand2
AC
3 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
1 ms
256 KB
supersmall0
AC
1 ms
256 KB
supersmall1
AC
1 ms
256 KB
supersmall2
AC
1 ms
256 KB