답안 #503086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
503086 2022-01-07T06:45:49 Z qwerasdfzxcl Skyscraper (JOI16_skyscraper) C++14
100 / 100
209 ms 197684 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int MOD = 1e9+7;
ll dp[102][102][3][1002], a[102];

inline void add(ll &x, ll y){
    x += y;
    if (x>=MOD) x -= MOD;
}

int main(){
    int n, L;
    scanf("%d %d", &n, &L);
    for (int i=1;i<=n;i++) scanf("%lld", a+i);
    if (n==1) {printf("1\n"); return 0;}
    sort(a+1, a+n+1);

    dp[n-1][0][1][(a[n]-a[n-1])] = 1;
    if (a[n]-a[n-1]*2<=L) dp[n-1][0][2][(a[n]-a[n-1])*2] = 1;

    for (int i=n-2;i;i--){
        for (int j=0;j<=n;j++){
            int val0 = (a[i+1] - a[i]) * (j*2);
            int val1 = (a[i+1] - a[i]) * (j*2 + 1);
            int val2 = (a[i+1] - a[i]) * (j*2 + 2);

            if (j){
            for (int k=val0;k<=L;k++){
                add(dp[i][j][0][k], dp[i+1][j+1][0][k-val0] * (j+1) %MOD);
                add(dp[i][j][0][k], dp[i+1][j][0][k-val0] * (j*2) %MOD);
                add(dp[i][j][0][k], dp[i+1][j-1][0][k-val0] * (j-1) %MOD);

                add(dp[i][j][0][k], dp[i+1][j][1][k-val0] *2 %MOD);
                add(dp[i][j][0][k], dp[i+1][j-1][1][k-val0] *2 %MOD);
            }}

            for (int k=val1;k<=L;k++){
                add(dp[i][j][1][k], dp[i+1][j+1][1][k-val1] * (j+1) %MOD);
                add(dp[i][j][1][k], dp[i+1][j][1][k-val1] * (j*2+1) %MOD);
                if (j) add(dp[i][j][1][k], dp[i+1][j-1][1][k-val1] * j %MOD);

                add(dp[i][j][1][k], dp[i+1][j][2][k-val1]);
                if (j) add(dp[i][j][1][k], dp[i+1][j-1][2][k-val1]);
            }

            for (int k=val2;k<=L;k++){
                add(dp[i][j][2][k], dp[i+1][j+1][2][k-val2] * (j+1) %MOD);
                add(dp[i][j][2][k], dp[i+1][j][2][k-val2] * (j*2+2) %MOD);
                if (j) add(dp[i][j][2][k], dp[i+1][j-1][2][k-val2] * (j+1) %MOD);
            }
        }
    }

    ll ans = 0;
    for (int k=0;k<=L;k++){
        add(ans, dp[1][1][0][k]);
        add(ans, dp[1][0][1][k]*2%MOD);

        //if (k<=10) printf("%d %d\n", dp[1][1][0][k], dp[1][0][1][k]);
    }

    printf("%lld\n", ans);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d %d", &n, &L);
      |     ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:16:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     for (int i=1;i<=n;i++) scanf("%lld", a+i);
      |                            ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 1 ms 844 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1996 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 1 ms 1740 KB Output is correct
5 Correct 2 ms 1868 KB Output is correct
6 Correct 1 ms 2124 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 2 ms 2380 KB Output is correct
9 Correct 2 ms 2508 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 1 ms 844 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 2 ms 972 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 2 ms 1996 KB Output is correct
12 Correct 1 ms 1740 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 1 ms 1740 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 1 ms 2124 KB Output is correct
17 Correct 1 ms 1612 KB Output is correct
18 Correct 2 ms 2380 KB Output is correct
19 Correct 2 ms 2508 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 6 ms 9548 KB Output is correct
22 Correct 201 ms 141064 KB Output is correct
23 Correct 190 ms 142652 KB Output is correct
24 Correct 181 ms 167980 KB Output is correct
25 Correct 177 ms 145216 KB Output is correct
26 Correct 175 ms 144708 KB Output is correct
27 Correct 132 ms 152256 KB Output is correct
28 Correct 132 ms 165164 KB Output is correct
29 Correct 209 ms 197684 KB Output is correct
30 Correct 193 ms 144476 KB Output is correct