Submission #1069194

#TimeUsernameProblemLanguageResultExecution timeMemory
1069194SharkySkyscraper (JOI16_skyscraper)C++17
100 / 100
40 ms25492 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1'000'000'007; const int N = 108, L = 1008; int dp[N][N][L][3], a[N]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, l; cin >> n >> l; for (int i = 1; i <= n; i++) cin >> a[i]; if (n == 1) { cout << 1 << '\n'; return 0; } sort(a + 1, a + n + 1); dp[0][0][0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= l; k++) { for (int m = 0; m <= 2; m++) { int v = dp[i - 1][j][k][m]; if (!v) continue; int add = (2 * j - m) * (a[i] - a[i - 1]); if (k + add > l) continue; if (j > 1) (dp[i][j - 1][k + add][m] += (v * (j - 1)) % mod) %= mod; if (j) (dp[i][j][k + add][m] += (v * (2 * j - m)) % mod) %= mod; (dp[i][j + 1][k + add][m] += (v * (j + 1 - m)) % mod) %= mod; if (m < 2) { (dp[i][j + 1][k + add][m + 1] += (v * (2 - m)) % mod) %= mod; if (j) (dp[i][j][k + add][m + 1] += (v * (2 - m)) % mod) %= mod; } } } } } int ans = 0; for (int i = 0; i <= l; i++) (ans += dp[n][1][i][2]) %= mod; cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...