Submission #23300

#TimeUsernameProblemLanguageResultExecution timeMemory
23300duongthoi1999Skyscraper (JOI16_skyscraper)C++14
100 / 100
76 ms4768 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef long long ll; typedef long double ld; typedef pair<ll, int> ii; const int mod = (int) 1e9 + 7; const ll inf = 1LL << 60; const int maxn = (int) 105; const ld eps = 1e-9; void add(int &a, ll b) { b %= mod; a += b; while (a >= mod) a -= mod; } int n, L, a[maxn]; int f[2][maxn][maxn * 10][3]; void trau() { int cnt = 0; do { int res = 0; rep(i, 1, n) res += abs(a[i] - a[i + 1]); if(res <= L) cnt ++; } while (next_permutation(a + 1, a + 1 + n)); cout << cnt << endl; } int main() { //freopen("test.txt", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> L; rep(i, 1, n + 1) cin >> a[i]; sort(a + 1, a + 1 + n); a[n + 1] = 12345; if(a[2] - a[1] <= L) f[1][1][a[2] - a[1]][1] = 2; if(2 * (a[2] - a[1]) <= L) f[1][1][2 * (a[2] - a[1])][0] = 1; rep(i, 1, n) { int d = a[i + 2] - a[i + 1]; rep(j, 1, i + 1) { rep(k, 0, L + 1) { rep(e, 0, min(j + 1, 3)) { if(!f[i & 1][j][k][e]) continue; if(e < 2) { if(k + (2 * (j + 1) - (e + 1)) * d <= L) add(f[(i + 1) & 1][j + 1][k + (2 * (j + 1) - (e + 1)) * d][e + 1], (2 - e) * f[i & 1][j][k][e]); if(k + (2 * j - (e + 1)) * d <= L) add(f[(i + 1) & 1][j][k + (2 * j - (e + 1)) * d][e + 1], (2 - e) * f[i & 1][j][k][e]); } if(k + (2 * (j + 1) - e) * d <= L) add(f[(i + 1) & 1][j + 1][k + (2 * (j + 1) - e) * d][e], 1LL * (j - e + 1) * f[i & 1][j][k][e]); if(k + (2 * j - e) * d <= L) add(f[(i + 1) & 1][j][k + (2 * j - e) * d][e], 1LL * (2 * j - e) * f[i & 1][j][k][e]); if(j > 1 && k + (2 * (j - 1) - e) * d <= L) add(f[(i + 1) & 1][j - 1][k + (2 * (j - 1) - e) * d][e], 1LL * (j - 1) * f[i & 1][j][k][e]); } } } memset(f[i & 1], 0, sizeof f[i & 1]); } int res = 0; rep(i, 0, L + 1) add(res, f[n & 1][1][i][2]); if(n == 1) res = 1; cout << res << endl; //trau(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...