// Author: Ngo Ba Van
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
using ii=pair<ll,ll>;
const ll N=1e3+5,M=1e9+7;
ll n,res,dp[N][N],k;
map<string,ll>m[2];
string s;
void nhap()
{
cin>>n>>k; int a=0,b=1;
m[0][""]=1;
for (int i=1;i<=n;i++)
{
for (int j=1;j<=k;j++)
{
res=0;
cin>>s; string t1,t2;
t1=s.substr(0,s.size()-1);
t2=s.substr(1,s.size()-1);
if (m[a].count(t1)) res+=m[a][t1];
if (t1!=t2)
{
if (m[a].count(t2)) res+=m[a][t2];
}
m[b][s]=(m[b][s]+res)%M;
}
swap(a,b);
m[b].clear();
}
res=0;
for (auto i:m[a])
res+=i.se;
cout<<res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#define task "a"
//define task ""
int t=1;
//cin>>t;
while (t--)
nhap();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
6 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
4 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
6 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |