This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
const int mod = 1e9 + 7;
int n, l;
int a[101];
int dp[101][101][1001][2][2];
void add(int i, int j, int k, int d, int a, int b, llong p) {
k += ((j << 1) + a + b) * d;
if (j < 0) return;
if (l < k) return;
dp[i][j][k][a][b] += p % mod;
dp[i][j][k][a][b] %= mod;
}
int main() {
scanf("%d%d", &n, &l);
if (n == 1) {
printf("1\n");
return 0;
}
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
sort(a, a + n);
dp[0][0][0][0][0] = 1;
for (int i = 0; i + 1 < n; ++i) {
int d = a[i + 1] - a[i];
for (int j = 0; j <= i; ++j) {
for (int k = 0; k <= l; ++k) {
llong v;
//0 0
v = dp[i][j][k][0][0];
add(i + 1, j, k, d, 1, 0, v);
add(i + 1, j, k, d, 0, 1, v);
add(i + 1, j + 1, k, d, 0, 0, v);
add(i + 1, j, k, d, 0, 0, v * (j << 1));
add(i + 1, j - 1, k, d, 0, 0, v * j * (j - 1));
add(i + 1, j - 1, k, d, 0, 1, v * j);
add(i + 1, j - 1, k, d, 1, 0, v * j);
//0 1
v = dp[i][j][k][0][1];
add(i + 1, j, k, d, 1, 1, v);
add(i + 1, j, k, d, 0, 1, v);
add(i + 1, j + 1, k, d, 0, 1, v);
add(i + 1, j, k, d, 0, 1, v * (j << 1));
add(i + 1, j - 1, k, d, 0, 1, v * j * (j - 1));
add(i + 1, j - 1, k, d, 0, 1, v * j);
add(i + 1, j - 1, k, d, 1, 1, v * j);
//1 0
v = dp[i][j][k][1][0];
add(i + 1, j, k, d, 1, 0, v);
add(i + 1, j, k, d, 1, 1, v);
add(i + 1, j + 1, k, d, 1, 0, v);
add(i + 1, j, k, d, 1, 0, v * (j << 1));
add(i + 1, j - 1, k, d, 1, 0, v * j * (j - 1));
add(i + 1, j - 1, k, d, 1, 1, v * j);
add(i + 1, j - 1, k, d, 1, 0, v * j);
//1 1
v = dp[i][j][k][1][1];
add(i + 1, j, k, d, 1, 1, v);
add(i + 1, j, k, d, 1, 1, v);
add(i + 1, j + 1, k, d, 1, 1, v);
add(i + 1, j, k, d, 1, 1, v * (j << 1));
add(i + 1, j - 1, k, d, 1, 1, v * j * (j - 1));
add(i + 1, j - 1, k, d, 1, 1, v * j);
add(i + 1, j - 1, k, d, 1, 1, v * j);
}
}
}
int ret = 0;
for (int i = 0; i <= l; ++i) {
ret += dp[n - 1][0][i][1][1];
ret %= mod;
ret += dp[n - 1][0][i][0][1];
ret %= mod;
ret += dp[n - 1][0][i][1][0];
ret %= mod;
}
printf("%d\n", ret);
return 0;
}
Compilation message (stderr)
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &l);
~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", a + i);
~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |