Wrong Answer
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Tc;
cin >> Tc;
while (Tc--) {
int N, M;
cin >> N >> M;
vector<string> T(N);
for (int i = 0; i < N; ++i) {
cin >> T[i];
}
// Count frequency of each string
unordered_map<string, int> freq;
for (const string& s : T) {
freq[s]++;
}
// Find the most frequent string
string S_initial;
int max_freq = 0;
for (const auto& [s, cnt] : freq) {
if (cnt > max_freq) {
max_freq = cnt;
S_initial = s;
}
}
// Calculate score if no change is made
int score_no_change = 0;
for (const string& s : T) {
if (s == S_initial) {
score_no_change += M;
} else {
for (int j = 0; j < M; ++j) {
if (s[j] == S_initial[j]) {
score_no_change++;
}
}
}
}
// Calculate score if change is made
int max_score = score_no_change;
for (int i = 0; i < N; ++i) {
string S_new = T[i];
int score_change = 0;
for (int k = 0; k < N; ++k) {
if (k <= i) {
// Before change, use S_initial
if (T[k] == S_initial) {
score_change += M;
} else {
for (int j = 0; j < M; ++j) {
if (T[k][j] == S_initial[j]) {
score_change++;
}
}
}
} else {
// After change, use S_new
if (T[k] == S_new) {
score_change += M;
} else {
for (int j = 0; j < M; ++j) {
if (T[k][j] == S_new[j]) {
score_change++;
}
}
}
}
}
max_score = max(max_score, score_change);
}
cout << max_score << "\n";
}
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 15:00:23
- Judged At
- 2025-02-17 15:00:23
- Judged By
- Score
- 0
- Total Time
- 807ms
- Peak Memory
- 696.0 KiB