# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91043 | tincamatei | Skyscraper (JOI16_skyscraper) | C++14 | 225 ms | 47800 KiB |
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 <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
const int MAX_L = 1000;
const int MOD = 1000000007;
int v[1+MAX_N];
int dp[1+MAX_N][1+MAX_N+1][1+MAX_L][3];
int main() {
#ifdef HOME
FILE *fin = fopen("input.in", "r");
FILE *fout = fopen("output.out", "w");
#else
FILE *fin = stdin;
FILE *fout = stdout;
#endif
int n, l;
fscanf(fin, "%d%d", &n, &l);
for(int i = 1; i <= n; ++i)
fscanf(fin, "%d", &v[i]);
sort(v + 1, v + 1 + n);
if(n == 1) {
fprintf(fout, "%d", 1);
} else {
dp[0][0][0][0] = 1;
for(int N = 1; N <= n; ++N)
for(int C = 1; C <= N; ++C)
for(int L = 0; L <= l; ++L)
for(int E = 0; E <= 2; ++E) {
int scad;
// Componenta noua:
scad = ((C - 1) * 2 - E) * (v[N] - v[N - 1]);
if(L >= scad)
dp[N][C][L][E] = ((long long)dp[N - 1][C - 1][L - scad][E] * (C - E) + dp[N][C][L][E]) % MOD;
// Atasez la o componenta
scad = (C * 2 - E) * (v[N] - v[N - 1]);
if(L >= scad)
dp[N][C][L][E] = ((long long)dp[N - 1][C][L - scad][E] * (C * 2 - E) + dp[N][C][L][E]) % MOD;
// Unesc doua componente
scad = ((C + 1) * 2 - E) * (v[N] - v[N - 1]);
if(L >= scad)
dp[N][C][L][E] = ((long long)dp[N - 1][C + 1][L - scad][E] * C + dp[N][C][L][E]) % MOD;
// Imi creez o componenta intr-o margine
scad = ((C - 1) * 2 - (E - 1)) * (v[N] - v[N - 1]);
if(L >= scad && E >= 1)
dp[N][C][L][E] = ((long long)dp[N - 1][C - 1][L - scad][E - 1] * (2 - E + 1) + dp[N][C][L][E]) % MOD;
// Atasez la o componenta si fixez marginea
scad = (2 * C - (E - 1)) * (v[N] - v[N - 1]);
if(L >= scad && E >= 1)
dp[N][C][L][E] = ((long long)dp[N - 1][C][L - scad][E - 1] * (2 - E + 1) + dp[N][C][L][E]) % MOD;
}
int rez = 0;
for(int i = 0; i <= l; ++i)
rez = (rez + dp[n][1][i][2]) % MOD;
fprintf(fout, "%d", rez % MOD);
}
#ifdef HOME
fclose(fin);
fclose(fout);
#endif
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |