Submission #1037127

#TimeUsernameProblemLanguageResultExecution timeMemory
1037127Shayan86Skyscraper (JOI16_skyscraper)C++14
100 / 100
57 ms79444 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") // Ofast, O0, O1, O2, O3, unroll-loops, fast-math, trapv typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define Mp make_pair #define sep ' ' #define endl '\n' #define F first #define S second #define pb push_back #define SZ(x) (int)x.size() #define all(x) (x).begin(),(x).end() #define kill(res) cout << res << '\n', exit(0); #define set_dec(x) cout << fixed << setprecision(x); #define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("input.txt", "r", stdin) ; freopen("output.txt", "w", stdout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll N = 109; const ll M = 1009; const ll Mod = 1e9 + 7; ll n, L, a[N], dp[N][N][M][3]; int main(){ fast_io; cin >> n >> L; for(int i = 1; i <= n; i++) cin >> a[i]; a[n+1] = 2e4; sort(a+1, a+n+1); if(n == 1) kill(1); dp[1][1][2*(a[2]-a[1])][0] = 1; dp[1][1][a[2]-a[1]][1] = 2; for(int i = 2; i <= n; i++){ for(int j = 1; j <= i; j++){ for(int k = 0; k <= L; k++){ for(int o = 0; o < 3; o++){ int dist = (a[i+1] - a[i]) * (2*j - o); if(k < dist) continue; dp[i][j][k][o] += (j-o) * dp[i-1][j-1][k-dist][o]; if(o) dp[i][j][k][o] += (3-o) * dp[i-1][j-1][k-dist][o-1]; dp[i][j][k][o] += (2*j-o) * dp[i-1][j][k-dist][o]; if(o) dp[i][j][k][o] += (3-o) * dp[i-1][j][k-dist][o-1]; dp[i][j][k][o] += j * dp[i-1][j+1][k-dist][o]; dp[i][j][k][o] %= Mod; } } } } ll res = 0; for(int k = 0; k <= L; k++) res += dp[n][1][k][2]; res %= Mod; cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...