Accepted
Code
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5;
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n, m;
cin >> n >> m;
vector< vector< vector<int> > > A(26, vector< vector<int> >(n + 1, vector<int>(m)));
for (int i = 1; i <= n; i++)
{
string s;
cin >> s;
for (int j = 0; j < 26; j++)
for (int k = 0; k < m; k++)
A[j][i][k] = A[j][i - 1][k] + (s[k] - 'a' == j);
}
int res = 0;
for (int i = 1; i <= n; i++)
{
int curr = 0;
for (int k = 0; k < m; k++)
{
int max1 = 0, max2 = 0;
for (int j = 0; j < 26; j++)
{
max1 = max(max1, A[j][i][k]);
max2 = max(max2, A[j][n][k] - A[j][i][k]);
}
curr += max1 + max2;
}
res = max(res, curr);
}
cout << res << "\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 16:51:09
- Judged At
- 2025-02-17 16:51:09
- Judged By
- Score
- 100
- Total Time
- 402ms
- Peak Memory
- 29.125 MiB