/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 47ms 532.0 KiB
#3 Accepted 47ms 532.0 KiB
#4 Accepted 48ms 600.0 KiB
#5 Accepted 47ms 536.0 KiB
#6 Accepted 49ms 536.0 KiB
#7 Accepted 49ms 536.0 KiB
#8 Accepted 47ms 532.0 KiB
#9 Accepted 46ms 532.0 KiB
#10 Accepted 45ms 660.0 KiB
#11 Accepted 48ms 576.0 KiB
#12 Accepted 50ms 576.0 KiB
#13 Accepted 48ms 580.0 KiB
#14 Accepted 48ms 532.0 KiB
#15 Accepted 47ms 532.0 KiB
#16 Accepted 46ms 532.0 KiB
#17 Accepted 48ms 652.0 KiB
#18 Accepted 46ms 664.0 KiB
#19 Accepted 47ms 576.0 KiB
#20 Accepted 47ms 536.0 KiB
#21 Accepted 48ms 656.0 KiB
#22 Accepted 44ms 1.52 MiB
#23 Accepted 47ms 1.316 MiB
#24 Accepted 49ms 1.508 MiB
#25 Accepted 46ms 1.27 MiB
#26 Accepted 48ms 1.473 MiB
#27 Accepted 48ms 1.52 MiB
#28 Accepted 43ms 1.062 MiB
#29 Accepted 49ms 1.52 MiB
#30 Accepted 42ms 1.52 MiB
#31 Accepted 46ms 1.348 MiB
#32 Accepted 36ms 788.0 KiB
#33 Accepted 37ms 788.0 KiB
#34 Accepted 37ms 788.0 KiB
#35 Accepted 35ms 788.0 KiB
#36 Accepted 36ms 788.0 KiB
#37 Accepted 20ms 1.52 MiB
#38 Accepted 20ms 1.523 MiB
#39 Accepted 19ms 1.566 MiB
#40 Accepted 20ms 1.52 MiB
#41 Accepted 20ms 1.523 MiB
#42 Accepted 67ms 2.355 MiB
#43 Accepted 63ms 2.27 MiB
#44 Accepted 92ms 2.355 MiB
#45 Accepted 56ms 2.27 MiB
#46 Accepted 56ms 2.312 MiB
#47 Accepted 57ms 2.27 MiB
#48 Accepted 56ms 2.27 MiB
#49 Accepted 57ms 2.27 MiB
#50 Accepted 57ms 2.27 MiB

Code

// Created on: 2025-02-17 21:06
// Author: Safwan_Ibrahim

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

#define ll long long
#define endl '\n'

void Try() {
    int num_of_row, num_of_col; cin >> num_of_row >> num_of_col;
    char A[num_of_row + 5][num_of_col + 5];
    for (int row = 1; row <= num_of_row; row++) {
        for (int col = 1; col <= num_of_col; col++) {
            cin >> A[row][col];
        }
    }

    int pref[num_of_row + 5][num_of_col + 5];
    int suf[num_of_row + 5][num_of_col + 5];

    for (int i = 0; i <= num_of_row + 1; i++) {
        for (int j = 0; j <= num_of_col + 1; j++) {
            pref[i][j] = 0;
            suf[i][j] = 0;
        }
    }
    
    
    for (int col = 1; col <= num_of_col; col++) {
        map<char, int>mp;
        for (int row = 1; row <= num_of_row; row++) {
            mp[A[row][col]]++;
            int mx = -1;
            for (auto [x , y] : mp) {
                mx = max(mx, y);
            }
            pref[row][col] = mx;
        }
    }

    for (int col = 1; col <= num_of_col; col++) {
        map<char, int>mp;
        for (int row = num_of_row; row >= 1; row--) {
            mp[A[row][col]]++;
            int mx = -1;
            for (auto [x, y] : mp) {
                mx = max(mx, y);
            }
            suf[row][col] = mx;
        }
    }

    
    // int new_pref[num_of_row + 5][num_of_col + 5];
    // int new_suf[num_of_row + 5][num_of_col + 5];
    
    // for (int i = 0; i <= num_of_row + 1; i++) {
    //     for (int j = 0; j <= num_of_col + 1; j++) {
    //         new_pref[i][j] = 0;
    //         new_suf[i][j] = 0;
    //     }
    // }
    // for (int i = 0; i <= num_of_row + 1; i++) {
    //     for (int j = 0; j <= num_of_col + 1; j++) {
    //         int mx1 = -1, mx2 = -1;
    //         for (int k = 0; k < 26; k++) {
    //             mx1 = max(mx1, pref[i][j][k]);
    //             mx2 = max(mx2, suf[i][j][k]);
    //         }
    //         new_pref[i][j] = mx1;
    //         new_suf[i][j] = mx2;
    //     }
    // }

    ll mx = -1;
    for (int row = 0; row <= num_of_row; row++) {
        ll sum1 = 0, sum2 = 0;
        for (int col = 1; col <= num_of_col; col++) {
            sum1 += pref[row][col];
            sum2 += suf[row + 1][col];
        }
        mx = max(mx, sum1 + sum2);
    }

    cout << mx << endl;
    
}

int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);

    int t = 1; cin >> t;
    for (int i = 1; i <= t; i++) {
        Try();
    }
    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:46:46
Judged At
2025-02-17 16:46:46
Judged By
Score
100
Total Time
92ms
Peak Memory
2.355 MiB