6063 | 2023-10-29 11:27:31 | Gervid | Forgó rulettkerék | cpp17 | Time limit exceeded 20/100 | 1.577s | 18328 KiB |
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n, m, i, j, k, x;
cin >> n >> m;
vector<string> patterns(1);
cin >> patterns[0];
vector<int> count(1, 1);
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 && 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 | 1816 KiB | ||||
2 | Accepted | 3ms | 2052 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2304 KiB | ||||
4 | Accepted | 3ms | 2516 KiB | ||||
5 | Accepted | 3ms | 2704 KiB | ||||
6 | Accepted | 4ms | 3048 KiB | ||||
7 | Accepted | 8ms | 3188 KiB | ||||
8 | Accepted | 4ms | 3144 KiB | ||||
9 | Accepted | 4ms | 3400 KiB | ||||
subtask3 | 0/15 | ||||||
10 | Accepted | 35ms | 4028 KiB | ||||
11 | Accepted | 64ms | 4664 KiB | ||||
12 | Accepted | 217ms | 5264 KiB | ||||
13 | Accepted | 50ms | 5412 KiB | ||||
14 | Accepted | 78ms | 5700 KiB | ||||
15 | Accepted | 1.093s | 6584 KiB | ||||
16 | Accepted | 1.207s | 7164 KiB | ||||
17 | Time limit exceeded | 1.554s | 6220 KiB | ||||
subtask4 | 0/65 | ||||||
18 | Accepted | 310ms | 8096 KiB | ||||
19 | Accepted | 943ms | 8940 KiB | ||||
20 | Accepted | 751ms | 10504 KiB | ||||
21 | Time limit exceeded | 1.557s | 10264 KiB | ||||
22 | Accepted | 992ms | 12144 KiB | ||||
23 | Accepted | 216ms | 12656 KiB | ||||
24 | Time limit exceeded | 1.577s | 12692 KiB | ||||
25 | Accepted | 519ms | 14444 KiB | ||||
26 | Accepted | 629ms | 15584 KiB | ||||
27 | Time limit exceeded | 1.565s | 15596 KiB | ||||
28 | Time limit exceeded | 1.562s | 17204 KiB | ||||
29 | Time limit exceeded | 1.554s | 17976 KiB | ||||
30 | Time limit exceeded | 1.565s | 18328 KiB |