답안 #854789

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854789 2023-09-29T00:53:05 Z wakandaaa Skyscraper (JOI16_skyscraper) C++17
100 / 100
158 ms 347584 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;
}

/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 347216 KB Output is correct
2 Correct 39 ms 347220 KB Output is correct
3 Correct 37 ms 347224 KB Output is correct
4 Correct 37 ms 347216 KB Output is correct
5 Correct 37 ms 347228 KB Output is correct
6 Correct 38 ms 347348 KB Output is correct
7 Correct 40 ms 347220 KB Output is correct
8 Correct 38 ms 347224 KB Output is correct
9 Correct 37 ms 347216 KB Output is correct
10 Correct 37 ms 347220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 347344 KB Output is correct
2 Correct 37 ms 347176 KB Output is correct
3 Correct 38 ms 347216 KB Output is correct
4 Correct 37 ms 347220 KB Output is correct
5 Correct 40 ms 347476 KB Output is correct
6 Correct 37 ms 347216 KB Output is correct
7 Correct 37 ms 347220 KB Output is correct
8 Correct 37 ms 347220 KB Output is correct
9 Correct 39 ms 347364 KB Output is correct
10 Correct 37 ms 347228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 347216 KB Output is correct
2 Correct 39 ms 347220 KB Output is correct
3 Correct 37 ms 347224 KB Output is correct
4 Correct 37 ms 347216 KB Output is correct
5 Correct 37 ms 347228 KB Output is correct
6 Correct 38 ms 347348 KB Output is correct
7 Correct 40 ms 347220 KB Output is correct
8 Correct 38 ms 347224 KB Output is correct
9 Correct 37 ms 347216 KB Output is correct
10 Correct 37 ms 347220 KB Output is correct
11 Correct 37 ms 347344 KB Output is correct
12 Correct 37 ms 347176 KB Output is correct
13 Correct 38 ms 347216 KB Output is correct
14 Correct 37 ms 347220 KB Output is correct
15 Correct 40 ms 347476 KB Output is correct
16 Correct 37 ms 347216 KB Output is correct
17 Correct 37 ms 347220 KB Output is correct
18 Correct 37 ms 347220 KB Output is correct
19 Correct 39 ms 347364 KB Output is correct
20 Correct 37 ms 347228 KB Output is correct
21 Correct 38 ms 347228 KB Output is correct
22 Correct 158 ms 347500 KB Output is correct
23 Correct 121 ms 347220 KB Output is correct
24 Correct 142 ms 347584 KB Output is correct
25 Correct 127 ms 347412 KB Output is correct
26 Correct 132 ms 347436 KB Output is correct
27 Correct 63 ms 347412 KB Output is correct
28 Correct 73 ms 347368 KB Output is correct
29 Correct 128 ms 347408 KB Output is correct
30 Correct 153 ms 347412 KB Output is correct