Submission #8050549


Source Code Expand

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

const int _ = 103;
int dp[_][_][_][2] , C[_][_] , coef[_][_][_][2] , N , M , K , D;

int poww(long long a , int b){
	int times = 1;
	while(b){if(b & 1) times = times * a % D; a = a * a % D; b >>= 1;}
	return times;
}

int main(){
	cin >> N >> M >> K >> D;
	for(int i = 0 ; i <= max(N , M) ; ++i){
		C[i][0] = 1;
		for(int j = 1 ; j <= i ; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % D;
	}

	for(int k = 0 ; k < K ; ++k)
		for(int i = 0 ; i <= M ; ++i)
			for(int j = 0 ; j <= N ; ++j){
				coef[k][i][j][0] = 1ll * poww(K - k , i) * (poww(k + 1 , M - i) - poww(k , M - i) + D) % D;
				coef[k][i][j][1] = 1ll * (poww(K - k , j) - poww(K - k - 1 , j) + D) * poww(k + 1 , N - j) % D;
			}
					
	dp[0][0][0][0] = 1;
	for(int k = 0 ; k < K ; ++k){
		for(int p = 0 ; p <= M ; ++p)
			for(int q = 0 ; q <= N ; ++q)
				if(dp[k][p][q][0])
					for(int tms = 1 , m = 0 ; m + q <= N ; ++m , tms = 1ll * tms * coef[k][p][q][0] % D)
						dp[k][p][q + m][1] = (dp[k][p][q + m][1] + 1ll * dp[k][p][q][0] * tms % D * C[N - q][m]) % D;
		for(int p = 0 ; p <= M ; ++p)
			for(int q = 0 ; q <= N ; ++q)
				if(dp[k][p][q][1])
					for(int tms = 1 , m = 0 ; m + p <= M ; ++m , tms = 1ll * tms * coef[k][p][q][1] % D)
						dp[k + 1][p + m][q][0] = (dp[k + 1][p + m][q][0] + 1ll * dp[k][p][q][1] * tms % D * C[M - p][m]) % D;
	}
	
	cout << dp[K][M][N][0];
	return 0;
}

Submission Info

Submission Time
Task F - Min Product Sum
User Itst
Language C++14 (GCC 5.4.1)
Score 2000
Code Size 1446 Byte
Status AC
Exec Time 4330 ms
Memory 17152 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 2000 / 2000
Status
AC × 3
AC × 21
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 4330 ms 17152 KB
02.txt AC 4181 ms 17024 KB
03.txt AC 3978 ms 16896 KB
04.txt AC 4281 ms 17152 KB
05.txt AC 1795 ms 16512 KB
06.txt AC 384 ms 11264 KB
07.txt AC 3293 ms 16640 KB
08.txt AC 1084 ms 16128 KB
09.txt AC 2 ms 2304 KB
10.txt AC 2 ms 2432 KB
11.txt AC 2 ms 2304 KB
12.txt AC 4 ms 14720 KB
13.txt AC 4 ms 14720 KB
14.txt AC 46 ms 14720 KB
15.txt AC 9 ms 2432 KB
16.txt AC 503 ms 11776 KB
17.txt AC 3317 ms 17024 KB
18.txt AC 1991 ms 16256 KB
s1.txt AC 1 ms 2304 KB
s2.txt AC 2 ms 2304 KB
s3.txt AC 143 ms 11392 KB