답안 #576077

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576077 2022-06-12T09:12:22 Z hoainiem Skyscraper (JOI16_skyscraper) C++14
100 / 100
261 ms 184396 KB
#include <bits/stdc++.h>
//#pragma GCC target("popcnt")
#define fi first
#define se second
#define lc id<<1
#define rc id<<1^1
#define val f[i][j][s][cl][cr]
const int mod = 1e9 + 7;
double begintime, endtime;

using namespace std;
inline void CALC_TIME()
{
    endtime = clock();
    cout << "\nexecution time : " << (endtime - begintime + 1) / 1000 << " s";
}
void add(int &x, int y)
{
    x += y;
    if (x >= mod)
        x -= mod;
}
int mul(int x, int y)
{
    return 1LL * x * y % mod;
}
typedef pair<int, int> pii;
int n, k, a[108], f[108][108][1008][2][2];
int dq(int i, int j, int s, int cl, int cr)
{
    if (s > k || (!j && i))
        return 0;
    if (val != -1)
        return val;
    if (i >= n)
        return val = (j == 1 && cl && cr);
    int res = 0;
    add(res, mul(j + 1 - cl - cr, dq(i + 1, j + 1, s + (j * 2 + 2 - cl - cr) * a[i + 1], cl, cr)));
    if (!cl)
        add(res, dq(i + 1, j + 1, s + (j * 2 + 1 - cr) * a[i + 1], 1, cr));
    if (!cr)
        add(res, dq(i + 1, j + 1, s + (j * 2 + 1 - cl) * a[i + 1], cl, 1));
    if (j > 0)
        add(res, mul(j * 2 - cl - cr, dq(i + 1, j, s + (j * 2 - cl - cr) * a[i + 1], cl, cr)));
    if (!cl)
        add(res, dq(i + 1, j, s + (j * 2 - 1 - cr) * a[i + 1], 1, cr));
    if (!cr)
        add(res, dq(i + 1, j, s + (j * 2 - 1 - cl) * a[i + 1], cl, 1));
    if (j > 1)
        add(res, mul(j - 1, dq(i + 1, j - 1, s + (j * 2 - 2 - cl - cr) * a[i + 1], cl, cr)));
    return val = res;
}   
int main()
{
    begintime = clock();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(f, -1, sizeof(f));
    cin >> n >> k;
    if (n == 1)
    {
        cout << 1;
        return 0;
    }
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    a[n] = 0;
    for (int i = n - 1; i > 0; i--)
        a[i] -= a[i - 1];
    a[0] = 0;
    cout << dq(0, 0, 0, 0, 0);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 184256 KB Output is correct
2 Correct 73 ms 184304 KB Output is correct
3 Correct 73 ms 184284 KB Output is correct
4 Correct 70 ms 184308 KB Output is correct
5 Correct 69 ms 184344 KB Output is correct
6 Correct 68 ms 184376 KB Output is correct
7 Correct 70 ms 184344 KB Output is correct
8 Correct 72 ms 184280 KB Output is correct
9 Correct 76 ms 184340 KB Output is correct
10 Correct 72 ms 184372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 184244 KB Output is correct
2 Correct 67 ms 184280 KB Output is correct
3 Correct 82 ms 184276 KB Output is correct
4 Correct 68 ms 184356 KB Output is correct
5 Correct 72 ms 184280 KB Output is correct
6 Correct 68 ms 184268 KB Output is correct
7 Correct 67 ms 184348 KB Output is correct
8 Correct 70 ms 184252 KB Output is correct
9 Correct 69 ms 184348 KB Output is correct
10 Correct 70 ms 184304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 184256 KB Output is correct
2 Correct 73 ms 184304 KB Output is correct
3 Correct 73 ms 184284 KB Output is correct
4 Correct 70 ms 184308 KB Output is correct
5 Correct 69 ms 184344 KB Output is correct
6 Correct 68 ms 184376 KB Output is correct
7 Correct 70 ms 184344 KB Output is correct
8 Correct 72 ms 184280 KB Output is correct
9 Correct 76 ms 184340 KB Output is correct
10 Correct 72 ms 184372 KB Output is correct
11 Correct 67 ms 184244 KB Output is correct
12 Correct 67 ms 184280 KB Output is correct
13 Correct 82 ms 184276 KB Output is correct
14 Correct 68 ms 184356 KB Output is correct
15 Correct 72 ms 184280 KB Output is correct
16 Correct 68 ms 184268 KB Output is correct
17 Correct 67 ms 184348 KB Output is correct
18 Correct 70 ms 184252 KB Output is correct
19 Correct 69 ms 184348 KB Output is correct
20 Correct 70 ms 184304 KB Output is correct
21 Correct 70 ms 184372 KB Output is correct
22 Correct 261 ms 184276 KB Output is correct
23 Correct 115 ms 184380 KB Output is correct
24 Correct 129 ms 184380 KB Output is correct
25 Correct 140 ms 184296 KB Output is correct
26 Correct 126 ms 184268 KB Output is correct
27 Correct 94 ms 184348 KB Output is correct
28 Correct 112 ms 184384 KB Output is correct
29 Correct 165 ms 184396 KB Output is correct
30 Correct 118 ms 184328 KB Output is correct