62822023-11-12 13:35:39aballaForgó rulettkerékcpp17Time limit exceeded 20/1001.578s12552 KiB
#include <bits/stdc++.h>

int n, m;

bool similar(std::string a, std::string b) {
    const std::string c = a+a;
    std::string str;
    for(int i = 0; i < m; i++) {
        str = std::string(&c[i], &c[i+m]);
        if (str == b)
        {
            return 1;
        }
    }
    return 0;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::string cache;
    std::vector<std::string> ids;
    int count = 0;
    int cachecount = 0;

    std::cin >> n >> m;
    for(int i = 0; i < n; i++) {
        std::cin >> cache; 
        ids.push_back(cache);
    }

    for (int i = 0; i < n; i++) {
        if (ids[i] == "#") {continue;}
        cachecount = 0;

        for (int j = 0; j < n-i-1; j++) {
            if (ids[n-j-1] == "#") {continue;}

            if(similar(ids[i], ids[n-j-1])) {
                cachecount++;
                ids[n-j-1] = "#";
            }
        }
        count = count + (cachecount*(cachecount+1))/2;
    }
    std::cout << count;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2060 KiB
subtask220/20
3Accepted3ms2280 KiB
4Accepted3ms2660 KiB
5Accepted3ms2764 KiB
6Accepted6ms2832 KiB
7Accepted19ms2916 KiB
8Accepted6ms3192 KiB
9Accepted7ms3388 KiB
subtask30/15
10Accepted85ms4052 KiB
11Accepted57ms4332 KiB
12Accepted846ms4408 KiB
13Accepted159ms4612 KiB
14Accepted54ms4740 KiB
15Time limit exceeded1.554s3680 KiB
16Time limit exceeded1.549s3660 KiB
17Time limit exceeded1.557s3592 KiB
subtask40/65
18Accepted1.253s6196 KiB
19Time limit exceeded1.572s4464 KiB
20Time limit exceeded1.557s4296 KiB
21Time limit exceeded1.569s4548 KiB
22Time limit exceeded1.569s4640 KiB
23Accepted666ms6260 KiB
24Time limit exceeded1.562s4876 KiB
25Time limit exceeded1.554s5100 KiB
26Time limit exceeded1.575s12508 KiB
27Time limit exceeded1.562s6152 KiB
28Time limit exceeded1.575s6520 KiB
29Time limit exceeded1.565s12552 KiB
30Time limit exceeded1.578s12324 KiB