Submission #225536

# Submission time Handle Problem Language Result Execution time Memory
225536 2020-04-20T20:02:51 Z MKopchev Skyscraper (JOI16_skyscraper) C++14
100 / 100
123 ms 130552 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=1e2+5,lmax=1e3+5,mod=1e9+7;

int n,inp[nmax];

int dp[nmax][nmax][lmax][3];

int mx;

int rec(int placed,int components,int sum,int ends)
{
    if(ends>2||sum>mx)return 0;

    if(components==0&&placed)return 0;

    if(placed==n)return ends==2&&components==1;

    if(dp[placed][components][sum][ends]!=-1)return dp[placed][components][sum][ends];

    int sum_new=sum+(inp[placed+1]-inp[placed])*(2*components-ends);

    long long ret=0;

    if(components>=2)ret=ret+1LL*(components-1)*rec(placed+1,components-1,sum_new,ends);//merge 2 components

    if(components>=1)ret=ret+1LL*(2*components-ends)*rec(placed+1,components,sum_new,ends);//add to a component's end

    ret=ret+1LL*(components+1-ends)*rec(placed+1,components+1,sum_new,ends);//create a new component

    if(ends<2)ret=ret+1LL*(2-ends)*rec(placed+1,components+1,sum_new,ends+1);//create a new end

    if(ends<2)ret=ret+1LL*(2-ends)*rec(placed+1,components,sum_new,ends+1);//extend a component to make it a border

    ret=ret%mod;

    dp[placed][components][sum][ends]=ret;

    return ret;
}
int main()
{
    memset(dp,-1,sizeof(dp));

    scanf("%i%i",&n,&mx);
    for(int i=1;i<=n;i++)scanf("%i",&inp[i]);

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

    sort(inp+1,inp+n+1);

    printf("%i\n",rec(0,0,0,0));
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&n,&mx);
     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:47:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)scanf("%i",&inp[i]);
                          ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 69 ms 130424 KB Output is correct
2 Correct 70 ms 130424 KB Output is correct
3 Correct 62 ms 130424 KB Output is correct
4 Correct 75 ms 130552 KB Output is correct
5 Correct 62 ms 130424 KB Output is correct
6 Correct 62 ms 130424 KB Output is correct
7 Correct 63 ms 130428 KB Output is correct
8 Correct 68 ms 130424 KB Output is correct
9 Correct 65 ms 130424 KB Output is correct
10 Correct 62 ms 130424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 130424 KB Output is correct
2 Correct 63 ms 130424 KB Output is correct
3 Correct 63 ms 130424 KB Output is correct
4 Correct 63 ms 130424 KB Output is correct
5 Correct 69 ms 130424 KB Output is correct
6 Correct 62 ms 130488 KB Output is correct
7 Correct 63 ms 130424 KB Output is correct
8 Correct 62 ms 130424 KB Output is correct
9 Correct 62 ms 130424 KB Output is correct
10 Correct 62 ms 130424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 130424 KB Output is correct
2 Correct 70 ms 130424 KB Output is correct
3 Correct 62 ms 130424 KB Output is correct
4 Correct 75 ms 130552 KB Output is correct
5 Correct 62 ms 130424 KB Output is correct
6 Correct 62 ms 130424 KB Output is correct
7 Correct 63 ms 130428 KB Output is correct
8 Correct 68 ms 130424 KB Output is correct
9 Correct 65 ms 130424 KB Output is correct
10 Correct 62 ms 130424 KB Output is correct
11 Correct 64 ms 130424 KB Output is correct
12 Correct 63 ms 130424 KB Output is correct
13 Correct 63 ms 130424 KB Output is correct
14 Correct 63 ms 130424 KB Output is correct
15 Correct 69 ms 130424 KB Output is correct
16 Correct 62 ms 130488 KB Output is correct
17 Correct 63 ms 130424 KB Output is correct
18 Correct 62 ms 130424 KB Output is correct
19 Correct 62 ms 130424 KB Output is correct
20 Correct 62 ms 130424 KB Output is correct
21 Correct 74 ms 130424 KB Output is correct
22 Correct 123 ms 130424 KB Output is correct
23 Correct 95 ms 130424 KB Output is correct
24 Correct 97 ms 130424 KB Output is correct
25 Correct 99 ms 130424 KB Output is correct
26 Correct 96 ms 130540 KB Output is correct
27 Correct 78 ms 130424 KB Output is correct
28 Correct 87 ms 130380 KB Output is correct
29 Correct 100 ms 130424 KB Output is correct
30 Correct 96 ms 130424 KB Output is correct