| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1285545 | Faisal_Saqib | Skyscraper (JOI16_skyscraper) | C++20 | 169 ms | 163112 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=102,L=1002,mod=1e9+7;
ll dp[N][N][L][4],a[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n,l;
cin>>n>>l;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
if(n==1)
{
cout<<1<<endl;
return 0;
}
sort(a+1,a+1+n);
a[n+1]=a[n];
dp[0][0][0][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
for(int k=0;k<=l;k++)
{
for(int m=0;m<3;m++)
{
ll ac=(a[i+1]-a[i])*(2*j-m);// additonal cost
if(k<ac)continue;
// new component not at the end
dp[i][j][k][m]+=dp[i-1][j-1][k-ac][m];
// new component at one of the end
if(m>0)
{
dp[i][j][k][m]+=(3-m)*dp[i-1][j-1][k-ac][m-1];
}
// add to one of the component but not any end
dp[i][j][k][m]+=(2*j-m)*dp[i-1][j][k-ac][m];
// add to component and making it end
if(m==1)
{
dp[i][j][k][m]+=j*2*dp[i-1][j][k-ac][m-1];
}
else if(m==2)
{
if(j==1)
{
if(i==n)
{
dp[i][j][k][m]+=dp[i-1][j][k-ac][m-1];
}
}
else
{
dp[i][j][k][m]+=(j-1)*dp[i-1][j][k-ac][m-1];
}
}
else
{
// m==0 not pos
}
// merge two components
// which two to merge
// if m==2
if(m==2)
{
if(j==1)
{
// we merge one containing the first endpoint and the last endpoint
if(i==n)
{
dp[i][j][k][m]+=dp[i-1][j+1][k-ac][m];
}
}
else
{
// we can't merge the first and the last with each other
dp[i][j][k][m]+=((j-1)*(j-2)+2*(j-1))*(dp[i-1][j+1][k-ac][m]);
}
}
else if(m==1)
{
// j + (j-1)*j = j*j
dp[i][j][k][m]+=(j*j)*dp[i-1][j+1][k-ac][m];
}
else
{
dp[i][j][k][m]+=(j+1)*(j)*dp[i-1][j+1][k-ac][m];
}
dp[i][j][k][m]%=mod;
}
}
}
}
ll ans=0;
for(int i=0;i<=l;i++)
{
ans+=dp[n][1][i][2];
ans%=mod;
}
cout<<ans<<endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
