Submission #2277433


Source Code Expand

#include <iostream>
using namespace std;
const int mod = 1000000007;
int n, d, s, a, inv[33], dp[33][33][909];
int binpow(int val, int ex) {
	int ret = 1;
	while(ex) {
		if(ex & 1) ret = 1LL * ret * val % mod;
		val = 1LL * val * val % mod;
		ex >>= 1;
	}
	return ret;
}
int main() {
	inv[1] = 1;
	for(int i = 2; i <= 30; i++) inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
	cin >> n >> d; dp[0][0][0] = 1;
	for(int i = 0; i < n; i++) {
		cin >> a;
		for(int j = 0; j <= i; j++) {
			for(int k = 0; k <= s; k++) {
				dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % mod;
				int val = 1;
				for(int l = 0; l < a; l++) {
					dp[i + 1][j + 1][k + l] = (dp[i + 1][j + 1][k + l] + 1LL * dp[i][j][k] * val) % mod;
					val = 1LL * val * (d - k - l) % mod * inv[l + 1] % mod;
				}
			}
		}
		s += a;
	}
	int ret = 0;
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= d && j <= s; j++) {
			int val = 1LL * dp[n][i][j] * binpow(n - i, d - j) % mod;
			if(i % 2 == 0) ret = (ret + val) % mod;
			else ret = (ret - val + mod) % mod;
		}
	}
	cout << ret << endl;
	return 0;
}

Submission Info

Submission Time
Task D - 天下一ボディービルコンテスト
User square1001
Language C++14 (GCC 5.4.1)
Score 280
Code Size 1124 Byte
Status AC
Exec Time 91 ms
Memory 2048 KB

Judge Result

