# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
907804 | ibm2006 | Ljetopica (COI19_ljetopica) | C++17 | 58 ms | 230228 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,i,j,k,l,r,x,y,z,w,a[1100000],b[1100000],com[5500][5500],tw[5500],dp[1100][1100],ans;
char c;
const ll mod=1000000007;
ll C(ll x,ll y)
{
if(x<0||y<0||y>x)
return 0;
return com[x][y];
}
ll two(ll x)
{
return tw[x];
}
int main()
{
tw[0]=1;
com[0][0]=1;
for(i=1;i<=5000;i++)
{
for(j=0;j<=i;j++)
{
if(j==0)
{
com[i][j]=1;
continue;
}
com[i][j]=(com[i-1][j]+com[i-1][j-1])%mod;
}
}
for(i=1;i<=5000;i++)
{
tw[i]=tw[i-1]*2%mod;
}
scanf("%lld %lld\n",&n,&k);
for(i=1;i<n;i++)
{
scanf("%c",&c);
if(c=='L')
{
a[i]=0;
}
else
{
a[i]=1;
}
}
dp[1][0]=1;
for(i=2;i<=n;i++)
{
for(j=0;j<i;j++)
{
if(a[n-i+1]==0)
{
if(j==0)
{
dp[i][j]=dp[i-1][j]+C(i-2,j)*two(i-2)%mod;
}
else
{dp[i][j]=dp[i-1][j]+C(i-2,j)*two(i-2)%mod+(two(i-2)*3+two(i-1)-1)*C(i-2,j-1)%mod-dp[i-1][j-1];}
dp[i][j]%=mod;
dp[i][j]=(dp[i][j]+mod)%mod;
}
else
{
if(j==0)
{
dp[i][j]=dp[i-1][j]+C(i-2,j)*two(i-1)%mod;
}
else
dp[i][j]=dp[i-1][j]+C(i-2,j)*two(i-1)%mod+(two(i)-1)*C(i-2,j-1)%mod-dp[i-1][j-1];
dp[i][j]%=mod;
dp[i][j]=(dp[i][j]+mod)%mod;
}
}
}
for(i=1;i<=n;i++)
{
scanf("%01lld",&b[i]);
}
for(i=1;i<=n;i++)
{
scanf("%01lld",&b[i]);
}
if(k>=1)
{
ans=dp[n][k]+dp[n][k-1]+(two(n)-1+two(n-1))*C(n,k)%mod-dp[n][k]-dp[n][k-1];
}
else
{
ans=dp[n][k]+two(n)-1+two(n-1)-dp[n][k];
}
printf("%lld",ans%mod);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |