제출 #1119280

#제출 시각아이디문제언어결과실행 시간메모리
1119280rahidilbayramliSkyscraper (JOI16_skyscraper)C++17
100 / 100
183 ms79432 KiB
#pragma GCC optimize("-O3") #include<bits/stdc++.h> #define ll long long #define ld long double #define vl vector<ll> #define vi vector<int> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back #define sz(v) (ll)(v.size()) #define f first #define s second #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; const ll mod = 1e9+7; ll dp[102][102][1002][3]; void solve() { ll n, l, i, j, h, k; cin >> n >> l; ll a[n+5]; for(i = 1; i <= n; i++) cin >> a[i]; if(n == 1) { cout << "1\n"; return; } sort(a+1, a+n+1); dp[0][0][0][0] = 1; a[n+1] = a[n]; for(i = 1; i <= n; i++) { ll diff = a[i+1] - a[i]; for(j = 0; j < i; j++) { for(h = 0; h <= l; h++) { for(k = 0; k < 3; k++) { ll tl = h + (2 * j + 2 - k) * diff; if(tl <= l) dp[i][j+1][tl][k] = ((((j + 1 - k) * dp[i-1][j][h][k]) % mod) + dp[i][j+1][tl][k]) % mod; if(k < 2) { tl = h + (2 * j + 1 - k) * diff; if(tl <= l) dp[i][j+1][tl][k+1] = ((((2 - k) * dp[i-1][j][h][k]) % mod) + dp[i][j+1][tl][k+1]) % mod; } if(j) { tl = h + (2 * j - k) * diff; if(tl <= l) dp[i][j][tl][k] = ((((2 * j - k) * dp[i-1][j][h][k]) % mod) + dp[i][j][tl][k]) % mod; if(k < 2) { tl = h + (2 * j - k - 1) * diff; if(tl <= l) dp[i][j][tl][k+1] = ((((2 - k) * dp[i-1][j][h][k]) % mod) + dp[i][j][tl][k+1]) % mod; } } if(j >= 2) { tl = h + (2 * j - 2 - k) * diff; if(tl <= l) dp[i][j-1][tl][k] = ((((j-1) * dp[i-1][j][h][k]) % mod) + dp[i][j-1][tl][k]) % mod; } } } } } ll res = 0; for(h = 0; h <= l; h++) { res += dp[n][1][h][2]; res %= mod; } cout << res << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll tests = 1; //cin >> tests; while(tests--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...