62952023-11-13 16:30:51aballaForgó rulettkerékcpp17Time limit exceeded 35/1001.549s27220 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2052 KiB
subtask220/20
3Accepted3ms2284 KiB
4Accepted3ms2316 KiB
5Accepted3ms2452 KiB
6Accepted3ms2556 KiB
7Accepted3ms2904 KiB
8Accepted3ms2764 KiB
9Accepted3ms2764 KiB
subtask315/15
10Accepted17ms3472 KiB
11Accepted21ms3924 KiB
12Accepted20ms3888 KiB
13Accepted17ms3940 KiB
14Accepted20ms4108 KiB
15Accepted23ms4664 KiB
16Accepted23ms4932 KiB
17Accepted21ms4880 KiB
subtask40/65
18Accepted45ms5876 KiB
19Accepted41ms6196 KiB
20Accepted201ms6256 KiB
21Accepted65ms7008 KiB
22Accepted52ms6584 KiB
23Accepted120ms5724 KiB
24Accepted48ms6904 KiB
25Accepted903ms6260 KiB
26Accepted75ms20508 KiB
27Accepted54ms8856 KiB
28Time limit exceeded1.549s4612 KiB
29Accepted75ms20656 KiB
30Accepted97ms27220 KiB