// 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,int>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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
324 KB |
Output is correct |
5 |
Correct |
5 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
5 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Incorrect |
4 ms |
468 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |