Submission #362230

#TimeUsernameProblemLanguageResultExecution timeMemory
362230AlexLuchianovSkyscraper (JOI16_skyscraper)C++14
100 / 100
678 ms3692 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <cassert> using ll = long long ; #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) < (b)) ? (b) : (a)) int const nmax = 100; int const lmax = 1000; int const modulo = 1000000007; int dp[5 + nmax][5 + lmax][2][2]; int dp2[5 + nmax][5 + lmax][2][2]; int v[1 + nmax]; void norm(int &aux) { if(modulo <= aux) aux -= modulo; } int main() { int n, target; std::cin >> n >> target; for(int i = 1;i <= n; i++) std::cin >> v[i]; std::sort(v + 1, v + n + 1); for(int h = 0; h < 2; h++) for(int h2 = 0; h2 < 2; h2++) dp[0][0][h][h2] = 1; for(int phase = 2; phase <= n; phase++) { for(int i = 0; i <= n; i++) for(int j = 0; j <= target; j++) for(int h = 0; h < 2; h++) for(int h2 = 0; h2 < 2; h2++) { int bonus = (i * 2 + h + h2) * (v[phase] - v[phase - 1]); if(j + bonus <= target) { dp2[i][j + bonus][h][h2] += dp[i][j][h][h2]; norm(dp2[i][j + bonus][h][h2]); } } for(int i = 0; i <= n; i++) for(int j = 0; j <= target; j++) for(int h = 0; h < 2; h++) for(int h2 = 0; h2 < 2; h2++) { dp[i][j][h][h2] = dp2[i][j][h][h2]; dp2[i][j][h][h2] = 0; } for(int i = 0; i <= n; i++) for(int j = 0; j <= target; j++) for(int h = 0; h < 2; h++) for(int h2 = 0; h2 < 2; h2++) { if(0 < i) { dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] * i % modulo; norm(dp2[i + 1][j][h][h2]); dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] * i * 2 % modulo; norm(dp2[i][j][h][h2]); dp2[i - 1][j][h][h2] += 1LL * dp[i][j][h][h2] * i % modulo; norm(dp2[i - 1][j][h][h2]); } if(h == 1) { dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo; norm(dp2[i][j][h][h2]); dp2[i][j][0][h2] += 1LL * dp[i][j][h][h2] % modulo; norm(dp2[i][j][0][h2]); dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo; norm(dp2[i + 1][j][h][h2]); dp2[i + 1][j][0][h2] += 1LL * dp[i][j][h][h2] % modulo; norm(dp2[i + 1][j][0][h2]); } if(h2 == 1) { dp2[i][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo; norm(dp2[i][j][h][h2]); dp2[i][j][h][0] += 1LL * dp[i][j][h][h2] % modulo; norm(dp2[i][j][h][0]); dp2[i + 1][j][h][h2] += 1LL * dp[i][j][h][h2] % modulo; norm(dp2[i + 1][j][h][h2]); dp2[i + 1][j][h][0] += 1LL * dp[i][j][h][h2] % modulo; norm(dp2[i + 1][j][h][0]); } } for(int i = 0; i <= n; i++) for(int j = 0; j <= target; j++) for(int h = 0; h < 2; h++) for(int h2 = 0; h2 < 2; h2++) { dp[i][j][h][h2] = dp2[i][j][h][h2]; dp2[i][j][h][h2] = 0; } } int result = 0; for(int j = 0; j <= target; j++) { result += dp[0][j][0][0]; if(modulo <= result) result -= modulo; } std::cout << result; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...