6064 | 2023-10-29 11:42:43 | Gervid | Forgó rulettkerék | cpp17 | Time limit exceeded 35/100 | 1.565s | 5904 KiB |
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n, m, i, j, k, x;
cin >> n >> m;
vector<string> patterns(1);
patterns.reserve(n);
cin >> patterns[0];
vector<int> count(1, 1);
count.reserve(n);
string tag;
for (i = 1; i < n; i++)
{
cin >> tag;
x = 0, k = 0;
for (j = 0; j < patterns.size(); j++)
{
for (k = 0; k < m; k++)
{
while (x < m && (x + k < m && tag[x+k] == patterns[j][x]) || (x + k >= m && tag[x + k - m] == patterns[j][x]))
{
x++;
}
if (x == m)
{
count[j]++;
break;
}
x = 0;
}
if (x == m)
{
break;
}
}
if (x != m)
{
patterns.push_back(tag);
count.push_back(1);
}
}
int sum = 0;
for (i = 0; i < count.size(); i++)
{
if (count[i] > 1)
{
sum += (count[i] * (count[i]-1)) >> 1;
}
}
cout << sum;
}
//4 4
//abcd
//xbcd
//cdab
//dabc
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1684 KiB | ||||
2 | Accepted | 3ms | 1932 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 2ms | 2008 KiB | ||||
4 | Accepted | 3ms | 2056 KiB | ||||
5 | Accepted | 3ms | 2276 KiB | ||||
6 | Accepted | 3ms | 2488 KiB | ||||
7 | Accepted | 6ms | 2740 KiB | ||||
8 | Accepted | 3ms | 2956 KiB | ||||
9 | Accepted | 3ms | 3180 KiB | ||||
subtask3 | 15/15 | ||||||
10 | Accepted | 25ms | 3412 KiB | ||||
11 | Accepted | 43ms | 3460 KiB | ||||
12 | Accepted | 126ms | 3516 KiB | ||||
13 | Accepted | 32ms | 3508 KiB | ||||
14 | Accepted | 52ms | 3844 KiB | ||||
15 | Accepted | 626ms | 4196 KiB | ||||
16 | Accepted | 670ms | 4592 KiB | ||||
17 | Accepted | 1.014s | 4496 KiB | ||||
subtask4 | 0/65 | ||||||
18 | Accepted | 182ms | 4228 KiB | ||||
19 | Accepted | 523ms | 4416 KiB | ||||
20 | Accepted | 432ms | 5236 KiB | ||||
21 | Accepted | 1.243s | 5288 KiB | ||||
22 | Accepted | 554ms | 4872 KiB | ||||
23 | Accepted | 134ms | 4816 KiB | ||||
24 | Time limit exceeded | 1.557s | 4384 KiB | ||||
25 | Accepted | 303ms | 5220 KiB | ||||
26 | Accepted | 377ms | 4924 KiB | ||||
27 | Time limit exceeded | 1.526s | 4640 KiB | ||||
28 | Time limit exceeded | 1.565s | 5068 KiB | ||||
29 | Time limit exceeded | 1.514s | 5904 KiB | ||||
30 | Time limit exceeded | 1.557s | 5100 KiB |