/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 58ms 1.207 MiB
#3 Wrong Answer 77ms 1.137 MiB

Code

#include <bits/stdc++.h>
#define int long long 
#define ll long long
#define ull unsigned long long
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define max_ele(v) *max_element(v.begin(), v.end())
#define min_ele(v) *min_element(v.begin(), v.end())
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v) reverse(v.begin(), v.end())
#define REV_SORT(v) sort((v).begin(), (v).end(), greater<>())
#define all(v) v.begin(), v.end()
#define vint vector<int>
#define u_set unordered_set
#define u_map unordered_map
#define setbit(x) __builtin_popcount(x)
#define lead_zero(x) __builtin_clz(x) 
#define trail_zero(x) __builtin_ctz(x) 
#define coutall(v) for(auto &&it : v) cout << it <<" "
#define coutnl(v) for(auto &&it : v) cout << it <<'\n'
#define cinall(v) for(auto &&it : v) cin >> it
#define cin2d(v) for(auto &&row : v) for(auto &&element : row) cin >> element;
#define cout2d(v) for (const auto& row : v) { for (const auto& element : row) cout << element << ' '; cout << '\n';}
#define nl cout << '\n';
#define endl '\n';
using namespace std;
#define m1(x) template<class T, class... U> void x(T&& a, U&&... b) 
#define m2(x) (int[]){(x forward<U>(b),0)...}
m1(print) { cout << forward<T>(a);  m2(cout << " " <<); cout << "\n"; } 
m1(read) { cin >> forward<T>(a); m2(cin >>); }
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;

void debug_mode(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}

void solve();
int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    //debug_mode();
    int TestCase = 1;
    cin >> TestCase; 
    int case_no = 1;
    while (TestCase--){
        // cout << "Case " << case_no++ << ": ";
        solve();
        // cout << '\n';
    }
    return 0;
}

void solve(){
    int n, m; cin >> n >> m;
    vector<string> vect(n);
    cinall(vect);
    vector<priority_queue<int>> pq(m);//for up-down match kore kora
    vector<priority_queue<int>> pqq(n);//for left-right match kore kora
    
    for(int c = 0; c < m; c++){
        vint f(26);
        for(int r = 0; r < n; r++){
            f[vect[r][c] - 'a']++;
        }
        for(int x = 0; x < 26; x++){
            pq[c].push(f[x]);
        }
    }

    for(int r = 0; r < n; r++){
        vint f(26);
        for(int c = 0; c < m; c++){
            f[vect[r][c] - 'a']++;
        }
        for(int x = 0; x < 26; x++){
            pqq[r].push(f[x]);
        }
    }

    // for(int i = 0; i < m; i++){
    //     print(pq[i].top());
    // }
    // return;

    int res = 0;
    for(int i = 0; i < m; i++){
        res += (pq[i].top());
        pq[i].pop();
    }
    int mx = 0;
    for(int i = 0; i < m; i++){
        if(!pq[i].empty()) mx = max(mx, pq[i].top());
    }


    int res2 = 0;
    for(int i = 0; i < n; i++){
        res2 += (pqq[i].top());
        pqq[i].pop();
    }


    int mxx = 0;
    for(int i = 0; i < n; i++){
        if(!pqq[i].empty()) mxx = max(mx, pqq[i].top());
    }
    // print(mxx);
    // print(res2);
    if(mxx == 0) mxx = 1;
    if(mx == 0) mx = 1;
    print(max(res + mx - 1, res2 + mxx - 1));
}

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:18:35
Judged At
2025-02-17 15:18:35
Judged By
Score
2
Total Time
77ms
Peak Memory
1.207 MiB