This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int MOD = 1e9 + 7;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define OPEN freopen(".in", "r", stdin); \
freopen(".out", "w", stdout);
#else
#define OPEN void(23);
#endif
int mods[] = {232323233, 232323323, 323232323};
int primes[] = {23 + 6, 23 + 14, 23 + 20};
string arr[55][1505];
array <int, 3> all[55][1505], sol[55][1505], sag[55][1505];
array <int, 3> hashle(string a)
{
int n = a.size();
array <int, 3> vals = {0, 0, 0};
for(int i = 0; i < n; i++)
{
for(int j = 0; j < 3; j++)
{
vals[j] = (vals[j] * primes[j] + (a[i] - 'a' +1)) % mods[j];
}
}
return vals;
}
bool operator== (array <int, 3> &a, array <int, 3> &b)
{
bool ok = true;
for(int i = 0; i < 3; i++) ok &= a[i] == b[i];
return ok;
}
void solve()
{
int n, k; cin >> n >> k;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= k; j++)
cin >> arr[i][j];
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= k; j++)
{
all[i][j] = hashle(arr[i][j]);
sol[i][j] = hashle(arr[i][j].substr(0, i -1));
sag[i][j] = hashle(arr[i][j].substr(1, i -1));
}
}
vector <int> dp(k +1, 1);
for(int i = 1; i <= n -1; i++)
{
vector <int> dp2(k +1);
for(int j = 1; j <= k; j++)
{
for(int c = 1; c <= k; c++)
{
if(all[i][j] == sol[i +1][c] || all[i][j] == sag[i +1][c])
dp2[c] = (dp2[c] + dp[j]) % MOD;
}
}
swap(dp, dp2);
}
int cev = 0;
for(int i = 1; i <= k; i++) cev = (cev + dp[i]) % MOD;
cout << cev;
return;
}
int32_t main()
{
OPEN;
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1; //cin >> t;
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... |