답안 #681605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681605 2023-01-13T12:44:23 Z vjudge1 Skyscraper (JOI16_skyscraper) C++14
100 / 100
193 ms 83768 KB
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100 +2;
const int M = 1000 +2;
const int mod = 1e9+7;
typedef pair<int,int> pii;

inline int add(int x, int y)
{
    return (x+y>=mod ? x+y-mod : x+y);
}

inline int gun(int x, int y)
{
    return ((x*1ll*y)%mod);
}

int n,l;
int a[N];
int dp[N][N][M][3];

int32_t main()
{
    scanf("%d %d",&n,&l);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    if(n==1)
    {
        cout<<"1\n";
        return 0;
    }
    for(int sum =0 ; sum<=l; sum++)
        dp[n][1][sum][2] = 1;

    for(int idx=n-1; idx>=0; idx--)
    {
        int prv = (idx-1>=0?a[idx-1] : 0);
        for(int comps = min(1,idx); comps <= n; comps++)
        {
            for(int sum =0 ; sum<=l; sum++)
            {
                for(int matha = 0 ; matha <= 2; matha++)
                {
                    int notun = sum + (a[idx]-prv)*(2*comps - matha);
                    if(notun > l)
                        continue;
                    int ans = 0;
                    //Create
                    ans = add(ans, gun(comps+1 - matha, dp[idx+1][comps+1][notun][matha]));
                    //merge
                    if(comps >= 2)
                        ans = add(ans, gun(comps-1, dp[idx+1][comps-1][notun][matha])) ;
                    //add
                    if(comps>=1)
                        ans = add(ans, gun(2*comps-matha, dp[idx+1][comps][notun][matha]));

                    if(matha < 2){
                        ans = add(ans, gun(2-matha, dp[idx+1][comps+1][notun][matha+1]));
                        ans = add(ans, gun(2-matha, dp[idx+1][comps][notun][matha+1]));
                    }
                    dp[idx][comps][sum][matha] = ans;
                }
            }
        }
    }
    printf("%d\n",dp[0][0][0][0]);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d %d",&n,&l);
      |     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1236 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 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 980 KB Output is correct
15 Correct 1 ms 980 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 3 ms 3796 KB Output is correct
22 Correct 167 ms 71160 KB Output is correct
23 Correct 173 ms 67400 KB Output is correct
24 Correct 169 ms 77316 KB Output is correct
25 Correct 193 ms 69736 KB Output is correct
26 Correct 166 ms 68456 KB Output is correct
27 Correct 77 ms 57712 KB Output is correct
28 Correct 92 ms 64192 KB Output is correct
29 Correct 177 ms 83768 KB Output is correct
30 Correct 182 ms 68812 KB Output is correct