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>
#define int long long
#define pb push_back
#define endl '\n'
using namespace std;
const int MOD = 1e9 + 7;
const int p = 31;
map<string,int> dp;
void solve(){
int n,k; cin>>n>>k;
//i=1;
for(int i=1;i<=k;i++){
string s; cin>>s;
dp[s]=1;
}
for(int i=2; i<=n-1; i++){
for(int j=1;j<=k;j++){
string s,s1,s2; cin>>s;
s1=s.substr(0, i-1);
s2=s.substr(1, i-1);
if(s1==s2)
dp[s]=dp[s1];
else
dp[s]=(dp[s1]+dp[s2])%MOD;
}
}
//i=n;
int ans=0;
for(int j=1;j<=k;j++){
string s,s1,s2; cin>>s;
s1=s.substr(0, n-1);
s2=s.substr(1, n-1);
if(s1==s2)
ans=(ans+dp[s1])%MOD;
else
ans=(ans+dp[s1]+dp[s2])%MOD;
}
cout<<ans;
}
int32_t main(){
cin.tie(0)->sync_with_stdio(false);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |