#include<iostream>
#include<cstring>
using namespace std;
const int mod=1000000007;
int n,k,dp[64][2048];
char c[64][2048][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 |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1152 KB |
Output is correct |
2 |
Correct |
11 ms |
1152 KB |
Output is correct |
3 |
Correct |
14 ms |
1280 KB |
Output is correct |
4 |
Correct |
19 ms |
1152 KB |
Output is correct |
5 |
Correct |
19 ms |
1152 KB |
Output is correct |
6 |
Correct |
18 ms |
1152 KB |
Output is correct |
7 |
Correct |
19 ms |
1152 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 |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
11 ms |
1152 KB |
Output is correct |
6 |
Correct |
11 ms |
1152 KB |
Output is correct |
7 |
Correct |
14 ms |
1280 KB |
Output is correct |
8 |
Correct |
19 ms |
1152 KB |
Output is correct |
9 |
Correct |
19 ms |
1152 KB |
Output is correct |
10 |
Correct |
18 ms |
1152 KB |
Output is correct |
11 |
Correct |
19 ms |
1152 KB |
Output is correct |
12 |
Correct |
1309 ms |
5856 KB |
Output is correct |
13 |
Correct |
1274 ms |
5876 KB |
Output is correct |
14 |
Correct |
1308 ms |
6100 KB |
Output is correct |
15 |
Correct |
1290 ms |
5880 KB |
Output is correct |
16 |
Execution timed out |
2091 ms |
5956 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |