Submission #1243222


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 924844033;

const int MAXN = 2e3 + 5;

ll f[MAXN];

int dp[2 * MAXN][MAXN][2];

int nxt[2 * MAXN], used[MAXN];

void solve(){
	int n, k;
	scanf("%d%d", &n, &k);
	f[0] = 1;
	REPN(i, 1, n){
		f[i] = (f[i - 1] * i) % MOD;
	}
	int top = 0;
	nxt[top++] = 0;
	REPN(i, 1, n){
		if (!used[i]){
			for(int j = i; j <= n; j += k){
				used[j] = 1;
				nxt[top++] = 1;
			}
			nxt[top - 1] = 0;
			for(int j = i; j <= n; j += k){
				nxt[top++] = 1;
			}
			nxt[top - 1] = 0;
		}
	}
	dp[0][0][0] = 1;
	REP(i, 0, 2 * n){
		REP(j, 0, n){
			if (nxt[i]){
				dp[i + 1][j + 1][1] = (dp[i + 1][j + 1][1] + dp[i][j][0]) % MOD;
			}
		}
		REPN(j, 0, n){
			dp[i + 1][j][0] = (dp[i + 1][j][0] + dp[i][j][0]) % MOD;
			dp[i + 1][j][0] = (dp[i + 1][j][0] + dp[i][j][1]) % MOD;
		}
	}
	
	/*REPN(i, 0, 2 * n){
		printf("%d %d\n", i, nxt[i]);
		REPN(j, 0, n){
			printf("%d ", dp[i][j][0] + dp[i][j][1]);
		}
		putchar('\n');
	}*/
	
	ll ans = 0ll;
	REPN(i, 0, n){
		ll add = ((ll)(dp[2 * n][i][0] + dp[2 * n][i][1]) * f[n - i]) % MOD;
		//printf("%d %lld\n", i, add);
		if (i % 2 == 1){
			ans = (ans + MOD - add) % MOD;
		} else {
			ans = (ans + add) % MOD;
		}
	}
	printf("%lld\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Submission Info

Submission Time
Task D - ~K Perm Counting
User Timur_Sitdikov
Language C++14 (GCC 5.4.1)
Score 900
Code Size 2203 Byte
Status AC
Exec Time 65 ms
Memory 62976 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:44: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
AC × 5
AC × 28
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 13440 KB
handmade0 AC 1 ms 256 KB
handmade1 AC 65 ms 62976 KB
handmade2 AC 54 ms 62976 KB
handmade3 AC 58 ms 59648 KB
handmade4 AC 46 ms 59648 KB
handmade5 AC 65 ms 62976 KB
handmade6 AC 65 ms 62976 KB
maxrand0 AC 52 ms 61696 KB
maxrand1 AC 56 ms 61696 KB
maxrand2 AC 58 ms 61824 KB
maxrand3 AC 60 ms 61696 KB
maxrand4 AC 50 ms 61696 KB
rand0 AC 62 ms 62720 KB
rand1 AC 10 ms 19840 KB
rand2 AC 12 ms 21888 KB
rand3 AC 2 ms 2944 KB
rand4 AC 46 ms 57600 KB
small0 AC 5 ms 9216 KB
small1 AC 3 ms 4992 KB
small2 AC 4 ms 7168 KB
supersmall0 AC 1 ms 256 KB
supersmall1 AC 1 ms 256 KB
supersmall2 AC 1 ms 256 KB