Submission #873930

# Submission time Handle Problem Language Result Execution time Memory
873930 2023-11-16T02:51:37 Z noiaint Skyscraper (JOI16_skyscraper) C++17
100 / 100
215 ms 347728 KB
#include <bits/stdc++.h>

using namespace std;

#define file ""

#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()

#define getbit(x, i) (((x) >> (i)) & 1)
#define bit(x) (1LL << (x))
#define popcount __builtin_popcountll

mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
    return l + rd() % (r - l + 1);
}

const int N = 1e6 + 5;
const int mod = (int)1e9 + 7; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;

template<class X, class Y> bool mini(X &a, Y b) {
    return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
    return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

int n, L;
int a[N];
long long f[105][105][1005][2][2];

long long calc(int i, int j, int s, int l, int r) {
    int news = s + (j * 2 + l + r) * (a[i] - a[i - 1]);
    if (news > L) return 0;
    if (j < 0) return 0;
    if (i == n) return j == 0;

    long long &res = f[i][j][s][l][r];
    if (res != -1) return res;
    res = 0;

    res += calc(i + 1, j, news, 1, r); // append to the left
    res += calc(i + 1, j - 1, news, 1, r) * j; // append to the left and merge

    res += calc(i + 1, j, news, l, 1); // append to the right
    res += calc(i + 1, j - 1, news, l, 1) * j; // append to the right and merge

    res += calc(i + 1, j + 1, news, l, r); // new one
    res += calc(i + 1, j, news, l, r) * j * 2; // append
    res += calc(i + 1, j - 1, news, l, r) * j * (j - 1); // merge

    res %= mod;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    // freopen(file".inp", "r", stdin);
    // freopen(file".out", "w", stdout);

    cin >> n >> L;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    a[0] = a[1];

    memset(f, -1, sizeof f);
    cout << calc(1, 0, 0, 0, 0);

    return 0;
}

/*

*/
# Verdict Execution time Memory Grader output
1 Correct 88 ms 347728 KB Output is correct
2 Correct 90 ms 347388 KB Output is correct
3 Correct 89 ms 347164 KB Output is correct
4 Correct 89 ms 347220 KB Output is correct
5 Correct 89 ms 347220 KB Output is correct
6 Correct 90 ms 347264 KB Output is correct
7 Correct 89 ms 347220 KB Output is correct
8 Correct 91 ms 347284 KB Output is correct
9 Correct 90 ms 347404 KB Output is correct
10 Correct 90 ms 347220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 347280 KB Output is correct
2 Correct 90 ms 347300 KB Output is correct
3 Correct 89 ms 347216 KB Output is correct
4 Correct 89 ms 347220 KB Output is correct
5 Correct 89 ms 347216 KB Output is correct
6 Correct 92 ms 347260 KB Output is correct
7 Correct 88 ms 347340 KB Output is correct
8 Correct 89 ms 347220 KB Output is correct
9 Correct 89 ms 347216 KB Output is correct
10 Correct 98 ms 347232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 347728 KB Output is correct
2 Correct 90 ms 347388 KB Output is correct
3 Correct 89 ms 347164 KB Output is correct
4 Correct 89 ms 347220 KB Output is correct
5 Correct 89 ms 347220 KB Output is correct
6 Correct 90 ms 347264 KB Output is correct
7 Correct 89 ms 347220 KB Output is correct
8 Correct 91 ms 347284 KB Output is correct
9 Correct 90 ms 347404 KB Output is correct
10 Correct 90 ms 347220 KB Output is correct
11 Correct 96 ms 347280 KB Output is correct
12 Correct 90 ms 347300 KB Output is correct
13 Correct 89 ms 347216 KB Output is correct
14 Correct 89 ms 347220 KB Output is correct
15 Correct 89 ms 347216 KB Output is correct
16 Correct 92 ms 347260 KB Output is correct
17 Correct 88 ms 347340 KB Output is correct
18 Correct 89 ms 347220 KB Output is correct
19 Correct 89 ms 347216 KB Output is correct
20 Correct 98 ms 347232 KB Output is correct
21 Correct 90 ms 347532 KB Output is correct
22 Correct 215 ms 347404 KB Output is correct
23 Correct 182 ms 347416 KB Output is correct
24 Correct 184 ms 347220 KB Output is correct
25 Correct 182 ms 347216 KB Output is correct
26 Correct 166 ms 347220 KB Output is correct
27 Correct 125 ms 347476 KB Output is correct
28 Correct 128 ms 347412 KB Output is correct
29 Correct 180 ms 347220 KB Output is correct
30 Correct 186 ms 347412 KB Output is correct