Set Name level1 level2 level3
Score / Max Score 40 / 40 100 / 100 140 / 140
Status
AC × 27
AC × 50
AC × 74
Set Name Test Cases
level1 level1_max_0.txt, level1_maxrand_0.txt, level1_maxrand_1.txt, level1_maxrand_2.txt, level1_maxrand_3.txt, level1_maxrand_4.txt, level1_maxrand_5.txt, level1_maxrand_6.txt, level1_maxrand_7.txt, level1_maxrand_8.txt, level1_maxrand_9.txt, level1_min1_0.txt, level1_min2_0.txt, level1_min3_0.txt, level1_min4_0.txt, level1_rand_0.txt, level1_rand_1.txt, level1_rand_2.txt, level1_rand_3.txt, level1_rand_4.txt, level1_rand_5.txt, level1_rand_6.txt, level1_rand_7.txt, level1_rand_8.txt, level1_rand_9.txt, level1_sample1.txt, level1_sample2.txt
level2 level1_max_0.txt, level1_maxrand_0.txt, level1_maxrand_1.txt, level1_maxrand_2.txt, level1_maxrand_3.txt, level1_maxrand_4.txt, level1_maxrand_5.txt, level1_maxrand_6.txt, level1_maxrand_7.txt, level1_maxrand_8.txt, level1_maxrand_9.txt, level1_min1_0.txt, level1_min2_0.txt, level1_min3_0.txt, level1_min4_0.txt, level1_rand_0.txt, level1_rand_1.txt, level1_rand_2.txt, level1_rand_3.txt, level1_rand_4.txt, level1_rand_5.txt, level1_rand_6.txt, level1_rand_7.txt, level1_rand_8.txt, level1_rand_9.txt, level1_sample1.txt, level1_sample2.txt, level2_max_0.txt, level2_maxrand_0.txt, level2_maxrand_1.txt, level2_maxrand_2.txt, level2_maxrand_3.txt, level2_maxrand_4.txt, level2_maxrand_5.txt, level2_maxrand_6.txt, level2_maxrand_7.txt, level2_maxrand_8.txt, level2_maxrand_9.txt, level2_min1_0.txt, level2_min2_0.txt, level2_rand_0.txt, level2_rand_1.txt, level2_rand_2.txt, level2_rand_3.txt, level2_rand_4.txt, level2_rand_5.txt, level2_rand_6.txt, level2_rand_7.txt, level2_rand_8.txt, level2_rand_9.txt
level3 level1_max_0.txt, level1_maxrand_0.txt, level1_maxrand_1.txt, level1_maxrand_2.txt, level1_maxrand_3.txt, level1_maxrand_4.txt, level1_maxrand_5.txt, level1_maxrand_6.txt, level1_maxrand_7.txt, level1_maxrand_8.txt, level1_maxrand_9.txt, level1_min1_0.txt, level1_min2_0.txt, level1_min3_0.txt, level1_min4_0.txt, level1_rand_0.txt, level1_rand_1.txt, level1_rand_2.txt, level1_rand_3.txt, level1_rand_4.txt, level1_rand_5.txt, level1_rand_6.txt, level1_rand_7.txt, level1_rand_8.txt, level1_rand_9.txt, level1_sample1.txt, level1_sample2.txt, level2_max_0.txt, level2_maxrand_0.txt, level2_maxrand_1.txt, level2_maxrand_2.txt, level2_maxrand_3.txt, level2_maxrand_4.txt, level2_maxrand_5.txt, level2_maxrand_6.txt, level2_maxrand_7.txt, level2_maxrand_8.txt, level2_maxrand_9.txt, level2_min1_0.txt, level2_min2_0.txt, level2_rand_0.txt, level2_rand_1.txt, level2_rand_2.txt, level2_rand_3.txt, level2_rand_4.txt, level2_rand_5.txt, level2_rand_6.txt, level2_rand_7.txt, level2_rand_8.txt, level2_rand_9.txt, level3_max_0.txt, level3_maxrand_0.txt, level3_maxrand_1.txt, level3_maxrand_2.txt, level3_maxrand_3.txt, level3_maxrand_4.txt, level3_maxrand_5.txt, level3_maxrand_6.txt, level3_maxrand_7.txt, level3_maxrand_8.txt, level3_maxrand_9.txt, level3_min1_0.txt, level3_min2_0.txt, level3_rand_0.txt, level3_rand_1.txt, level3_rand_2.txt, level3_rand_3.txt, level3_rand_4.txt, level3_rand_5.txt, level3_rand_6.txt, level3_rand_7.txt, level3_rand_8.txt, level3_rand_9.txt, level3_sample3.txt
Case Name Status Exec Time Memory
level1_max_0.txt AC 1 ms 384 KB
level1_maxrand_0.txt AC 1 ms 384 KB
level1_maxrand_1.txt AC 1 ms 256 KB
level1_maxrand_2.txt AC 1 ms 384 KB
level1_maxrand_3.txt AC 1 ms 384 KB
level1_maxrand_4.txt AC 1 ms 384 KB
level1_maxrand_5.txt AC 1 ms 256 KB
level1_maxrand_6.txt AC 1 ms 256 KB
level1_maxrand_7.txt AC 1 ms 384 KB
level1_maxrand_8.txt AC 1 ms 256 KB
level1_maxrand_9.txt AC 1 ms 384 KB
level1_min1_0.txt AC 1 ms 256 KB
level1_min2_0.txt AC 1 ms 384 KB
level1_min3_0.txt AC 1 ms 384 KB
level1_min4_0.txt AC 1 ms 256 KB
level1_rand_0.txt AC 1 ms 256 KB
level1_rand_1.txt AC 1 ms 256 KB
level1_rand_2.txt AC 1 ms 256 KB
level1_rand_3.txt AC 1 ms 256 KB
level1_rand_4.txt AC 1 ms 256 KB
level1_rand_5.txt AC 1 ms 256 KB
level1_rand_6.txt AC 1 ms 384 KB
level1_rand_7.txt AC 1 ms 256 KB
level1_rand_8.txt AC 1 ms 256 KB
level1_rand_9.txt AC 1 ms 256 KB
level1_sample1.txt AC 1 ms 256 KB
level1_sample2.txt AC 1 ms 256 KB
level2_max_0.txt AC 1 ms 384 KB
level2_maxrand_0.txt AC 1 ms 384 KB
level2_maxrand_1.txt AC 1 ms 256 KB
level2_maxrand_2.txt AC 1 ms 256 KB
level2_maxrand_3.txt AC 1 ms 384 KB
level2_maxrand_4.txt AC 1 ms 384 KB
level2_maxrand_5.txt AC 1 ms 256 KB
level2_maxrand_6.txt AC 1 ms 256 KB
level2_maxrand_7.txt AC 1 ms 384 KB
level2_maxrand_8.txt AC 1 ms 384 KB
level2_maxrand_9.txt AC 1 ms 256 KB
level2_min1_0.txt AC 1 ms 384 KB
level2_min2_0.txt AC 1 ms 256 KB
level2_rand_0.txt AC 1 ms 256 KB
level2_rand_1.txt AC 1 ms 256 KB
level2_rand_2.txt AC 1 ms 256 KB
level2_rand_3.txt AC 1 ms 256 KB
level2_rand_4.txt AC 1 ms 384 KB
level2_rand_5.txt AC 1 ms 256 KB
level2_rand_6.txt AC 1 ms 256 KB
level2_rand_7.txt AC 1 ms 256 KB
level2_rand_8.txt AC 1 ms 256 KB
level2_rand_9.txt AC 1 ms 256 KB
level3_max_0.txt AC 91 ms 2048 KB
level3_maxrand_0.txt AC 28 ms 2048 KB
level3_maxrand_1.txt AC 21 ms 2048 KB
level3_maxrand_2.txt AC 20 ms 2048 KB
level3_maxrand_3.txt AC 24 ms 2048 KB
level3_maxrand_4.txt AC 21 ms 2048 KB
level3_maxrand_5.txt AC 30 ms 2048 KB
level3_maxrand_6.txt AC 28 ms 2048 KB
level3_maxrand_7.txt AC 22 ms 2048 KB
level3_maxrand_8.txt AC 26 ms 2048 KB
level3_maxrand_9.txt AC 21 ms 2048 KB
level3_min1_0.txt AC 2 ms 2048 KB
level3_min2_0.txt AC 1 ms 256 KB
level3_rand_0.txt AC 13 ms 1280 KB
level3_rand_1.txt AC 9 ms 1152 KB
level3_rand_2.txt AC 1 ms 256 KB
level3_rand_3.txt AC 4 ms 768 KB
level3_rand_4.txt AC 1 ms 256 KB
level3_rand_5.txt AC 4 ms 640 KB
level3_rand_6.txt AC 4 ms 640 KB
level3_rand_7.txt AC 7 ms 1024 KB
level3_rand_8.txt AC 2 ms 384 KB
level3_rand_9.txt AC 1 ms 384 KB
level3_sample3.txt AC 2 ms 640 KB