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 fod(i,a,b) for(int i = (int) (a); i <= (int) (b); i++)
#define fok(i,a,b) for(int i = (int) (a); i >= (int) (b); i--)
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define el '\n'
#define ve vector
#define vi ve<int>
#define vll ve<ll>
#define mask(a) (1LL<<(a))
#define BIT(msk,i) (msk>>(i)&1LL)
using namespace std;
template <class T> bool mini(T &a, T b){ return (a > (b)) ? a = (b), 1 : 0; }
template <class T> bool maxi(T &a, T b){ return (a < (b)) ? a = (b), 1 : 0; }
#define name "trener"
const int MOD = 1e9 + 7;
inline void madd(int &a, int b){
a += b;
if(a >= MOD) a -= MOD;
else if(a < 0) a += MOD;
}
int n, k;
unordered_map <string, int> dp;
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> k;
string s;
fod(i,1,k){
cin >> s;
dp[s]++;
}
fod(i,2,n){
unordered_map <string, int> new_dp;
fod(j,1,k){
string s; cin >> s;
new_dp[s]++;
}
for(auto &x : new_dp){
string x1 = x.fi.substr(0, i - 1);
string x2 = x.fi.substr(1, i - 1);
x.se = 1LL * x.se * (dp[x1] + (x1 != x2 ? dp[x2] : 0)) % MOD;
}
swap(dp, new_dp);
}
int res = 0;
for(auto &x : dp) madd(res, x.se);
cout << res;
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... |