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>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) ll(x.size())
#define pb push_back
#define N 75005
#define M ll(1e9 + 7)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
vector <ll> dp, dpl;
int main()
{
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
vector <string> t(k), b(k);
dp.resize(k);
dpl.resize(k);
for (register int i = 0; i < k; i++) dpl[i] = 1;
for (register int i = 0; i < k; i++) cin >> t[i];
for (register int i = 1; i < n; i++)
{
for (register int j = 0; j < k; j++)
{
string str, str1, str2;
cin >> str;
str1 = str.substr(0, i);
str2 = str.substr(1);
b[j] = str;
for (register int u = 0; u < k; u++)
if (str1 == t[u] || str2 == t[u]) dp[j] = (dp[j] + dpl[u]) % M;
}
t = b;
dpl = dp;
dp.clear();
dp.resize(k, 0ll);
}
ll ans = 0;
for (register int i = 0; i < k; i++) ans = (ans + dpl[i]) % M;
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |