61002023-10-29 19:07:37MCDaveForgó rulettkerékcpp17Time limit exceeded 35/1001.557s14452 KiB
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

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);

		sortedStr = min(sortedStr, shiftedStr);
	}

	return sortedStr;
}

int main() {
	int n, m;
	cin >> n >> m;
	unordered_map<string, int> sortedCount;

	for (int i = 0; i < n; i++) {
		string input;
		cin >> input;
		string sortedStr = shiftToSort(input);
		sortedCount[sortedStr]++;
	}

	long long out = 0;

	for (const auto& entry : sortedCount) {
		int count = entry.second;
		out += (count * 1LL * (count - 1)) / 2;
	}

	cout << out;

}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1708 KiB
2Accepted3ms1932 KiB
subtask220/20
3Accepted3ms2144 KiB
4Accepted3ms2224 KiB
5Accepted3ms2480 KiB
6Accepted4ms2596 KiB
7Accepted4ms2828 KiB
8Accepted4ms2908 KiB
9Accepted4ms3108 KiB
subtask315/15
10Accepted54ms3244 KiB
11Accepted68ms3400 KiB
12Accepted63ms3496 KiB
13Accepted52ms3852 KiB
14Accepted61ms3888 KiB
15Accepted68ms4468 KiB
16Accepted68ms4984 KiB
17Accepted68ms4760 KiB
subtask40/65
18Accepted143ms4260 KiB
19Accepted135ms4296 KiB
20Accepted598ms5036 KiB
21Accepted210ms4872 KiB
22Accepted162ms4700 KiB
23Accepted312ms4568 KiB
24Accepted148ms5268 KiB
25Time limit exceeded1.557s3768 KiB
26Accepted118ms4608 KiB
27Accepted150ms5540 KiB
28Time limit exceeded1.557s4792 KiB
29Accepted119ms6292 KiB
30Accepted137ms14452 KiB