답안 #442309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442309 2021-07-07T12:25:44 Z Pajaraja Skyscraper (JOI16_skyscraper) C++17
100 / 100
400 ms 2760 KB
#include <bits/stdc++.h>
#define MAXN 107
#define MAXL 2007
#define LAYERS 25
#define MOD 1000000007
using namespace std;
long long dp[2][LAYERS][MAXL][3],a[MAXN];
int main()
{
    int n; long long lim; cin>>n>>lim;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n); a[n]=a[n-1];
    dp[n&1][0][0][0]=1;
    for(int i=n-1;i>=0;i--)
    {
        int l=i&1;
        for(int j=0;j<LAYERS;j++) for(int k=0;k<MAXL;k++) for(int g=0;g<3;g++)
        {
            dp[l][j][k][g]=0;
            if(i<n-1 && k-(2*j-g)*(a[i+1]-a[i])>=0) dp[l][j][k][g]=(dp[l][j][k][g]+dp[l^1][j][k-(2*j-g)*(a[i+1]-a[i])][g]*(2*j-g))%MOD;
            if(j>0 && k-(2*j-2-g)*(a[i+1]-a[i])>=0) dp[l][j][k][g]=(dp[l][j][k][g]+dp[l^1][j-1][k-(2*j-2-g)*(a[i+1]-a[i])][g])%MOD;
            if((j>1 || g<2) && j+1<LAYERS && k-(2*j+2-g)*(a[i+1]-a[i])>=0) dp[l][j][k][g]=(dp[l][j][k][g]+dp[l^1][j+1][k-(2*j+2-g)*(a[i+1]-a[i])][g]*(j+1-(g+1)/2)*(j-g/2))%MOD;
            if(g>0 && j>0 && k-(2*j-1-g)*(a[i+1]-a[i])>=0) dp[l][j][k][g]=(dp[l][j][k][g]+dp[l^1][j-1][k-(2*j-1-g)*(a[i+1]-a[i])][g-1])%MOD;
            if((j>1 || g<2) && g>0 && k-(2*j+1-g)*(a[i+1]-a[i])>=0) dp[l][j][k][g]=(dp[l][j][k][g]+dp[l^1][j][k-(2*j+1-g)*(a[i+1]-a[i])][g-1]*(j+1-g))%MOD;
        }
    }
    for(int k=0;k<MAXL;k++) if(k-2*(a[1]-a[0])>=0) dp[0][1][k][2]=(dp[0][1][k][2]+dp[1][2][k-2*(a[1]-a[0])][2])%MOD;
    for(int k=0;k<MAXL;k++) if(k-1*(a[1]-a[0])>=0) dp[0][1][k][2]=(dp[0][1][k][2]+dp[1][1][k-1*(a[1]-a[0])][1])%MOD;
    long long sol=0;
    for(int k=0;k<=lim;k++) sol=(sol+2*dp[0][1][k][2])%MOD;
    if(n==1) sol=1;
    cout<<sol;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1356 KB Output is correct
2 Correct 8 ms 2620 KB Output is correct
3 Correct 12 ms 2636 KB Output is correct
4 Correct 23 ms 2648 KB Output is correct
5 Correct 18 ms 2652 KB Output is correct
6 Correct 20 ms 2636 KB Output is correct
7 Correct 27 ms 2636 KB Output is correct
8 Correct 33 ms 2576 KB Output is correct
9 Correct 23 ms 2636 KB Output is correct
10 Correct 35 ms 2536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 2636 KB Output is correct
2 Correct 55 ms 2636 KB Output is correct
3 Correct 58 ms 2636 KB Output is correct
4 Correct 55 ms 2636 KB Output is correct
5 Correct 55 ms 2628 KB Output is correct
6 Correct 56 ms 2636 KB Output is correct
7 Correct 56 ms 2636 KB Output is correct
8 Correct 59 ms 2540 KB Output is correct
9 Correct 56 ms 2636 KB Output is correct
10 Correct 54 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1356 KB Output is correct
2 Correct 8 ms 2620 KB Output is correct
3 Correct 12 ms 2636 KB Output is correct
4 Correct 23 ms 2648 KB Output is correct
5 Correct 18 ms 2652 KB Output is correct
6 Correct 20 ms 2636 KB Output is correct
7 Correct 27 ms 2636 KB Output is correct
8 Correct 33 ms 2576 KB Output is correct
9 Correct 23 ms 2636 KB Output is correct
10 Correct 35 ms 2536 KB Output is correct
11 Correct 49 ms 2636 KB Output is correct
12 Correct 55 ms 2636 KB Output is correct
13 Correct 58 ms 2636 KB Output is correct
14 Correct 55 ms 2636 KB Output is correct
15 Correct 55 ms 2628 KB Output is correct
16 Correct 56 ms 2636 KB Output is correct
17 Correct 56 ms 2636 KB Output is correct
18 Correct 59 ms 2540 KB Output is correct
19 Correct 56 ms 2636 KB Output is correct
20 Correct 54 ms 2636 KB Output is correct
21 Correct 165 ms 2760 KB Output is correct
22 Correct 313 ms 2636 KB Output is correct
23 Correct 365 ms 2636 KB Output is correct
24 Correct 379 ms 2616 KB Output is correct
25 Correct 370 ms 2636 KB Output is correct
26 Correct 375 ms 2740 KB Output is correct
27 Correct 398 ms 2648 KB Output is correct
28 Correct 400 ms 2676 KB Output is correct
29 Correct 398 ms 2636 KB Output is correct
30 Correct 366 ms 2756 KB Output is correct