65632023-12-11 18:33:53GervidForgó rulettkerékcpp17Wrong answer 0/1001.565s5584 KiB
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, m, i, j, k;
    cin >> n >> m;

	vector<int> count;
	vector<string> orderedcodes;
	string raw;

	for (i = 0; i < n; i++)
	{
		cin >> raw;
		
		raw += raw;

		vector<int> candidates;

		char min = 'z';

		for (j = 0; j < m; j++)
		{
			if (raw[j] < min)
			{
				min = raw[j];
			}
		}

		for (j = 0; j < m; j++)
		{
			if (raw[j] == min)
			{
				candidates.push_back(j);
			}
		}

		j = 1;
		while (candidates.size() > 1 && j < m)
		{
			min = 'z';
			for (k = 0; k < candidates.size(); k++)
			{
				if (raw[candidates[k]+j] < min)
				{
					min = raw[candidates[k] + j];
				}
			}

			for (k = 0; k < candidates.size(); k++)
			{
				if (raw[candidates[k]+j] > min)
				{
					candidates.erase(candidates.begin()+k);
					if (candidates.size() == 1)
					{
						break;
					}
				}
			}

			j++;
		}

		string ordered;

		for (j = 0; j < m; j++)
		{
			ordered.push_back(raw[candidates[0] + j]);
		}

		for (j = 0; j < orderedcodes.size(); j++)
		{
			if (ordered == orderedcodes[j])
			{
				count[j]++;
				break;
			}
		}

		if (j == orderedcodes.size())
		{
			orderedcodes.push_back(ordered);
			count.push_back(1);
		}
	}

	int out = 0;

	for (i = 0; i < count.size(); i++)
	{
		out += (count[i] * (count[i] - 1)) >> 1;
	}

	cout << out;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Accepted3ms2088 KiB
subtask20/20
3Accepted3ms2212 KiB
4Wrong answer3ms2300 KiB
5Wrong answer3ms2656 KiB
6Wrong answer4ms2748 KiB
7Accepted4ms2932 KiB
8Wrong answer4ms3156 KiB
9Wrong answer4ms3224 KiB
subtask30/15
10Wrong answer48ms3116 KiB
11Wrong answer68ms3192 KiB
12Wrong answer59ms3584 KiB
13Wrong answer48ms3464 KiB
14Wrong answer50ms3392 KiB
15Wrong answer54ms3896 KiB
16Accepted52ms4260 KiB
17Wrong answer50ms3828 KiB
subtask40/65
18Wrong answer108ms3540 KiB
19Wrong answer101ms3540 KiB
20Wrong answer759ms4332 KiB
21Wrong answer233ms4308 KiB
22Wrong answer128ms3940 KiB
23Wrong answer377ms3756 KiB
24Wrong answer130ms4536 KiB
25Wrong answer1.126s4516 KiB
26Wrong answer177ms3980 KiB
27Wrong answer168ms4572 KiB
28Time limit exceeded1.562s5584 KiB
29Wrong answer402ms4996 KiB
30Time limit exceeded1.565s4160 KiB