This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Aber der schlimmste Fiend, dem du begegnen kannst, wirst du immer dir selber sein
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define rev reverse
#define all(x) x.begin(),x.end()
#define acc accumulate
#define sz size()
#define MOD 1000000007
#define rall(x) x.rbegin(),x.rend()
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const int N = 2e5 + 5;
inline void solve(){
int n, k;
cin >> n >> k;
map<string, int> mp;
string ma[n][k];
for(int i = 0; i < n; i++){
for(int j = 0; j < k; j++){
cin >> ma[i][j];
}
}
for(int i = 0; i < k; i++){
mp[ma[n-1][i]]++;
}
for(int i = n-1; i > 0; i--){
for(int j = 0; j < k; j++){
string s1 = ma[i][j].substr(0, i), s2 = ma[i][j].substr(1, i);
mp[s1] = (mp[ma[i][j]] + mp[s1]) % MOD;
if(s1 != s2){
mp[s2] = (mp[s2] + mp[ma[i][j]]) % MOD;
}
}
}
int ans = 0;
for(int i = 0; i < k; i++){
ans = (ans + mp[ma[0][i]]) % MOD;
}
cout << ans << endl;
}
int main(){
fast_io
int t;
t = 1;
while(t--) 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... |