답안 #558834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
558834 2022-05-08T15:03:13 Z hibiki Skyscraper (JOI16_skyscraper) C++11
100 / 100
169 ms 81800 KB
#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define pb push_back

int n,l;
long long dp[105][105][1005][3];
vector<int> v;

int main()
{
    scanf("%d %d",&n,&l);
    for(int i = 0; i < n; i++)
    {
        int a;
        scanf("%d",&a);
        v.pb(a);
    }

    sort(v.begin(), v.end());

    if(n==1)
    {
        printf("1\n");
        return 0;
    }

    dp[0][1][0][0]=1;
    dp[0][1][0][1]=2;
    for(int idx = 0; idx < n - 1; idx++)
    {
        for(int g = 1; g <= idx + 1; g++)
        {
            for(int val = 0; val <= l; val++)
            {
                for(int ex = 0; ex < 3; ex++)
                {
                    // let's say we have ex = 0
                    // means we have space for start and end ex place(s)
                    long long cur = val + (2 * g - ex) * (v[idx + 1] - v[idx]);
                    long long nw = dp[idx][g][val][ex];
                    if(cur > l) continue;

                    // merge at start or end
                    dp[idx + 1][g][cur][ex + 1] += (2 - ex) * nw;
                    dp[idx + 1][g][cur][ex + 1] %= mod;

                    // create g at start or end;
                    dp[idx + 1][g + 1][cur][ex + 1] += (2 - ex) * nw;
                    dp[idx + 1][g + 1][cur][ex + 1] %= mod;

                    // merge
                    dp[idx + 1][g - 1][cur][ex] += (g - 1) * nw;
                    dp[idx + 1][g - 1][cur][ex] %= mod;

                    // create g
                    dp[idx + 1][g + 1][cur][ex] += (g + 1 - ex) * nw;
                    dp[idx + 1][g + 1][cur][ex] %= mod;

                    // add to g
                    dp[idx + 1][g][cur][ex] += (2 * g - ex) * nw;
                    dp[idx + 1][g][cur][ex] %= mod;
                }
            }
        }
    }

    long long ans = 0;
    for(int i = 0; i <= l; i++)
    {
        ans = ( ans + dp[n-1][1][i][2] ) % mod;
    }
    printf("%lld\n",ans);

    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d",&n,&l);
      |     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1084 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 852 KB Output is correct
3 Correct 1 ms 960 KB Output is correct
4 Correct 1 ms 956 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 832 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 1 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 1084 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 568 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 1 ms 960 KB Output is correct
14 Correct 1 ms 956 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 832 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 3 ms 3540 KB Output is correct
22 Correct 102 ms 68980 KB Output is correct
23 Correct 138 ms 81128 KB Output is correct
24 Correct 126 ms 79160 KB Output is correct
25 Correct 131 ms 81576 KB Output is correct
26 Correct 111 ms 76228 KB Output is correct
27 Correct 50 ms 43280 KB Output is correct
28 Correct 65 ms 49948 KB Output is correct
29 Correct 110 ms 76268 KB Output is correct
30 Correct 169 ms 81800 KB Output is correct