# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238558 | vankata | Trener (COCI20_trener) | C++14 | 2081 ms | 1904 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;
const int MAXN = (int)(1<<11);
const int MOD = (int)(1e9+7);
int n,k;
vector<string>v[2];
long long dp[MAXN][MAXN];
bool cmp(string a,string b)
{
for(size_t i=0;i<a.size();i++)
{
if(a[i]!=b[i])return false;
}return true;
}
void comp(int t)
{
int i,j,lm=0,ll=0,l=0;
string s="";
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
lm=ll=0;
for(l=0;l<v[(t%2)^1][j].size();l++)
{
if(v[t%2][i][l]!=v[(t%2)^1][j][l])lm=-1;
if(v[t%2][i][l+1]!=v[(t%2)^1][j][l])ll=-1;
}
if(!lm||!ll)
{
dp[t][i]+=dp[t-1][j];
if(dp[t][i]>=MOD)dp[t][i]-=MOD;
}
}
}
}
void read()
{
int i,j,t=1;
string s;
cin>>n>>k;
for(i=0;i<k;i++)
{
dp[0][i]=1;
cin>>s;
v[0].push_back(s);
}
for(i=1;i<n;i++)
{
v[i%2].clear();
for(j=0;j<k;j++)
{
cin>>s;
v[i%2].push_back(s);
}
comp(i);
}
long long ans = 0;
for(i=0;i<k;i++)
{
ans+=dp[n-1][i];
}
ans%=MOD;cout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
read();
return 0;
}
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... |