Submission #81775

# Submission time Handle Problem Language Result Execution time Memory
81775 2018-10-26T13:49:03 Z Bodo171 Skyscraper (JOI16_skyscraper) C++14
100 / 100
454 ms 7460 KB
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
const int nmax=105;
const long long mod=1000*1000*1000+7;
long long dp[2][nmax][nmax*10][2][2];
int a[nmax];
int n,l,use,cost,newcost,st,dr;
long long i,gaps,difs,endss;
long long ans;
void prp(long long &a,long long b)
{
    a+=(b%mod);
    if(a>=mod)
        a-=mod;
}
int main()
{
    //freopen("data.in","r",stdin);
    cin>>n>>l;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    //dp[use][cc][cost][fix_st][fix_dr]
    for(st=0;st<2;st++)
        for(dr=0;dr<2;dr++)
           dp[1][1][0][st][dr]=1;
    for(int cnt=2;cnt<=n;cnt++)
    {
        use=1-use;
        for(i=1;i<=n;i++)
          for(cost=0;cost<=l;cost++)
            for(st=0;st<2;st++)
              for(dr=0;dr<2;dr++)
               dp[1-use][i][cost][st][dr]=0;
        for(i=1;i<=n;i++)
          for(cost=0;cost<=l;cost++)
            for(st=0;st<2;st++)
              for(dr=0;dr<2;dr++)
        {
             gaps=i+1-st-dr;
             endss=2*(i-1)+(1-st)+(1-dr);
             newcost=(a[cnt]-a[cnt-1])*endss+cost;
             if(newcost<=l)
             {
                 prp(dp[1-use][i-1][newcost][st][dr],1LL*dp[use][i][cost][st][dr]*(i-1));
                 prp(dp[1-use][i+1][newcost][st][dr],1LL*dp[use][i][cost][st][dr]*gaps);
                 prp(dp[1-use][i][newcost][st][dr],1LL*dp[use][i][cost][st][dr]*endss);
                 if(!st)
                 {
                     prp(dp[1-use][i+1][newcost][1][dr],dp[use][i][cost][st][dr]);
                     prp(dp[1-use][i][newcost][1][dr],dp[use][i][cost][st][dr]);
                 }
                 if(!dr)
                 {
                     prp(dp[1-use][i+1][newcost][st][1],dp[use][i][cost][st][dr]);
                     prp(dp[1-use][i][newcost][st][1],dp[use][i][cost][st][dr]);
                 }
             }
        }
    }
    use=1-use;
    for(i=0;i<=l;i++)
        prp(ans,dp[use][1][i][1][1]);
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 4 ms 1036 KB Output is correct
6 Correct 5 ms 1164 KB Output is correct
7 Correct 2 ms 1164 KB Output is correct
8 Correct 2 ms 1164 KB Output is correct
9 Correct 5 ms 1164 KB Output is correct
10 Correct 2 ms 1164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1164 KB Output is correct
2 Correct 3 ms 1164 KB Output is correct
3 Correct 2 ms 1164 KB Output is correct
4 Correct 3 ms 1164 KB Output is correct
5 Correct 3 ms 1164 KB Output is correct
6 Correct 3 ms 1164 KB Output is correct
7 Correct 2 ms 1164 KB Output is correct
8 Correct 3 ms 1164 KB Output is correct
9 Correct 3 ms 1164 KB Output is correct
10 Correct 3 ms 1164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 524 KB Output is correct
5 Correct 4 ms 1036 KB Output is correct
6 Correct 5 ms 1164 KB Output is correct
7 Correct 2 ms 1164 KB Output is correct
8 Correct 2 ms 1164 KB Output is correct
9 Correct 5 ms 1164 KB Output is correct
10 Correct 2 ms 1164 KB Output is correct
11 Correct 3 ms 1164 KB Output is correct
12 Correct 3 ms 1164 KB Output is correct
13 Correct 2 ms 1164 KB Output is correct
14 Correct 3 ms 1164 KB Output is correct
15 Correct 3 ms 1164 KB Output is correct
16 Correct 3 ms 1164 KB Output is correct
17 Correct 2 ms 1164 KB Output is correct
18 Correct 3 ms 1164 KB Output is correct
19 Correct 3 ms 1164 KB Output is correct
20 Correct 3 ms 1164 KB Output is correct
21 Correct 4 ms 1164 KB Output is correct
22 Correct 415 ms 5380 KB Output is correct
23 Correct 448 ms 7460 KB Output is correct
24 Correct 379 ms 7460 KB Output is correct
25 Correct 452 ms 7460 KB Output is correct
26 Correct 392 ms 7460 KB Output is correct
27 Correct 154 ms 7460 KB Output is correct
28 Correct 185 ms 7460 KB Output is correct
29 Correct 343 ms 7460 KB Output is correct
30 Correct 454 ms 7460 KB Output is correct