60632023-10-29 11:27:31GervidForgó rulettkerékcpp17Time limit exceeded 20/1001.577s18328 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
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1816 KiB
2Accepted3ms2052 KiB
subtask220/20
3Accepted3ms2304 KiB
4Accepted3ms2516 KiB
5Accepted3ms2704 KiB
6Accepted4ms3048 KiB
7Accepted8ms3188 KiB
8Accepted4ms3144 KiB
9Accepted4ms3400 KiB
subtask30/15
10Accepted35ms4028 KiB
11Accepted64ms4664 KiB
12Accepted217ms5264 KiB
13Accepted50ms5412 KiB
14Accepted78ms5700 KiB
15Accepted1.093s6584 KiB
16Accepted1.207s7164 KiB
17Time limit exceeded1.554s6220 KiB
subtask40/65
18Accepted310ms8096 KiB
19Accepted943ms8940 KiB
20Accepted751ms10504 KiB
21Time limit exceeded1.557s10264 KiB
22Accepted992ms12144 KiB
23Accepted216ms12656 KiB
24Time limit exceeded1.577s12692 KiB
25Accepted519ms14444 KiB
26Accepted629ms15584 KiB
27Time limit exceeded1.565s15596 KiB
28Time limit exceeded1.562s17204 KiB
29Time limit exceeded1.554s17976 KiB
30Time limit exceeded1.565s18328 KiB