/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 8.527 MiB
#2 Accepted 15ms 11.004 MiB
#3 Accepted 10ms 12.785 MiB
#4 Accepted 11ms 12.965 MiB
#5 Accepted 12ms 11.027 MiB
#6 Accepted 10ms 10.777 MiB
#7 Accepted 26ms 12.914 MiB
#8 Accepted 45ms 11.027 MiB
#9 Accepted 50ms 23.574 MiB
#10 Accepted 44ms 15.066 MiB
#11 Accepted 26ms 14.996 MiB
#12 Accepted 35ms 40.301 MiB
#13 Accepted 35ms 41.605 MiB
#14 Accepted 38ms 43.836 MiB
#15 Accepted 39ms 44.023 MiB
#16 Accepted 40ms 43.969 MiB
#17 Accepted 39ms 42.676 MiB
#18 Accepted 37ms 44.066 MiB
#19 Accepted 43ms 40.27 MiB
#20 Accepted 37ms 37.527 MiB
#21 Accepted 260ms 65.918 MiB
#22 Accepted 246ms 65.57 MiB
#23 Accepted 256ms 65.609 MiB
#24 Accepted 231ms 65.613 MiB
#25 Accepted 317ms 65.781 MiB
#26 Accepted 244ms 65.707 MiB
#27 Accepted 258ms 65.887 MiB
#28 Accepted 291ms 65.875 MiB
#29 Accepted 247ms 65.738 MiB
#30 Accepted 263ms 65.578 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int sz = 2005 ;
char grid[sz][sz] ;
int n , m , leftToRight[sz][sz] , rightToLeft[sz][sz] , topToDown[sz][sz] , downToTop[sz][sz];
void preCalc() {

   // Left to Right
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < m ; j++){
            if(grid[i][j] != '+') leftToRight[i][j] =  0 ;
            else {
                if(j == 0) leftToRight[i][j] = 1 ;
                else {
                    leftToRight[i][j] = 1 + leftToRight[i][j - 1] ;
                }
            }
        }
    }
    // Right to Left
    for(int i = 0 ; i < n ; i++){
        for(int j = m - 1 ; j >= 0 ; j--){
            if(grid[i][j] != '+') rightToLeft[i][j] =  0 ;
            else {
                if(j == (m - 1)) rightToLeft[i][j] = 1 ;
                else {
                    rightToLeft[i][j] = 1 + rightToLeft[i][j + 1] ;
                }
            }
        }
    }
    // Top to Down
    for(int j = 0 ; j < m ; j++) {
        for(int i = 0 ; i < n ; i++){
            if(grid[i][j] != '+') topToDown[i][j] =  0 ;
            else {
                if(i == 0) topToDown[i][j] = 1 ;
                else {
                    topToDown[i][j] = topToDown[i - 1][j] + 1 ;
                }
            }
        }
    }
    // Down to Top
    for(int j = 0 ; j < m ; j++) {
        for(int i = n - 1 ; i >= 0 ; i--){
            if(grid[i][j] != '+') downToTop[i][j] =  0 ;
            else {
                if(i == (n - 1)) downToTop[i][j] = 1 ;
                else {
                    downToTop[i][j] = downToTop[i + 1][j] + 1 ;
                }
            }
        }
    }
//    for(int i = 0 ; i < n ; i++){
//        for(int j = 0 ; j < m ; j++){
//            cout << i << " " << j << " --> " << leftToRight[i][j] << " and " << rightToLeft[i][j] << " " << topToDown[i][j] << " " << downToTop[i][j] << endl ;
//        }
//    }
}
void solve()
{
    int Ans = 0; cin >> n >> m ;
    for(int i = 0 ; i < n ; i++) for(int j = 0 ; j < m ; j++) {
        cin >> grid[i][j] ;
        leftToRight[i][j] = rightToLeft[i][j] = topToDown[i][j] = downToTop[i][j] = 0 ;
    }
    preCalc() ;
    for(int i = 0 ; i < n ; i++) {
        for(int j = 0 ; j < m ; j++){
            if(grid[i][j] == '+') {
                int totPlus = min({leftToRight[i][j] - 1 , rightToLeft[i][j] - 1 , topToDown[i][j] - 1 , downToTop[i][j] - 1 }) * 4 ;
                Ans = max(Ans , 1 + totPlus ) ;
            }
        }
    }
    cout << Ans << "\n" ;
}
int main()
{
     __Heart__
     int t ; cin >> t ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Contest
LU Divisonal Contest Problem Testing Round
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-08 03:23:36
Judged At
2024-12-08 03:23:36
Judged By
Score
100
Total Time
317ms
Peak Memory
65.918 MiB