#include<iostream>
#include<cstring>
using namespace std;
const int mod=1000000007;
int n,k,dp[52][1510];
char c[52][1510][64];
void read()
{
cin>>n>>k;
for(int i=0;i<n;i++)
for(int j=0;j<k;j++)
cin>>c[i][j];
}
int finds(char d[64],char e[64])
{
int sz1=strlen(d);
int sz2=strlen(e);
bool l;
for(int i=0;i<sz1-sz2+1;i++)
{
l=true;
for(int j=0;j<sz2;j++)
if(d[i+j]!=e[j])
{
l=false;
break;
}
if(l)return 1;
}
return 0;
}
void solve()
{
for(int i=0;i<k;i++)
dp[0][i]=1;
int rez;
for(int i=1;i<n;i++)
for(int j=0;j<k;j++)
for(int p=0;p<k;p++)
{
rez=finds(c[i][j],c[i-1][p]);
///cout<<rez<<' '<<c[i][j]<<' '<<c[i-1][p]<<endl;
if(rez)dp[i][j]=(dp[i-1][p]%mod+dp[i][j]%mod)%mod;
}
int ans=0,pos=n-1;
for(int i=0;i<k;i++)
ans=(dp[pos][i]%mod+ans%mod)%mod;
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
read();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1024 KB |
Output is correct |
2 |
Correct |
15 ms |
1024 KB |
Output is correct |
3 |
Correct |
12 ms |
1152 KB |
Output is correct |
4 |
Correct |
19 ms |
1024 KB |
Output is correct |
5 |
Correct |
19 ms |
1024 KB |
Output is correct |
6 |
Correct |
19 ms |
1024 KB |
Output is correct |
7 |
Correct |
19 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
1024 KB |
Output is correct |
6 |
Correct |
15 ms |
1024 KB |
Output is correct |
7 |
Correct |
12 ms |
1152 KB |
Output is correct |
8 |
Correct |
19 ms |
1024 KB |
Output is correct |
9 |
Correct |
19 ms |
1024 KB |
Output is correct |
10 |
Correct |
19 ms |
1024 KB |
Output is correct |
11 |
Correct |
19 ms |
1024 KB |
Output is correct |
12 |
Correct |
1325 ms |
5368 KB |
Output is correct |
13 |
Correct |
1302 ms |
5440 KB |
Output is correct |
14 |
Correct |
1290 ms |
5536 KB |
Output is correct |
15 |
Correct |
1319 ms |
5496 KB |
Output is correct |
16 |
Execution timed out |
2091 ms |
5512 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |