62942023-11-13 16:27:11aballaForgó rulettkerékcpp17Wrong answer 0/1001.57s28440 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 = 0;
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::string cache;
    std::vector<std::string> ids;
    std::vector<int> veccount;
    std::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
1Accepted3ms1892 KiB
2Accepted3ms2084 KiB
subtask20/20
3Accepted3ms2296 KiB
4Accepted3ms2516 KiB
5Wrong answer3ms2748 KiB
6Wrong answer3ms3088 KiB
7Accepted3ms3432 KiB
8Wrong answer3ms3508 KiB
9Wrong answer3ms3708 KiB
subtask30/15
10Wrong answer17ms4520 KiB
11Wrong answer21ms4848 KiB
12Wrong answer20ms5104 KiB
13Wrong answer17ms4764 KiB
14Accepted20ms4948 KiB
15Accepted23ms5448 KiB
16Accepted23ms5720 KiB
17Accepted23ms5484 KiB
subtask40/65
18Wrong answer45ms6376 KiB
19Wrong answer43ms6584 KiB
20Wrong answer199ms6992 KiB
21Wrong answer67ms7436 KiB
22Wrong answer52ms6968 KiB
23Accepted119ms6240 KiB
24Wrong answer48ms7220 KiB
25Wrong answer904ms6980 KiB
26Wrong answer93ms21112 KiB
27Wrong answer57ms9444 KiB
28Time limit exceeded1.57s5240 KiB
29Accepted96ms21180 KiB
30Wrong answer160ms28440 KiB