답안 #775442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
775442 2023-07-06T11:43:42 Z PoonYaPat Skyscraper (JOI16_skyscraper) C++14
100 / 100
116 ms 81944 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll mod=1e9+7;
int n,lim,a[105];
ll dp[105][105][1005][3];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>lim;
    for (int i=1; i<=n; ++i) cin>>a[i];
    sort(a+1,a+n+1);

    if (n==1) {
        cout<<1;
        return 0;
    }

    dp[1][1][0][0]=1;
    dp[1][1][0][1]=2;

    for (int i=2; i<=n; ++i) {
        for (int j=1; j<i; ++j) {
            for (int k=0; k<=lim; ++k) {
                for (int e=0; e<3; ++e) {
                    //consider value from dp[i-1][j][k][e]
                    int nw=k+(a[i]-a[i-1])*(2*j-e);
                    if (nw>lim) continue;

                    //insert to middle component
                    dp[i][j][nw][e]=(dp[i][j][nw][e]+dp[i-1][j][k][e]*(2*j-e))%mod;

                    //insert to rim component
                    dp[i][j][nw][e+1]=(dp[i][j][nw][e+1]+dp[i-1][j][k][e]*(2-e))%mod;

                    //merge 2 component
                    dp[i][j-1][nw][e]=(dp[i][j-1][nw][e]+dp[i-1][j][k][e]*(j-1))%mod;

                    //create new middle component
                    dp[i][j+1][nw][e]=(dp[i][j+1][nw][e]+dp[i-1][j][k][e]*(j+1-e))%mod;

                    //create new rim component
                    dp[i][j+1][nw][e+1]=(dp[i][j+1][nw][e+1]+dp[i-1][j][k][e]*(2-e))%mod;
                    
                }
            }
        }
    }

    ll ans=0;
    for (int k=0; k<=lim; ++k) ans=(ans+dp[n][1][k][2])%mod;
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 1108 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 3 ms 1092 KB Output is correct
10 Correct 1 ms 584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 852 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 1108 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 3 ms 1092 KB Output is correct
10 Correct 1 ms 584 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 852 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 852 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 4 ms 3540 KB Output is correct
22 Correct 87 ms 69104 KB Output is correct
23 Correct 111 ms 80896 KB Output is correct
24 Correct 100 ms 79096 KB Output is correct
25 Correct 109 ms 81696 KB Output is correct
26 Correct 98 ms 76484 KB Output is correct
27 Correct 45 ms 43216 KB Output is correct
28 Correct 55 ms 49992 KB Output is correct
29 Correct 95 ms 76208 KB Output is correct
30 Correct 116 ms 81944 KB Output is correct