답안 #869644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869644 2023-11-05T07:20:46 Z sleepntsheep Skyscraper (JOI16_skyscraper) C++17
100 / 100
153 ms 5212 KB
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>

using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;

#define int long long
const ll M = 1'000'000'007;
int I, n, l, a[101], dp[2][101][1001][3], z, D;

inline int O(int j, int k, int l)
{
    k -= (2*j-l) * D;
    if (j < 0 || k < 0) return 0;
    return dp[!I][j][k][l];
}

signed main()
{
    ShinLena;
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a+1, a+n+1);
    dp[1][1][0][0] = 1;
    dp[1][1][0][1] = 2;
    for (int i = 2; i <= n; ++i, I ^= 1)
    {
        D = a[i] - a[i-1];
        memset(dp[I], 0, sizeof *dp);
        for (int j = 1; j <= i; ++j)
        {
            for (int k = 1; k <= l; ++k)
            {
                /* dp[I][j][k][0] */ {
                    int &d = dp[I][j][k][0];
                    (d += O(j+1, k, 0) * j % M) %= M;

                    (d += O(j-1, k, 0) * j % M) %= M;

                    (d += O(j+0, k, 0) * 2*j % M) %= M;
                }

                /* dp[I][j][k][1] */ {
                    int &d = dp[I][j][k][1];
                    (d += O(j+1, k, 1) * j % M) %= M;

                    (d += O(j-1, k, 1) * (j-1) % M) %= M;

                    (d += O(j+0, k, 1) * (2*j-1) % M) %= M;

                    (d += O(j-1, k, 0) * 2 % M) %= M;

                    (d += O(j+0, k, 0) * 2 % M) %= M;
                }

                /* dp[I][j][k][2] */ {

                    int &d = dp[I][j][k][2];
                    (d += O(j+1, k, 2) * j % M) %= M;

                    (d += O(j-1, k, 2) * (j-2) % M) %= M;

                    (d += O(j+0, k, 2) * (2*j-2) % M) %= M;

                    (d += O(j-1, k, 1) % M) %= M;

                    (d += O(j+0, k, 1) % M) %= M;
                }
            }
        }
    }

    for (int k = 0; k <= l; ++k) (z += dp[n&1][1][k][2] % M) %= M;
    cout << z + (n == 1);

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 2 ms 4996 KB Output is correct
6 Correct 4 ms 5208 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 2 ms 4996 KB Output is correct
6 Correct 4 ms 5208 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 5212 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 5212 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 4 ms 4956 KB Output is correct
22 Correct 117 ms 4956 KB Output is correct
23 Correct 149 ms 5180 KB Output is correct
24 Correct 138 ms 5200 KB Output is correct
25 Correct 153 ms 4956 KB Output is correct
26 Correct 144 ms 5180 KB Output is correct
27 Correct 53 ms 4956 KB Output is correct
28 Correct 65 ms 4956 KB Output is correct
29 Correct 125 ms 4952 KB Output is correct
30 Correct 151 ms 5184 KB Output is correct