Submission #237575

# Submission time Handle Problem Language Result Execution time Memory
237575 2020-06-07T12:46:10 Z DodgeBallMan Skyscraper (JOI16_skyscraper) C++14
100 / 100
263 ms 261884 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 105;
const int mod = 1e9 + 7;
const int L = 1e3 + 10;

int n, l, a[N];
long long dp[N][N][L][3];

long long solve( int pos, int cc, int diff, int ends ) {
    if( pos == n+1 ) return ( cc == 1 && diff <= l && ends == 2 );
    if( cc == 0 || diff > l || ends == 3 ) return 0;
    long long &now = dp[pos][cc][diff][ends];
    if( now != -1 ) return now;
    int nxt = diff + ( a[pos] - a[pos-1] ) * ( 2 * cc - ends );
    now = 0;
    now = ( now + ( cc + 1 - ends ) * solve( pos+1, cc+1, nxt, ends ) % mod ) % mod;
    now = ( now + ( cc - 1 ) * solve( pos+1, cc-1, nxt, ends ) % mod ) % mod;
    now = ( now + ( 2*cc - ends ) * solve( pos+1, cc, nxt, ends ) % mod ) % mod;
    now = ( now + ( 2 - ends ) * solve( pos+1, cc, nxt, ends + 1 ) % mod ) % mod;
    now = ( now + ( 2 - ends ) * solve( pos+1, cc + 1, nxt, ends + 1 ) % mod ) % mod;
    return now;
}

int main()
{
    memset( dp, -1, sizeof dp );
    scanf("%d %d",&n,&l);
    for( int i = 1 ; i <= n ; i++ ) scanf("%d",&a[i]);
    sort( a+1, a+1+n );
    if( n == 1 ) return !printf("1\n");
    printf("%lld\n",( solve( 2, 1, 0, 0 ) + 2*solve( 2, 1, 0, 1 ) ) % mod);
    return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&l);
     ~~~~~^~~~~~~~~~~~~~~
skyscraper.cpp:31:42: 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("%d",&a[i]);
                                     ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 138 ms 261752 KB Output is correct
2 Correct 128 ms 261784 KB Output is correct
3 Correct 132 ms 261880 KB Output is correct
4 Correct 139 ms 261752 KB Output is correct
5 Correct 155 ms 261756 KB Output is correct
6 Correct 150 ms 261880 KB Output is correct
7 Correct 130 ms 261856 KB Output is correct
8 Correct 132 ms 261880 KB Output is correct
9 Correct 132 ms 261752 KB Output is correct
10 Correct 155 ms 261752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 261752 KB Output is correct
2 Correct 142 ms 261884 KB Output is correct
3 Correct 133 ms 261880 KB Output is correct
4 Correct 136 ms 261880 KB Output is correct
5 Correct 137 ms 261836 KB Output is correct
6 Correct 138 ms 261884 KB Output is correct
7 Correct 136 ms 261752 KB Output is correct
8 Correct 134 ms 261752 KB Output is correct
9 Correct 132 ms 261856 KB Output is correct
10 Correct 154 ms 261880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 261752 KB Output is correct
2 Correct 128 ms 261784 KB Output is correct
3 Correct 132 ms 261880 KB Output is correct
4 Correct 139 ms 261752 KB Output is correct
5 Correct 155 ms 261756 KB Output is correct
6 Correct 150 ms 261880 KB Output is correct
7 Correct 130 ms 261856 KB Output is correct
8 Correct 132 ms 261880 KB Output is correct
9 Correct 132 ms 261752 KB Output is correct
10 Correct 155 ms 261752 KB Output is correct
11 Correct 138 ms 261752 KB Output is correct
12 Correct 142 ms 261884 KB Output is correct
13 Correct 133 ms 261880 KB Output is correct
14 Correct 136 ms 261880 KB Output is correct
15 Correct 137 ms 261836 KB Output is correct
16 Correct 138 ms 261884 KB Output is correct
17 Correct 136 ms 261752 KB Output is correct
18 Correct 134 ms 261752 KB Output is correct
19 Correct 132 ms 261856 KB Output is correct
20 Correct 154 ms 261880 KB Output is correct
21 Correct 150 ms 261880 KB Output is correct
22 Correct 263 ms 261752 KB Output is correct
23 Correct 194 ms 261752 KB Output is correct
24 Correct 213 ms 261752 KB Output is correct
25 Correct 210 ms 261752 KB Output is correct
26 Correct 191 ms 261752 KB Output is correct
27 Correct 173 ms 261880 KB Output is correct
28 Correct 172 ms 261752 KB Output is correct
29 Correct 224 ms 261880 KB Output is correct
30 Correct 203 ms 261880 KB Output is correct