Submission #883315

#TimeUsernameProblemLanguageResultExecution timeMemory
883315phoenix0423Skyscraper (JOI16_skyscraper)C++17
100 / 100
174 ms145160 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) // #pragma GCC optimize("Ofast") #define FOR(i, a, b) for(int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 0, n + 1) #define SZ(x) (int)(x).size() #define pb push_back #define pf push_front #define eb emplace_back #define f first #define s second #define lowbit(x) x&-x #define ckmin(a, b) a = min(a, b) #define ckmax(a, b) a = max(a, b) #define int long long const int INF = 1e18; const int maxn = 1000 + 5; const int N = 1e9 + 7; ll dp[105][105][2005][3]; signed main(void){ fastio; int n, L; cin>>n>>L; vector<int> a(n); for(int i = 0; i < n; i++) cin>>a[i]; if(n == 1){ cout<<1<<"\n"; return 0; } sort(a.begin(), a.end()); a.pb(a[n - 1]); dp[0][0][0][0] = 1; for(int i = 0; i < n; i++){ for(int j = 0; j <= i; j++){ for(int k = 0; k <= L; k++){ for(int l = 0; l <= 2; l++){ dp[i][j][k][l] %= N; if(k + (2 * j - 2 - l) * (a[i + 1] - a[i]) > L) continue; if(j) (dp[i + 1][j][k + (2 * j - l) * (a[i + 1] - a[i])][l] += dp[i][j][k][l] * (2 * j - l)) %= N; (dp[i + 1][j + 1][k + (2 * j + 2 - l) * (a[i + 1] - a[i])][l] += dp[i][j][k][l] * (j + 1 - l)) %= N; if(j > 1) (dp[i + 1][j - 1][k + (2 * j - 2 - l) * (a[i + 1] - a[i])][l] += dp[i][j][k][l] * (j - 1)) %= N; if(l != 2){ (dp[i + 1][j][k + (2 * j - (l + 1)) * (a[i + 1] - a[i])][l + 1] += dp[i][j][k][l] * (2 - l)) %= N; (dp[i + 1][j + 1][k + (2 * j + 2 - (l + 1)) * (a[i + 1] - a[i])][l + 1] += dp[i][j][k][l] * (2 - l)) %= N; } // if(dp[i][j][k][l]) cout<<i<<" "<<j<<" "<<k<<" "<<l<<" : "<<dp[i][j][k][l]<<"\n"; } } } } ll ans = 0; // for(int i = 0; i <= L; i++) (ans += dp[n - 1][2][i][2]) %= N; // for(int i = 0; i <= L; i++) (ans += dp[n - 1][1][i][1]) %= N; for(int i = 0; i <= L; i++) (ans += dp[n][1][i][2]) %= N; cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...