# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
998997 | vjudge1 | Trener (COCI20_trener) | C++17 | 772 ms | 8688 KiB |
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;
const int mod = 1e9+7, base = 727;
int main()
{
int n, k;
cin >> n >> k;
string s[n][k];
int hsh[n][k];
for(int i = 0; i < n; i ++)
for(int j = 0; j < k; j++)
cin >> s[i][j];
int dp[n][k];
for(int i = 0; i < k; i++)
dp[0][i] = 1;
for(int i = 0; i < k ; i++)
hsh[0][i] = s[0][i][0] % mod;
for(int i = 1; i < n; i ++)
{
for(int j = 0; j < k; j++)
{
dp[i][j] = 0;
int hshp = 0, hshs = 0, hshc = 0;
for(int l = 0; l < s[i][j].size(); l++)
hshc = (1ll * hshc * base % mod + s[i][j][l]) % mod;
for(int l = 0; l + 1 < s[i][j].size(); l++)
hshp = (1ll * hshp * base % mod + s[i][j][l]) % mod;
for(int l = 1; l < s[i][j].size(); l++)
hshs = (1ll * hshs * base % mod + s[i][j][l]) % mod;
hsh[i][j] = hshc;
for(int l = 0; l < k; l++)
if(hsh[i - 1][l] == hshp || hsh[i - 1][l] == hshs)
dp[i][j] = (dp[i][j] + dp[i - 1][l]) % mod;
// cerr << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
}
}
int ans = 0;
for(int i = 0; i < k; i ++)
ans = (ans + dp[n - 1][i]) % mod;
cout << ans << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |