Submission #1124762

#TimeUsernameProblemLanguageResultExecution timeMemory
1124762pemguimnSkyscraper (JOI16_skyscraper)C++20
20 / 100
423 ms589824 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 1e2 + 5, S = 2e4 + 5, SHIFT = 1e3 + 5, MOD = 1e9 + 7; int n, s, a[N]; namespace sub3{ void solve(){ int sum = 0; for(int i = 1; i <= n; i++) sum += a[i]; int shift = -sum, lim; sum *= 2, lim = sum; vector<vector<vector<vector<int>>>> dp(3, vector<vector<vector<int>>>(n + 1, vector<vector<int>>(n + 1, vector<int>(lim + 1, 0)))); dp[0][0][0][0 - shift] = 1; sum = 0; for(int i = 1; i <= n; i++){ for(int cc = 1; cc <= i; cc++){ for(int j = 0; j <= lim; j++){ if(j - 2 * a[i] >= 0){ // Create for(int k = 0; k < 3; k++){ if(j + 2 * a[i] <= lim) (dp[k][i][cc][j] += dp[k][i - 1][cc - 1][j + 2 * a[i]] * (cc - k)) %= MOD; if(k >= 1 && j + a[i] <= lim) (dp[k][i][cc][j] += dp[k - 1][i - 1][cc - 1][j + a[i]] * (2 - k + 1)) %= MOD; } } if(cc){ // Append for(int k = 0; k < 3; k++){ (dp[k][i][cc][j] += dp[k][i - 1][cc][j] * (2 * cc - k)) %= MOD; if(k >= 1 && j >= a[i]) (dp[k][i][cc][j] += dp[k - 1][i - 1][cc][j - a[i]] * (2 - k + 1)) %= MOD; } } // Merge if(cc <= (n + 1) / 2){ for(int k = 0; k < 3; k++){ if(j >= 2 * a[i]) (dp[k][i][cc][j] += dp[k][i - 1][cc + 1][j - 2 * a[i]] * cc) %= MOD; } } // for(int k = 0; k < 3; k++){ // if(dp[k][i][cc][j]) cout << i << ' ' << k << ' ' << cc << ' ' << j << ' ' << dp[k][i][cc][j] << '\n'; // } } } } int ans = 0; for(int i = 0 - shift; i <= s - shift; i++){ (ans += dp[2][n][1][i]) %= MOD; // cout << i + shift << ' ' << dp[2][n][1][i] << '\n'; } cout << ans << '\n'; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> s; if(n == 1){ cout << 1 << '\n'; return 0; } for(int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1); return sub3::solve(), 0; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...