6295 | 2023-11-13 16:30:51 | aballa | Forgó rulettkerék | cpp17 | Time limit exceeded 35/100 | 1.549s | 27220 KiB |
#include <bits/stdc++.h>
int n, m;
std::string tagid(std::string str) {
std::string s = str + str, k, min;
min = str;
for(int i = 1; i < m; i++) {
k = std::string(&s[i], &s[i+m]);
if(min > k) min = k;
}
return min;
}
int main() {
long long count = 0, cc = 1;
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::string cache;
std::vector<std::string> ids;
std::vector<int> veccount;
std::unordered_map<std::string, int> map;
std::cin >> n >> m;
for(int i = 0; i < n; i++) {
std::cin >> cache;
ids.push_back(tagid(cache));
}
map.insert({ids[0], 0});
veccount.push_back(1);
for(int i = 1; i < n; i++) {
if (auto search = map.find(ids[i]); search != map.end()) {
veccount[search->second]++;
}
else {
map.insert({ids[i], cc});
veccount.push_back(1);
cc++;
}
}
for(const auto x : veccount) {
count += x*(x-1);
}
std::cout << count/2 << std::flush;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2052 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2284 KiB | ||||
4 | Accepted | 3ms | 2316 KiB | ||||
5 | Accepted | 3ms | 2452 KiB | ||||
6 | Accepted | 3ms | 2556 KiB | ||||
7 | Accepted | 3ms | 2904 KiB | ||||
8 | Accepted | 3ms | 2764 KiB | ||||
9 | Accepted | 3ms | 2764 KiB | ||||
subtask3 | 15/15 | ||||||
10 | Accepted | 17ms | 3472 KiB | ||||
11 | Accepted | 21ms | 3924 KiB | ||||
12 | Accepted | 20ms | 3888 KiB | ||||
13 | Accepted | 17ms | 3940 KiB | ||||
14 | Accepted | 20ms | 4108 KiB | ||||
15 | Accepted | 23ms | 4664 KiB | ||||
16 | Accepted | 23ms | 4932 KiB | ||||
17 | Accepted | 21ms | 4880 KiB | ||||
subtask4 | 0/65 | ||||||
18 | Accepted | 45ms | 5876 KiB | ||||
19 | Accepted | 41ms | 6196 KiB | ||||
20 | Accepted | 201ms | 6256 KiB | ||||
21 | Accepted | 65ms | 7008 KiB | ||||
22 | Accepted | 52ms | 6584 KiB | ||||
23 | Accepted | 120ms | 5724 KiB | ||||
24 | Accepted | 48ms | 6904 KiB | ||||
25 | Accepted | 903ms | 6260 KiB | ||||
26 | Accepted | 75ms | 20508 KiB | ||||
27 | Accepted | 54ms | 8856 KiB | ||||
28 | Time limit exceeded | 1.549s | 4612 KiB | ||||
29 | Accepted | 75ms | 20656 KiB | ||||
30 | Accepted | 97ms | 27220 KiB |