# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
845267 |
2023-09-06T12:54:37 Z |
vjudge1 |
Trener (COCI20_trener) |
C++17 |
|
126 ms |
2640 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 5, MOD = 1e9 + 7, p = 29;
ll dp[55][1505], h[55][1505][3], us[60];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
us[0] = 1;
for(int i = 1; i < 60; i++)
{
us[i] = (us[i - 1] * p) % MOD;
}
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= k; j++)
{
string str;
cin >> str;
str = "#" + str;
for(int l = 1; l <= i; l++)
{
h[i][j][0] = (h[i][j][0] + (str[l] - 'a' + 1) * us[l]) % MOD;
if(l == i - 1)
h[i][j][1] = h[i][j][0];
}
for(int l = 2; l <= i; l++)
{
h[i][j][2] = (h[i][j][2] + (str[l] - 'a' + 1) * us[l - 1]) % MOD;
}
// cout << i << " " << j << " " << h[i][j][0] << " " << h[i][j][1] << " " << h[i][j][2] << '\n';
}
}
for(int i = 1; i <= k; i++)
dp[1][i] = 1;
for(int i = 1; i < n; i++)
{
for(int j = 1; j <= k; j++)
{
for(int l = 1; l <= k; l++)
{
if(h[i][j][0] == h[i + 1][l][1])
{
if(dp[i + 1][l] == 0)
{
dp[i + 1][l] = dp[i][j];
}
else
{
dp[i + 1][l] = (dp[i + 1][l] + dp[i][j]) % MOD;
}
}
else if(h[i][j][0] == h[i + 1][l][2])
{
if(dp[i + 1][l] == 0)
{
dp[i + 1][l] = dp[i][j];
}
else
{
dp[i + 1][l] = (dp[i + 1][l] + dp[i][j]) % MOD;
}
}
}
}
}
// for(int i = 1; i <= n; i++)
// {
// for(int j = 1; j <= k; j++)
// {
// cout << dp[i][j] << " " ;
// }
// cout << '\n';
// }
ll ans = 0;
for(int i = 1; i <= k; i++)
ans = (ans + dp[n][i]) % MOD;
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
856 KB |
Output is correct |
2 |
Correct |
3 ms |
860 KB |
Output is correct |
3 |
Correct |
2 ms |
860 KB |
Output is correct |
4 |
Correct |
3 ms |
856 KB |
Output is correct |
5 |
Correct |
3 ms |
856 KB |
Output is correct |
6 |
Correct |
3 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
4 ms |
856 KB |
Output is correct |
6 |
Correct |
3 ms |
860 KB |
Output is correct |
7 |
Correct |
2 ms |
860 KB |
Output is correct |
8 |
Correct |
3 ms |
856 KB |
Output is correct |
9 |
Correct |
3 ms |
856 KB |
Output is correct |
10 |
Correct |
3 ms |
856 KB |
Output is correct |
11 |
Correct |
3 ms |
860 KB |
Output is correct |
12 |
Correct |
126 ms |
2628 KB |
Output is correct |
13 |
Correct |
125 ms |
2640 KB |
Output is correct |
14 |
Incorrect |
125 ms |
2640 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |