/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 332.0 KiB
#2 Wrong Answer 9ms 588.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int N, M;
    cin >> N >> M;
    
    vector<string> T(N);
    vector<vector<int>> freq(M, vector<int>(26, 0));

    // Read input and populate frequency table
    for (int i = 0; i < N; ++i) {
        cin >> T[i];
        for (int j = 0; j < M; ++j) {
            freq[j][T[i][j] - 'a']++;
        }
    }

    // Construct the best possible S
    string bestS = "";
    for (int j = 0; j < M; ++j) {
        int maxFreq = 0;
        char bestChar = 'a';

        for (int c = 0; c < 26; ++c) {
            if (freq[j][c] > maxFreq) {
                maxFreq = freq[j][c];
                bestChar = 'a' + c;
            }
        }
        bestS += bestChar;
    }

    // Calculate maximum possible score
    int maxScore = 0;
    for (int i = 0; i < N; ++i) {
        int currentScore = 0;
        for (int j = 0; j < M; ++j) {
            if (T[i][j] == bestS[j]) currentScore++;
        }
        maxScore = max(maxScore, currentScore);
    }

    cout << maxScore << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int Tc;
    cin >> Tc;
    while (Tc--) {
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1164 Simple character matching game
Contest
Brain Booster #8
Language
C++17 (G++ 13.2.0)
Submit At
2025-02-17 14:56:00
Judged At
2025-02-17 14:56:00
Judged By
Score
0
Total Time
9ms
Peak Memory
588.0 KiB