Submission #1255245

#TimeUsernameProblemLanguageResultExecution timeMemory
1255245dbenceSkyscraper (JOI16_skyscraper)C++20
100 / 100
109 ms120336 KiB
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() #define len(x) (x).size() #define lsb(x) (x) & (-x) #define l(x) (x << 1) + 1 #define r(x) (x << 1) + 2 #define mp make_pair #define xx first #define yy second #define pb push_back #define lb lower_bound #define ub upper_bound using namespace std; typedef long long ll; typedef pair<int, int> pii; template <typename T> void print(T t) { cout << t << "\n"; } template <typename T, typename... Args> void print(T t, Args ...args) { cout << t << " "; print(args...); } const int N = 101; const int M = 1001; const int mod = 1e9 + 7; int n, h, a[N], dp[N][N][M][3]; int calc(int i, int j, int k, int f) { if (f >= 3) { return 0; } if (j == 0) { return 0; } if (k > h) { return 0; } if (i > n) { return j == 1 && f == 2; } if (dp[i][j][k][f] != -1) { return dp[i][j][k][f]; } int res = 0, remk = k + (a[i] - a[i - 1]) * (2 * j - f); res += 1ll * calc(i + 1, j + 1, remk, f) * (j + 1 - f) % mod; res += 1ll * calc(i + 1, j + 1, remk, f + 1) * (2 - f) % mod; res %= mod; res += 1ll * calc(i + 1, j - 1, remk, f) * (j - 1) % mod; res %= mod; res += 1ll * calc(i + 1, j, remk, f) * (2 * j - f) % mod; res %= mod; res += 1ll * calc(i + 1, j, remk, f + 1) * (2 - f) % mod; res %= mod; return dp[i][j][k][f] = res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> h; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); memset(dp, -1, sizeof dp); cout << (calc(2, 1, 0, 0) + 2ll * calc(2, 1, 0, 1) + calc(2, 1, 0, 2)) % mod << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...