Submission #328740

#TimeUsernameProblemLanguageResultExecution timeMemory
328740EndRaySkyscraper (JOI16_skyscraper)C++17
100 / 100
285 ms128128 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; const int N = 100+1, L = 1000+1, mod = 1e9+7; int n, l; int a[N]; ll dp[N][N][L][3]; int main(){ ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> n >> l; for(int i = 0; i < n; ++i) cin >> a[i]; if(n == 1){ cout << "1\n"; return 0; } sort(a, a+n); a[n] = L; dp[0][0][0][0] = 1; for(int i = 1; i <= n; ++i){ for(int j = 1; j <= n; ++j){ for(int k = 0; k <= l; ++k){ int dif; // e = 0 dif = 2*j*(a[i]-a[i-1]); if(dif <= k){ dp[i][j][k][0] = (dp[i][j][k][0] + dp[i-1][j-1][k - dif][0]*j)%mod; dp[i][j][k][0] = (dp[i][j][k][0] + dp[i-1][j][k - dif][0]*2*j)%mod; dp[i][j][k][0] = (dp[i][j][k][0] + dp[i-1][j+1][k - dif][0]*j)%mod; } // e = 1 dif = (2*j - 1)*(a[i] - a[i-1]); if(dif <= k){ dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j-1][k - dif][0]*2)%mod; dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j][k - dif][0]*2)%mod; dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j-1][k - dif][1]*(j-1))%mod; dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j][k - dif][1]*(2*j-1))%mod; dp[i][j][k][1] = (dp[i][j][k][1] + dp[i-1][j+1][k - dif][1]*j)%mod; } // e = 2 dif = (2*j - 2)*(a[i] - a[i-1]); if(dif <= k){ dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j-1][k - dif][1])%mod; dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j][k - dif][1])%mod; dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j-1][k - dif][2]*(j-2))%mod; dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j][k - dif][2]*(2*j-2))%mod; dp[i][j][k][2] = (dp[i][j][k][2] + dp[i-1][j+1][k - dif][2]*j)%mod; } } } } ll ans = 0; for(int i = 0; i <= l; ++i) ans = (ans + dp[n][1][i][2])%mod; cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...