Submission #863063

# Submission time Handle Problem Language Result Execution time Memory
863063 2023-10-19T14:24:22 Z TAhmed33 Magneti (COCI21_magneti) C++
0 / 110
83 ms 66952 KB
#include <bits/stdc++.h>
using namespace std;
int n, l, x;
const int MOD = 1e9 + 7;
int nCr[30500][500];
int dp[2][100001][51];
int add (int a, int b) {
	a += b; if (a >= MOD) a -= MOD;
	return a;
}
int sub (int a, int b) {
	a -= b; if (a < 0) a += MOD;
	return a;
}
int mul (int a, int b) {
	return (a * 1ll * b) % MOD;
}
int arr[51];
int main () {
	cin >> n >> l;
	for (int i = 0; i < 30500; i++) {
		for (int j = 0; j <= min(499, i); j++) {
			if (j == 0 || j == i) {
				nCr[i][j] = 1;
			} else {
				nCr[i][j] = add(nCr[i - 1][j], nCr[i - 1][j - 1]);
			}
		}
	}
	for (int i = 1; i <= n; i++) cin >> arr[i];
	sort(arr + 1, arr + n + 1);
	dp[0][0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= l; j++) {
			for (int k = 1; k <= i; k++) {
				dp[i & 1][j][k] = 0;
				if (2 * arr[i] - 1 <= j) dp[i & 1][j][k] = add(dp[i & 1][j][k], mul(mul(k + 1, k), dp[i & 1 ^ 1][j - 2 * arr[i] + 1][k + 1]));
				dp[i & 1][j][k] = add(dp[i & 1][j][k], dp[i & 1 ^ 1][j - 1][k - 1]);
				if (arr[i] <= j) dp[i & 1][j][k] = add(dp[i & 1][j][k], mul(2 * k, dp[i & 1 ^ 1][j - arr[i]][k]));
				//cout << i << " " << j << " " << k << ": " << dp[i][j][k] << '\n';
			}
		}
	}
	//for (int i = 1; i <= l; i++) cout << dp[n][i][1] << '\n';
	int sum = 0;
	for (int i = 1; i <= l; i++) sum = add(sum, mul(dp[n & 1][i][1], nCr[n - i + l][n]));
	cout << sum << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:37:93: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   37 |     if (2 * arr[i] - 1 <= j) dp[i & 1][j][k] = add(dp[i & 1][j][k], mul(mul(k + 1, k), dp[i & 1 ^ 1][j - 2 * arr[i] + 1][k + 1]));
      |                                                                                           ~~^~~
Main.cpp:38:49: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   38 |     dp[i & 1][j][k] = add(dp[i & 1][j][k], dp[i & 1 ^ 1][j - 1][k - 1]);
      |                                               ~~^~~
Main.cpp:39:77: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   39 |     if (arr[i] <= j) dp[i & 1][j][k] = add(dp[i & 1][j][k], mul(2 * k, dp[i & 1 ^ 1][j - arr[i]][k]));
      |                                                                           ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 66952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 66908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 62800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 83 ms 66952 KB Output isn't correct
2 Halted 0 ms 0 KB -