Submission #527004

#TimeUsernameProblemLanguageResultExecution timeMemory
527004FireGhost1301Skyscraper (JOI16_skyscraper)C++11
100 / 100
92 ms15212 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; void add(int &x, int y) { x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int mul(int x, int y) { return (x * 1LL * y) % MOD; } const int N = 100 + 3, M = 1000 + 3; int n, m, a[N]; int f[N][N][M][3]; void solve() { cin >> n >> m; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); a[n + 1] = a[n]; if (n == 1) { cout << 1; return; } f[0][0][0][0] = 1; for (int i = 0; i < n; ++i) { int x = a[i + 2] - a[i + 1]; for (int j = 0; j <= i; ++j) { for (int k = 0; k <= m; ++k) { for (int l = 0; l < 3; ++l) if (f[i][j][k][l]) { if (k + (2 * j - l + 2) * x <= m) add(f[i + 1][j + 1][k + (2 * j - l + 2) * x][l], mul(f[i][j][k][l], j - l + 1)); if (l < 2 && k + (2 * j - l + 1) * x <= m) add(f[i + 1][j + 1][k + (2 * j - l + 1) * x][l + 1], mul(f[i][j][k][l], 2 - l)); if (k + (2 * j - l) * x <= m) add(f[i + 1][j][k + (2 * j - l) * x][l], mul(f[i][j][k][l], 2 * j - l)); if (l < 2 && k + (2 * j - l - 1) * x <= m) add(f[i + 1][j][k + (2 * j - l - 1) * x][l + 1], mul(f[i][j][k][l], 2 - l)); if (j - 1 > 0 && k + (2 * j - l - 2) * x <= m) add(f[i + 1][j - 1][k + (2 * j - l - 2) * x][l], mul(f[i][j][k][l], j - 1)); } } } } int ans = 0; for (int i = 0; i <= m; ++i) add(ans, f[n][1][i][2]); cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...