답안 #94599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94599 2019-01-21T15:36:13 Z Bliss_of_comprehension Skyscraper (JOI16_skyscraper) C++14
100 / 100
900 ms 316924 KB
#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;

typedef long long ll;

ll dp[105][105][1005][2][2]={};

int main(){
    int n,l;
    cin >> n >> l;
    vector <int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    if(n==1){
        cout << 1 << endl;
        return 0;
    }
    sort(a.begin(),a.end());
    dp[0][0][0][0][0]=1;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(i==n-1){
            for(int k=0;k<=l;k++){
                for(int iss=0;iss<2;iss++){
                    for(int ise=0;ise<2;ise++){
                        dp[i][0][k][iss][ise]%=mod;
                        if(iss+ise>0)
                            ans=(ans+dp[i][0][k][iss][ise])%mod;
                    }
                }

            }
            continue;
        }

        for(int j=0;j<=n;j++){
            for(int k=0;k<=l;k++){
                for(int iss=0;iss<2;iss++){
                    for(int ise=0;ise<2;ise++){
//                        if(i==2){
//                            cout << i << " " << j << " " << k << " " << iss << " " << ise << " " << dp[i][j][k][iss][ise] << endl;
//                        }
                        ll &cur = dp[i][j][k][iss][ise];
                        assert(cur>=0);
                        cur%=mod;
                        int diff = a[i+1]-a[i];
                        int nl=k+(a[i+1]-a[i])*(2*j+iss+ise);
                        if(j){
                            if(nl-2*diff>l){
                                continue;
                            }
                            if(iss){
                                dp[i+1][j-1][nl-2*diff][iss][ise]+=cur*j;
                                dp[i+1][j-1][nl-2*diff][iss][ise]%=mod;
                            }
                            if(ise){
                                dp[i+1][j-1][nl-2*diff][iss][ise]+=cur*j;
                                dp[i+1][j-1][nl-2*diff][iss][ise]%=mod;
                            }
                            if(j>1){
                                dp[i+1][j-1][nl-2*diff][iss][ise]+=cur*j*(j-1);
                                dp[i+1][j-1][nl-2*diff][iss][ise]%=mod;
                            }
                            if(nl-diff>l){
                                continue;
                            }
                            if(!iss){
                                dp[i+1][j-1][nl-diff][1][ise]+=cur*j;
                                dp[i+1][j-1][nl-diff][1][ise]%=mod;
                            }
                            if(!ise){
                                dp[i+1][j-1][nl-diff][iss][1]+=cur*j;
                                dp[i+1][j-1][nl-diff][iss][1]%=mod;
                            }
                        }

                        if(nl>l){
                            continue;
                        }
                        if(iss){
                            dp[i+1][j][nl][iss][ise]+=cur;
                            dp[i+1][j][nl][iss][ise]%=mod;
                        }
                        if(ise){
                            dp[i+1][j][nl][iss][ise]+=cur;
                            dp[i+1][j][nl][iss][ise]%=mod;
                        }
                        if(j){
                            dp[i+1][j][nl][iss][ise]+=(2*j)*cur;
                            dp[i+1][j][nl][iss][ise]%=mod;
                        }
                        if(nl+diff>l){
                            continue;
                        }
                        if(!iss){
                            dp[i+1][j][nl+diff][1][ise]+=cur;
                            dp[i+1][j][nl+diff][1][ise]%=mod;
                        }
                        if(!ise){
                            dp[i+1][j][nl+diff][iss][1]+=cur;
                            dp[i+1][j][nl+diff][iss][1]%=mod;
                        }
                        if(nl+2*diff>l){
                            continue;
                        }
                        dp[i+1][j+1][nl+2*diff][iss][ise]+=cur;
                        dp[i+1][j+1][nl+2*diff][iss][ise]%=mod;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 7 ms 2424 KB Output is correct
6 Correct 6 ms 2296 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 7 ms 2552 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1400 KB Output is correct
2 Correct 4 ms 1784 KB Output is correct
3 Correct 4 ms 1528 KB Output is correct
4 Correct 4 ms 1784 KB Output is correct
5 Correct 4 ms 1912 KB Output is correct
6 Correct 5 ms 1784 KB Output is correct
7 Correct 3 ms 1400 KB Output is correct
8 Correct 4 ms 1528 KB Output is correct
9 Correct 4 ms 1784 KB Output is correct
10 Correct 4 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 7 ms 2424 KB Output is correct
6 Correct 6 ms 2296 KB Output is correct
7 Correct 3 ms 888 KB Output is correct
8 Correct 3 ms 760 KB Output is correct
9 Correct 7 ms 2552 KB Output is correct
10 Correct 3 ms 888 KB Output is correct
11 Correct 4 ms 1400 KB Output is correct
12 Correct 4 ms 1784 KB Output is correct
13 Correct 4 ms 1528 KB Output is correct
14 Correct 4 ms 1784 KB Output is correct
15 Correct 4 ms 1912 KB Output is correct
16 Correct 5 ms 1784 KB Output is correct
17 Correct 3 ms 1400 KB Output is correct
18 Correct 4 ms 1528 KB Output is correct
19 Correct 4 ms 1784 KB Output is correct
20 Correct 4 ms 1656 KB Output is correct
21 Correct 14 ms 9080 KB Output is correct
22 Correct 785 ms 185464 KB Output is correct
23 Correct 900 ms 316408 KB Output is correct
24 Correct 756 ms 275136 KB Output is correct
25 Correct 863 ms 316920 KB Output is correct
26 Correct 799 ms 307448 KB Output is correct
27 Correct 287 ms 118548 KB Output is correct
28 Correct 367 ms 136504 KB Output is correct
29 Correct 682 ms 222204 KB Output is correct
30 Correct 862 ms 316924 KB Output is correct