Submission #164293

# Submission time Handle Problem Language Result Execution time Memory
164293 2019-11-19T02:51:19 Z kataki Skyscraper (JOI16_skyscraper) C++14
100 / 100
627 ms 347512 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

ll dp[105][105][1005][2][2];
int n,l;
int a[105];
ll solve(int pos, int comp, int cost, int cl, int cr)
{
    if(comp < 0)
        return 0;
    int ncost = cost;
    if(pos > 0)
    {
        ncost += (cl+cr+2*comp) * abs(a[pos] - a[pos-1]);
    } 
    if(ncost > l)
        return 0;
    if(pos == n-1)
    {
        return comp == 0;
    }
    ll &ans = dp[pos][comp][cost][cl][cr];
    if(ans != -1)
        return ans;
    ans = 0;
    
    ans += solve(pos+1, comp, ncost, 1, cr);
    ans += solve(pos+1, comp-1, ncost, 1, cr) * comp;

    ans += solve(pos+1, comp, ncost, cl, 1);
    ans += solve(pos+1, comp-1, ncost, cl, 1) * comp;


    ans += solve(pos+1, comp, ncost, cl, cr) * (2 * comp);
    ans += solve(pos+1, comp-1, ncost, cl, cr) * (comp) * (comp-1);
    
    ans += solve(pos+1, comp+1, ncost, cl, cr);
    
    ans %= mod;
    return ans;
       
}

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

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:51: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:53:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 302 ms 347384 KB Output is correct
2 Correct 303 ms 347384 KB Output is correct
3 Correct 303 ms 347284 KB Output is correct
4 Correct 310 ms 347256 KB Output is correct
5 Correct 316 ms 347512 KB Output is correct
6 Correct 317 ms 347336 KB Output is correct
7 Correct 336 ms 347256 KB Output is correct
8 Correct 312 ms 347468 KB Output is correct
9 Correct 304 ms 347256 KB Output is correct
10 Correct 302 ms 347416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 330 ms 347348 KB Output is correct
2 Correct 305 ms 347256 KB Output is correct
3 Correct 303 ms 347256 KB Output is correct
4 Correct 303 ms 347388 KB Output is correct
5 Correct 304 ms 347256 KB Output is correct
6 Correct 351 ms 347384 KB Output is correct
7 Correct 307 ms 347256 KB Output is correct
8 Correct 305 ms 347256 KB Output is correct
9 Correct 302 ms 347324 KB Output is correct
10 Correct 304 ms 347384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 302 ms 347384 KB Output is correct
2 Correct 303 ms 347384 KB Output is correct
3 Correct 303 ms 347284 KB Output is correct
4 Correct 310 ms 347256 KB Output is correct
5 Correct 316 ms 347512 KB Output is correct
6 Correct 317 ms 347336 KB Output is correct
7 Correct 336 ms 347256 KB Output is correct
8 Correct 312 ms 347468 KB Output is correct
9 Correct 304 ms 347256 KB Output is correct
10 Correct 302 ms 347416 KB Output is correct
11 Correct 330 ms 347348 KB Output is correct
12 Correct 305 ms 347256 KB Output is correct
13 Correct 303 ms 347256 KB Output is correct
14 Correct 303 ms 347388 KB Output is correct
15 Correct 304 ms 347256 KB Output is correct
16 Correct 351 ms 347384 KB Output is correct
17 Correct 307 ms 347256 KB Output is correct
18 Correct 305 ms 347256 KB Output is correct
19 Correct 302 ms 347324 KB Output is correct
20 Correct 304 ms 347384 KB Output is correct
21 Correct 312 ms 347288 KB Output is correct
22 Correct 627 ms 347256 KB Output is correct
23 Correct 485 ms 347412 KB Output is correct
24 Correct 498 ms 347256 KB Output is correct
25 Correct 495 ms 347256 KB Output is correct
26 Correct 468 ms 347256 KB Output is correct
27 Correct 391 ms 347256 KB Output is correct
28 Correct 420 ms 347384 KB Output is correct
29 Correct 539 ms 347384 KB Output is correct
30 Correct 515 ms 347388 KB Output is correct