Submission #468133

#TimeUsernameProblemLanguageResultExecution timeMemory
468133sinamhdvSkyscraper (JOI16_skyscraper)C++11
100 / 100
146 ms5532 KiB
// JOI16_skyscraper #include <bits/stdc++.h> using namespace std; #define int ll typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1e9 + 100; const ll LINF = 1e18 + 100; #ifdef DEBUG #define dbg(x) cout << #x << " = " << (x) << endl << flush; #define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; } #else #define dbg(x) ; #define dbgr(s, f) ; #endif #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define fr first #define sc second #define all(x) (x).begin(), (x).end() #define endl '\n' const int MAXN = 110; const int MAXL = 1010; int n, L, a[MAXN]; int dp[2][MAXN][MAXL][3]; inline void relax(int i, int j, int k, int l, ll val) { if (k < 0 || k >= MAXL) return; dp[i][j][k][l] = (dp[i][j][k][l] + val) % mod; } int32_t main(void) { fast_io; cin >> n >> L; if (n == 1) return cout << "1\n", 0; FOR(i, 1, n + 1) cin >> a[i]; sort(a + 1, a + n + 1); // base FOR(k, 0, MAXL) { dp[1][1][k][0] = 1; dp[1][1][k][1] = 1; } // dp FOR(i, 1, n) { int p = i % 2, c = 1 - p; int dif = a[i + 1] - a[i]; memset(dp[c], 0, sizeof(dp[c])); FOR(j, 1, i + 1) { FOR(k, 0, MAXL) { relax(c, j + 1, k + 2 * j * dif, 0, (j + 1) * (ll)dp[p][j][k][0]); relax(c, j, k + 2 * j * dif, 0, 2 * j * (ll)dp[p][j][k][0]); relax(c, j - 1, k + 2 * j * dif, 0, (j - 1) * (ll)dp[p][j][k][0]); relax(c, j + 1, k + (2 * j - 1) * dif, 1, j * (ll)dp[p][j][k][1]); relax(c, j + 1, k + 2 * j * dif, 1, dp[p][j][k][0]); relax(c, j, k + (2 * j - 1) * dif, 1, (2 * j - 1) * (ll)dp[p][j][k][1]); relax(c, j, k + 2 * j * dif, 1, dp[p][j][k][0]); relax(c, j - 1, k + (2 * j - 1) * dif, 1, (j - 1) * (ll)dp[p][j][k][1]); relax(c, j + 1, k + (2 * j - 2) * dif, 2, (j - 1) * (ll)dp[p][j][k][2]); relax(c, j + 1, k + (2 * j - 1) * dif, 2, 2ll * dp[p][j][k][1]); relax(c, j, k + (2 * j - 2) * dif, 2, (2 * j - 2) * (ll)dp[p][j][k][2]); relax(c, j, k + (2 * j - 1) * dif, 2, 2ll * dp[p][j][k][1]); relax(c, j - 1, k + (2 * j - 2) * dif, 2, (j - 1) * (ll)dp[p][j][k][2]); } } if (i + 1 < n) { FOR(k, 0, MAXL) dp[c][1][k][2] = 0; } } int ans = dp[n % 2][1][L][2]; ans = (mod + ans % mod) % mod; cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...