/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Runtime Error 3ms 1.141 MiB
#3 Runtime Error 2ms 1.016 MiB

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
 
#define pb push_back
#define MOD 1000000007
#define vll vector<ll>
#define endl "\n" 
#define all(v) v.begin(), v.end()
#define mem(a,b) memset(a, b, sizeof(a))
#define co(n) cout << n << endl
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define fr(x, n) for (int i = x; i < n; ++i)
#define fraction(x) cout << fixed << setprecision(x)
#define Baba_Yaga ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
const double eps = 1e-9;
const int N = 2e3+123;
 
ll gcd(ll a,ll b) { return __gcd(a,b); }
ll lcm(ll a,ll b) { return (a*b)/__gcd(a,b); }
 
int dx[] = {0, 0, +1, -1, +1, +1, -1, -1};
int dy[] = {+1, -1, 0, 0, +1, -1, +1, -1};


void solve()
{
    ll n, m;
    cin >> n >> m;
    ll arr[n+5][m+5];
    ll upore[n+5][m+5], niche[n+5][m+5], dan[n+5][m+5], bam[n+5][m+5];
    for(int i=0; i<n+5; i++)
    {
        for(int j=0; j<m+5; j++)
        {
            upore[i][j] = 0, niche[i][j] = 0;
            bam[i][j] = 0, dan[i][j] = 0;
            arr[i][j] = 0;
        }
    }


    
    ll ase = 0;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            char c ; cin >> c;
            if(c == '+')
            {
                arr[i][j] = 1;
                ase = 1;
            }
            else arr[i][j] = 0;
            
        }
    }
    
    if(ase == 0)
    {
        cout << 0 << endl;
        return;
    }

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

    for(int i=n; i>=1; i--)
    {
        for(int j=m; j>=1; j--)
        {
            if(arr[i][j] == 0)
            {
                dan[i][j] = 0;
            }
            else
            {
                dan[i][j] = (1+dan[i][j+1]);
            }
        }
    }
    

    for(int i=1; i<=m; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(arr[i][j] == 0)
            {
                upore[i][j] = 0;
            }
            else
            {
                upore[i][j] = 1 + upore[i-1][j];
            }
        }
    }
    
    for(int i=1; i<=m; i++)
    {
        for(int j=n; j>=1; j--)
        {
            if(arr[j][i] == 0)
            {
                niche[j][i] = 0;
            }
            else
            {
                niche[j][i] = 1 + niche[j+1][i];
            }
        }
    }
    // for(int i=1; i<=n; i++)
    // {
    //     for(int j=1; j<=m; j++)
    //     {
    //         cout << niche[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll maxi = -1;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(arr[i][j] == 1)
            {
                ll val_1 = bam[i][j-1];
                ll val_2 = dan[i][j+1];
                ll val_3 = upore[i-1][j];
                ll val_4 = niche[i+1][j];
                ll mi = min({val_1, val_2, val_3, val_4});
                maxi = max(maxi, mi);
            }
            
        }
    }

    cout << maxi*4+1 << endl;


}

int main()
{
    Baba_Yaga;
    ll tc = 1; cin >> tc;
    for(int i=1; i<=tc; i++)
    {
       // cout << "Case " << i << ": ";
        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 09:39:26
Judged At
2024-12-09 09:39:26
Judged By
Score
2
Total Time
3ms
Peak Memory
1.141 MiB