/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 592.0 KiB
#2 Accepted 13ms 1.027 MiB
#3 Accepted 8ms 840.0 KiB
#4 Accepted 9ms 796.0 KiB
#5 Accepted 15ms 956.0 KiB
#6 Accepted 8ms 1.164 MiB
#7 Accepted 29ms 1.027 MiB
#8 Accepted 48ms 964.0 KiB
#9 Accepted 54ms 4.422 MiB
#10 Accepted 52ms 4.418 MiB
#11 Accepted 30ms 4.277 MiB
#12 Accepted 101ms 38.918 MiB
#13 Accepted 98ms 38.828 MiB
#14 Accepted 51ms 39.02 MiB
#15 Accepted 99ms 38.77 MiB
#16 Accepted 95ms 38.684 MiB
#17 Accepted 97ms 38.914 MiB
#18 Accepted 99ms 38.918 MiB
#19 Accepted 101ms 38.77 MiB
#20 Accepted 100ms 39.02 MiB
#21 Accepted 397ms 153.734 MiB
#22 Accepted 385ms 153.738 MiB
#23 Accepted 385ms 153.52 MiB
#24 Accepted 373ms 153.738 MiB
#25 Accepted 458ms 153.699 MiB
#26 Accepted 366ms 153.586 MiB
#27 Accepted 375ms 153.734 MiB
#28 Accepted 382ms 153.73 MiB
#29 Accepted 383ms 153.574 MiB
#30 Accepted 382ms 153.738 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+12;

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+2][m+2], l_r[n+2][m+2], r_l[n+2][m+2], u_d[n+2][m+2], d_u[n+2][m+2];

    for(int i=0; i<=n+1; i++)
    {
        for(int j=0; j<=m+1; j++)
        {
            arr[i][j] = 0;
            l_r[i][j] = 0;
            r_l[i][j] = 0;
            u_d[i][j] = 0;
            d_u[i][j] = 0;
        }
    }
    
    bool yo = true;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            char c; cin >> c;
            if(c == '+')
            {
                arr[i][j] = 1;
                yo = false;
            }
            else arr[i][j] = 0;
        }
    }
    // arr input done
    if(yo)
    {
        cout << 0 << endl;
        return;
    }

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

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

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

    ll ans = 0;

    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(arr[i][j] == 1)
            {
                ll a = l_r[i][j-1];
                ll b = r_l[i][j+1];
                ll c = u_d[i-1][j];
                ll d = d_u[i+1][j];
                ll mini = min({a, b, c, d});
                ans = max(ans, mini);
            }
        }
    }
    
    cout << ans * 4 + 1 << endl;
}

// --- Think the problem backwards ---

int main()
{
    Baba_Yaga;
    ll tc = 1; cin >> tc;
    while(tc--) solve();
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-12 12:14:45
Judged At
2024-12-12 12:14:45
Judged By
Score
100
Total Time
458ms
Peak Memory
153.738 MiB