44132023-03-27 18:40:48balaaaazsŐsi szövegcpp14Runtime error 36/100250ms523632 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<string> S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    
    vector<vector<int>> dist(N, vector<int>(N, 0));
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int d = 0;
            for (int k = 0; k < K; k++) {
                if (S[i][k] != S[j][k]) {
                    d++;
                }
            }
            dist[i][j] = d;
            dist[j][i] = d;
        }
    }
    
    vector<double> avgdist(N, 0.0);
    double divisor = N - 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i != j) {
                avgdist[i] += dist[i][j];
            }
        }
        avgdist[i] /= divisor;
    }
    
    int min_index = min_element(avgdist.begin(), avgdist.end()) - avgdist.begin();
    cout << min_index << endl;
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1808 KiB
2Accepted3ms2068 KiB
subtask24/4
3Accepted3ms2284 KiB
4Accepted3ms2496 KiB
5Accepted7ms2988 KiB
subtask311/11
6Accepted3ms2724 KiB
7Accepted3ms2976 KiB
8Accepted8ms3696 KiB
9Accepted8ms3692 KiB
10Accepted8ms3952 KiB
subtask421/21
11Accepted3ms3232 KiB
12Accepted3ms3264 KiB
13Accepted3ms3264 KiB
14Accepted3ms3256 KiB
15Accepted3ms3332 KiB
16Accepted3ms3272 KiB
subtask50/25
17Accepted28ms5020 KiB
18Accepted72ms5988 KiB
19Runtime error240ms523632 KiB
20Runtime error246ms523596 KiB
21Runtime error250ms523564 KiB
22Runtime error250ms523332 KiB
23Runtime error247ms523320 KiB
subtask60/39
24Accepted28ms5716 KiB
25Accepted72ms6676 KiB
26Runtime error239ms522656 KiB
27Runtime error246ms522660 KiB
28Runtime error250ms522536 KiB
29Runtime error246ms522560 KiB
30Runtime error247ms522536 KiB
31Runtime error247ms522532 KiB