/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 12ms 796.0 KiB
#3 Accepted 7ms 556.0 KiB
#4 Accepted 8ms 584.0 KiB
#5 Accepted 9ms 772.0 KiB
#6 Accepted 7ms 732.0 KiB
#7 Accepted 23ms 796.0 KiB
#8 Accepted 44ms 552.0 KiB
#9 Accepted 45ms 2.27 MiB
#10 Accepted 45ms 2.223 MiB
#11 Accepted 25ms 2.02 MiB
#12 Accepted 36ms 17.02 MiB
#13 Accepted 36ms 16.812 MiB
#14 Accepted 56ms 16.754 MiB
#15 Accepted 36ms 16.945 MiB
#16 Accepted 47ms 17.109 MiB
#17 Accepted 39ms 17.008 MiB
#18 Accepted 40ms 16.758 MiB
#19 Accepted 47ms 16.77 MiB
#20 Accepted 40ms 16.77 MiB
#21 Accepted 223ms 65.844 MiB
#22 Accepted 223ms 65.887 MiB
#23 Accepted 235ms 65.84 MiB
#24 Accepted 253ms 65.844 MiB
#25 Accepted 296ms 65.844 MiB
#26 Accepted 233ms 65.77 MiB
#27 Accepted 234ms 65.848 MiB
#28 Accepted 247ms 66.035 MiB
#29 Accepted 226ms 65.848 MiB
#30 Accepted 237ms 65.629 MiB

Code

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


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<typename T> using o_set = tree<T, null_type, std::less<T>, 
rb_tree_tag, tree_order_statistics_node_update>;


void solve() {
    int n, m;
    cin >> n >> m;
    char g[n + 5][m + 5];
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) cin >> g[i][j];
    }

    int rs[n + 5][m + 5], rr[n + 5][m + 5], cs[n + 5][m + 5], cr[n + 5][m + 5];
    memset(rs, 0, sizeof(rs));
    memset(rr, 0, sizeof(rr));
    memset(cs, 0, sizeof(cs));
    memset(cr, 0,sizeof(cr));
    //for (int i = 0; i)

    // for (int i = 1; i <= n; i++) {
    //     for (int j = 1; j <= m; j++) cout << cr[i][j] << " \n"[j == m];
    // }


    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if(g[i][j] == '+') rs[i][j] = rs[i][j - 1] + 1;
            else rs[i][j] = 0;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = m; j >= 1; j--) {
            if(g[i][j] == '+') rr[i][j] = rr[i][j + 1] + 1;
            else rr[i][j] = 0;
        }
    }

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if(g[j][i] == '+') cs[j][i] = cs[j - 1][i] + 1;
            else cs[j][i] = 0;
        }
    }

    for (int i = 1; i <= m; i++) {
        for (int j = n; j >= 1; j--) {
            if(g[j][i] == '+') cr[j][i] = cr[j + 1][i] + 1;
            else cr[j][i] = 0;
        }
    }

    int ans = 0;
//     for (int i = 1; i <= n; i++) {
//         for (int j = 1; j <= m; j++) cout << rs[i][j] << " \n"[j == m];
//     }
//     for (int i = 1; i <= n; i++) {
//         for (int j = 1; j <= m; j++) cout << rr[i][j] << " \n"[j == m];
//     }
//     for (int i = 1; i <= n; i++) {
//         for (int j = 1; j <= m; j++) cout << cs[i][j] << " \n"[j == m];
//     }
// for (int i = 1; i <= n; i++) {
//         for (int j = 1; j <= m; j++) cout << cr[i][j] << " \n"[j == m];
//     }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if(g[i][j] == '+') {
                //cout << "d";
                int mn = min({rs[i][j - 1], rr[i][j + 1], cs[i - 1][j], cr[i + 1][j]});
                ans = max(ans, (4 * mn) + 1);

            }
        }
    }

    cout << ans << '\n'; 
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1; 
    cin>>t;
    for(int tc = 1; tc <= t; tc++) {
        // cout<<"Case "<<tc<<":";
        solve();
    }
}

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:07:50
Judged At
2024-12-09 06:07:50
Judged By
Score
100
Total Time
296ms
Peak Memory
66.035 MiB