6097 | 2023-10-29 19:00:51 | MCDave | Forgó rulettkerék | cpp17 | Time limit exceeded 35/100 | 1.574s | 5452 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1848 KiB | ||||
2 | Accepted | 3ms | 2000 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2240 KiB | ||||
4 | Accepted | 3ms | 2328 KiB | ||||
5 | Accepted | 3ms | 2548 KiB | ||||
6 | Accepted | 4ms | 2616 KiB | ||||
7 | Accepted | 4ms | 2756 KiB | ||||
8 | Accepted | 4ms | 2828 KiB | ||||
9 | Accepted | 4ms | 2960 KiB | ||||
subtask3 | 15/15 | ||||||
10 | Accepted | 52ms | 3092 KiB | ||||
11 | Accepted | 67ms | 3104 KiB | ||||
12 | Accepted | 61ms | 3148 KiB | ||||
13 | Accepted | 50ms | 3356 KiB | ||||
14 | Accepted | 61ms | 3816 KiB | ||||
15 | Accepted | 67ms | 4264 KiB | ||||
16 | Accepted | 68ms | 4292 KiB | ||||
17 | Accepted | 68ms | 4264 KiB | ||||
subtask4 | 0/65 | ||||||
18 | Accepted | 140ms | 3800 KiB | ||||
19 | Accepted | 135ms | 3868 KiB | ||||
20 | Accepted | 597ms | 4784 KiB | ||||
21 | Accepted | 209ms | 4768 KiB | ||||
22 | Accepted | 158ms | 4408 KiB | ||||
23 | Accepted | 326ms | 4092 KiB | ||||
24 | Accepted | 152ms | 5052 KiB | ||||
25 | Time limit exceeded | 1.574s | 3736 KiB | ||||
26 | Accepted | 181ms | 4592 KiB | ||||
27 | Accepted | 211ms | 5084 KiB | ||||
28 | Time limit exceeded | 1.554s | 4708 KiB | ||||
29 | Accepted | 437ms | 5452 KiB | ||||
30 | Time limit exceeded | 1.565s | 5012 KiB |