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 int long long
const int mod = 1e9 + 7;
void solve(){
int n,k;cin >> n >> k;
string v[n+1][k];
map < string , int > mpa;
for(int i = 1;i<=n;i++){
for(int j = 0;j<k;j++){
cin >> v[i][j];
}
}
for(int i = 0;i<k;i++)mpa[v[1][i]]++;
for(int i = 2;i<=n;i++){
for(int j = 0;j<k;j++){
if(string(v[i][j].begin() , v[i][j].end()-1) == string(v[i][j].begin()+1 , v[i][j].end()))(mpa[v[i][j]] += mpa[string(v[i][j].begin() , v[i][j].end()-1)] % mod) %= mod;
else (mpa[v[i][j]] += (mpa[string(v[i][j].begin() , v[i][j].end()-1)] + mpa[string(v[i][j].begin()+1 , v[i][j].end())]) % mod) %= mod;
}
}
int ans = 0;
for(int i = 0;i<k;i++)ans = (ans + mpa[v[n][i]]) % mod;
cout << ans << endl ;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |