Submission #1046800

#TimeUsernameProblemLanguageResultExecution timeMemory
1046800idiotcomputerSkyscraper (JOI16_skyscraper)C++11
100 / 100
176 ms238788 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int const ll mod = 1e9+7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,l; cin >> n >> l; vector<int> h(n); for (int i = 0; i < n; i++) cin >> h[i]; sort(h.begin(),h.end()); ll dp[n][n+1][1005][3]; memset(dp,0,sizeof(dp)); dp[0][1][0][2] = 1; dp[0][1][0][1] = 2; int v; for (int i = 0; i < n-1; i++){ for (int j = 1; j < n; j++){ for (int k = 0; k <= l; k++){ for (int t = 0; t < 3; t++){ dp[i][j][k][t] = (dp[i][j][k][t])%mod; v = (h[i+1]-h[i]) * (2*j-(2-t)); //if (k+v > l && dp[i][j][k][t] > 0) cout << i << " " << j << " " << k << ' ' << t << " " << v << '\n'; if (k + v > l) continue; // cout << t << " " << v << ' ' << j << ' ' << i << ' ' << k << '\n'; //appending dp[i+1][j][k+v][t] += dp[i][j][k][t] * (2*j-(2-t)); if (t > 0) dp[i+1][j][k+v][t-1] += dp[i][j][k][t] * (t) * (j+t-2); if (t == 1 && i == n-2) dp[i+1][j][k+v][t-1] += dp[i][j][k][t]; //combining dp[i+1][j-1][k+v][t] += dp[i][j][k][t] * (j-1) * (j-2+t); if (i == n-2 && t == 0) dp[i+1][j-1][k+v][t] += dp[i][j][k][t]; //new cc dp[i+1][j+1][k+v][t] += dp[i][j][k][t]; if (t != 0) dp[i+1][j+1][k+v][t-1] += dp[i][j][k][t] * (t); } } } } if (n == 1) dp[0][1][0][0] = 1; ll res = 0; for (int i = 0; i <= l; i++) res = (res + dp[n-1][1][i][0]) % mod; //for (int i = 0; i <= l; i++) cout << dp[n-1][1][i][0] << " "; // cout << dp[n-2][1][7][1] << "\n"; // cout << '\n'; cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...