Submission #975203

#TimeUsernameProblemLanguageResultExecution timeMemory
975203Beerus13Skyscraper (JOI16_skyscraper)C++14
100 / 100
134 ms51648 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 1e2 + 5; const int mod = 1e9 + 7; void add(int &a, int b) { a += b; if(a >= mod) a -= mod; if(a < 0) a += mod; } int n, L, a[N]; int dp[N][N][N * 10][3]; void solve() { cin >> n >> L; for(int i = 1; i <= n; ++i) cin >> a[i]; if(n == 1) return cout << 1 << '\n', void(); sort(a + 1, a + n + 1); dp[1][1][0][0] = 1; dp[1][1][0][1] = 2; for(int i = 2; i <= n; ++i) { for(int j = 0; j <= i; ++j) { for(int k = 0; k <= L; ++k) { for(int z = 0; z <= 2; ++z) { int cost = (2 * j - z) * (a[i] - a[i - 1]); if(k + cost > L) continue; // connect 2 components if(j) add(dp[i][j - 1][k + cost][z], 1ll * (j - 1) * dp[i - 1][j][k][z] % mod); // add a[i] at the beginning or end of one comp of permutation but don't lock add(dp[i][j][k + cost][z], 1ll * (2 * j - z) * dp[i - 1][j][k][z] % mod); // add a[i] at the beginning or end of one comp of permutation and lock if(z < 2) add(dp[i][j][k + cost][z + 1], 1ll * (2 - z) * dp[i - 1][j][k][z] % mod); // create new component // add a[i] at the beginning or end of permutation but don't lock add(dp[i][j + 1][k + cost][z], 1ll * (2 - z) * dp[i - 1][j][k][z] % mod); // add a[i] at the beginning or end of permutation and lock if(z < 2) add(dp[i][j + 1][k + cost][z + 1], 1ll * (2 - z) * dp[i - 1][j][k][z] % mod); // add a[i] as a middle component if(j >= 2) add(dp[i][j + 1][k + cost][z], 1ll * (j - 1) * dp[i - 1][j][k][z] % mod); } } } } int res = 0; for(int i = 0; i <= L; ++i) { add(res, dp[n][1][i][2]); } cout << res << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int test = 1; // cin >> test; while(test--) solve(); return 0; } // https://oj.uz/problem/view/JOI16_skyscraper
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...