60972023-10-29 19:00:51MCDaveForgó rulettkerékcpp17Time limit exceeded 35/1001.574s5452 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

string shiftToSort(string input) {
	int n = input.length();
	string sortedStr = input;

	for (int shift = 1; shift < n; shift++) {
		string shiftedStr = input.substr(shift) + input.substr(0, shift);

		if (shiftedStr < sortedStr) {
			sortedStr = shiftedStr;
		}
	}

	return sortedStr;
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<string> sorted;
	vector<int> sortedi;
	for (int i = 0; i < n; i++)
	{
		string input;
		cin >> input;
		string sortedStr = shiftToSort(input);
		auto temp1 = find(sorted.begin(), sorted.end(), sortedStr);
		if (temp1 != sorted.end())
		{
			sortedi[temp1-sorted.begin()]++;
		}
		else
		{
			sorted.push_back(sortedStr);
			sortedi.push_back(1);
		}
	}

	int out=0;

	for (int i = 0; i < sorted.size(); i++)
	{
		out += (sortedi[i] * (sortedi[i]-1)) / 2;
	}
	cout << out;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1848 KiB
2Accepted3ms2000 KiB
subtask220/20
3Accepted3ms2240 KiB
4Accepted3ms2328 KiB
5Accepted3ms2548 KiB
6Accepted4ms2616 KiB
7Accepted4ms2756 KiB
8Accepted4ms2828 KiB
9Accepted4ms2960 KiB
subtask315/15
10Accepted52ms3092 KiB
11Accepted67ms3104 KiB
12Accepted61ms3148 KiB
13Accepted50ms3356 KiB
14Accepted61ms3816 KiB
15Accepted67ms4264 KiB
16Accepted68ms4292 KiB
17Accepted68ms4264 KiB
subtask40/65
18Accepted140ms3800 KiB
19Accepted135ms3868 KiB
20Accepted597ms4784 KiB
21Accepted209ms4768 KiB
22Accepted158ms4408 KiB
23Accepted326ms4092 KiB
24Accepted152ms5052 KiB
25Time limit exceeded1.574s3736 KiB
26Accepted181ms4592 KiB
27Accepted211ms5084 KiB
28Time limit exceeded1.554s4708 KiB
29Accepted437ms5452 KiB
30Time limit exceeded1.565s5012 KiB