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>
using namespace std;
#define itn long long
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=2003;
string a[N][N];
const int mod=1e9+7;
map<string,int>dp;
signed main(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++)cin>>a[i][j];
}
for(int i=1;i<=k;i++){
dp[a[1][i]]++;
}
for(int i=2;i<=n;i++){
set<string>st;
for(int j=1;j<=k;j++){
string x=a[i][j];
st.insert(x);
}
for(auto x:st){
string y=x;
y.pop_back();
dp[x]+=dp[y];
if(x.substr(1,i-1)!=y)dp[x]+=dp[x.substr(1,i-1)];
dp[x]%=mod;
}
}
int ans=0;
set<string>st;
for(int i=1;i<=k;i++){
st.insert(a[n][i]);
}
for(auto x:st){
ans+=dp[x];
ans%=mod;
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |