Submission #1124750

#TimeUsernameProblemLanguageResultExecution timeMemory
1124750IcelastSkyscraper (JOI16_skyscraper)C++17
15 / 100
1 ms584 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long #define int long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9, mod = 1e9+7; ll f[102][102][1002][3]; void solve(){ int n, s; cin >> n >> s; vector<ll> h(n+1); for(int i = 1; i <= n; i++){ cin >> h[i]; } sort(h.begin()+1, h.end()); f[0][0][0][0] = 1; h.push_back(10000); for(int i = 1; i <= n; i++){ for(int j = 1; j <= i; j++){ for(int k = 0; k <= s; k++){ for(int m = 0; m <= 2; m++){ ll cost = (j*2-m)*(h[i+1]-h[i]); if(k-cost < 0 || i+j+1-m > n) continue; f[i][j][k][m] += f[i-1][j-1][k-cost][m]; if(m) f[i][j][k][m] += f[i-1][j-1][k-cost][m-1] * (3-m) % mod; f[i][j][k][m] += f[i-1][j][k-cost][m] * (j*2-m) % mod; if(m == 1){ f[i][j][k][m] += f[i-1][j][k-cost][m-1] * (j*2); }else if(m == 2){ if(i == n){ f[i][j][k][m] += f[i-1][j][k-cost][m-1]; }else if(j > 1){ f[i][j][k][m] += f[i-1][j][k-cost][m-1] * (j-1) % mod; } } if(m == 0){ f[i][j][k][m] += f[i-1][j+1][k-cost][m] * (j*(j+1)%mod) % mod; }else if(m == 1){ f[i][j][k][m] += f[i-1][j+1][k-cost][m] * (j*j) % mod; }else if(m == 2){ if(i == n){ f[i][j][k][m] += f[i-1][j+1][k-cost][m]; }else{ f[i][j][k][m] += f[i-1][j+1][k-cost][m] * (j*(j-1)%mod); } } f[i][j][k][m] %= mod; } } } } ll ans = 0; for(int k = 0; k <= s; k++){ ans += f[n][1][k][2]; } ans %= mod; cout << ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...