Submission #2237248


Source Code Expand

import java.util.*;
import java.io.*;

class Main {
	static long [][] c = new long [2002][2002];
	static long [] fac = new long [2002]; 
	static final int mod = 924844033;
	static long [][] dp = new long [4002][4002];
	
	public static void main (String[] args) {
		Reader in = new Reader();
		int n = in.nextInt();
		int k = in.nextInt();
		
		fac[0] = 1;
		for(int i = 1; i <= n; i++) {
			fac[i] = fac[i - 1] * i;
			fac[i] %= mod;
		}
		for(int i = 0; i <= n; i++) {
			c[i][0] = 1;
			for(int j = 1; j <= i; j++) {
				c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
				c[i][j] %= mod;
			}
		}
		ArrayList <Integer> chain = new ArrayList <> ();
		for(int i = 1; i <= k; i++) {
			int sz = 0;
			int cur = i;
			while(cur <= n) {
				++sz;
				cur += k;
			}
			chain.add(sz);
			chain.add(sz);
		}
		dp[0][0] = 1;
		for(int i = 1; i <= chain.size(); i++) {
			int sz = chain.get(i - 1);
			for(int j = 0; j <= n; j++) {
				for(int x = 0; x <= Math.min(j, sz); x++) {
					dp[i][j] += dp[i - 1][j - x] * c[sz - x][x];
					dp[i][j] %= mod;
				}
			}
		}
		
		long ans = 0;
		for(int i = 0; i <= n; i++) {
			if(i % 2 == 1) {
				ans -= fac[n - i] * dp[chain.size()][i];
			} else {
				ans += fac[n - i] * dp[chain.size()][i];
			}
			ans %= mod;
		}
		if(ans < 0) ans += mod;
		System.out.println(ans);
	}
	static class Reader {
		private BufferedReader a;
		private StringTokenizer b;
		Reader() {
			a = new BufferedReader (new InputStreamReader (System.in));
		} 
		public String next () {
			while(b == null || !b.hasMoreTokens()) {
				try {
					 b = new StringTokenizer (a.readLine());
				 } catch (IOException e) {
					 e.printStackTrace();
				 }
			 }
			 return b.nextToken();
		}
		public int nextInt () {
		     return Integer.parseInt(next());
		}
		public long nextLong () {
			return Long.parseLong(next());
		}
		public double nextDouble () {
			return Double.parseDouble(next());
		}
		public String nextLine () {
		 	try {
		 		return a.readLine();
		 	} catch (IOException e) {
		 		e.printStackTrace ();
		 	}
		 	return "##";
		}
	}
}

Submission Info

Submission Time
Task D - ~K Perm Counting
User tasmeemreza
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 2155 Byte
Status MLE
Exec Time 315 ms
Memory 244948 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 900
Status
AC × 5
AC × 27
MLE × 1
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 167 ms 241364 KB
example1 AC 166 ms 239416 KB
example2 AC 168 ms 242252 KB
example3 AC 169 ms 241852 KB
example4 AC 200 ms 242388 KB
handmade0 AC 173 ms 241080 KB
handmade1 MLE 246 ms 244948 KB
handmade2 AC 315 ms 242388 KB
handmade3 AC 243 ms 241108 KB
handmade4 AC 299 ms 241108 KB
handmade5 AC 258 ms 241984 KB
handmade6 AC 261 ms 242120 KB
maxrand0 AC 280 ms 241988 KB
maxrand1 AC 280 ms 241604 KB
maxrand2 AC 283 ms 244172 KB
maxrand3 AC 260 ms 241988 KB
maxrand4 AC 290 ms 241476 KB
rand0 AC 275 ms 241108 KB
rand1 AC 203 ms 241996 KB
rand2 AC 210 ms 242628 KB
rand3 AC 171 ms 240708 KB
rand4 AC 278 ms 242000 KB
small0 AC 195 ms 243524 KB
small1 AC 190 ms 226380 KB
small2 AC 200 ms 244692 KB
supersmall0 AC 167 ms 242756 KB
supersmall1 AC 166 ms 242624 KB
supersmall2 AC 168 ms 240580 KB