/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 516.0 KiB
#2 Accepted 13ms 796.0 KiB
#3 Accepted 9ms 796.0 KiB
#4 Accepted 9ms 948.0 KiB
#5 Accepted 10ms 1.055 MiB
#6 Accepted 9ms 1.027 MiB
#7 Accepted 22ms 1.004 MiB
#8 Accepted 40ms 840.0 KiB
#9 Accepted 62ms 10.176 MiB
#10 Accepted 63ms 10.074 MiB
#11 Accepted 49ms 10.277 MiB
#12 Accepted 59ms 38.695 MiB
#13 Accepted 58ms 38.77 MiB
#14 Accepted 55ms 38.918 MiB
#15 Accepted 57ms 38.902 MiB
#16 Accepted 56ms 39.0 MiB
#17 Accepted 58ms 38.77 MiB
#18 Accepted 65ms 38.922 MiB
#19 Accepted 68ms 38.77 MiB
#20 Accepted 62ms 38.77 MiB
#21 Accepted 234ms 153.52 MiB
#22 Accepted 234ms 153.742 MiB
#23 Accepted 238ms 153.734 MiB
#24 Accepted 231ms 153.734 MiB
#25 Accepted 302ms 153.594 MiB
#26 Accepted 329ms 153.734 MiB
#27 Accepted 329ms 153.73 MiB
#28 Accepted 346ms 153.734 MiB
#29 Accepted 232ms 153.566 MiB
#30 Accepted 240ms 153.73 MiB

Code

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

#define nl '\n'
#define ll long long
#define int long long
#define pii pair<int, int> 



void solve(){
    int n, m; cin >> n >> m;
    int mx = max(n,m);
    int a[mx+2][mx+2];
    int prea[mx+2][mx+2], prera[mx+2][mx+2];
    int sufa[mx+2][mx+2], sufra[mx+2][mx+2];
    memset(a, 0, sizeof a);
    memset(prea, 0, sizeof prea);
    memset(sufa, 0, sizeof sufa);
    memset(prera, 0, sizeof prera);
    memset(sufra, 0, sizeof sufra);
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=m;++j){
            char c; cin >> c;
            a[i][j] = (c == '+');
        }
    }
    for(int i=1;i<=mx;++i) {
        for(int j=1;j<=mx;++j) {
            prea[i][j] = a[i][j];
            if(a[i][j])
                prea[i][j] = prea[i][j-1] + a[i][j];
        }
        for(int j=mx;j>=1;--j) {
            sufa[i][j] = a[i][j];
            if(a[i][j])
                sufa[i][j] = sufa[i][j+1] + a[i][j];
        }
    }
    for(int i=1;i<=mx;++i) {
        for(int j=1;j<=mx;++j) {
            prera[i][j] = a[i][j];
            if(a[i][j])
                prera[i][j] = prera[i-1][j] + a[i][j];
        }
    }
    for(int i=mx;i>=1;--i) {
        for(int j=mx;j>=1;--j) {
            sufra[i][j] = a[i][j];
            if(a[i][j])
                sufra[i][j] = sufra[i+1][j] + a[i][j];
        }
    }
    // for(int i=1;i<=mx;++i) {
    //     for(int j=1;j<=mx;++j){
    //         cout << sufra[i][j] << " \n"[j==mx];
    //     }
    // }
    int ans = 0;
    for(int i=1;i<=mx;++i){
        for(int j=1;j<=mx;++j){
            if(a[i][j] == 0) continue;
            int left = prea[i][j];
            int right = prera[i][j];
            int top = sufa[i][j];
            int down = sufra[i][j];
            int now = min({left , right , top , down})*4 - 3 ;
            ans = max(ans, now);
            // cerr << i << " " << j << " " << now << endl;
        }
    }
    cout << ans << nl;
}

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

    int t = 1, tc = 0;
    cin >> t ;
    while(t--){
        // cout << "Case " << ++tc  << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 06:24:25
Judged At
2024-12-09 06:24:25
Judged By
Score
100
Total Time
346ms
Peak Memory
153.742 MiB