/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 348.0 KiB
#2 Accepted 8ms 1.062 MiB
#3 Accepted 13ms 796.0 KiB
#4 Accepted 14ms 796.0 KiB
#5 Accepted 21ms 832.0 KiB
#6 Accepted 14ms 944.0 KiB
#7 Accepted 74ms 796.0 KiB
#8 Accepted 26ms 748.0 KiB
#9 Accepted 36ms 2.492 MiB
#10 Accepted 33ms 2.219 MiB
#11 Accepted 169ms 2.414 MiB
#12 Accepted 647ms 16.988 MiB
#13 Accepted 31ms 16.77 MiB
#14 Accepted 15ms 1.527 MiB
#15 Accepted 31ms 16.801 MiB
#16 Accepted 28ms 17.0 MiB
#17 Accepted 28ms 16.809 MiB
#18 Accepted 642ms 16.984 MiB
#19 Accepted 37ms 16.961 MiB
#20 Accepted 542ms 16.98 MiB
#21 Time Exceeded ≥2094ms ≥65.695 MiB
#22 Accepted 211ms 65.898 MiB
#23 Accepted 225ms 65.77 MiB
#24 Accepted 227ms 65.895 MiB
#25 Accepted 147ms 65.836 MiB
#26 Accepted 989ms 65.898 MiB
#27 Accepted 257ms 65.902 MiB
#28 Accepted 191ms 65.855 MiB
#29 Accepted 1579ms 65.895 MiB
#30 Time Exceeded ≥2050ms ≥65.898 MiB

Code

/*
 *Copyright (c) Swadheen Islam Robi (SIR01)
 *Created on Tue Dec 10 2024 3:03:19 PM
 */

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pie 2*(acos(0.0))
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define pb push_back
#define endl "\n"
#define lcm(a,b) (a*b)/(__gcd<ll>(a,b))
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);

void sir() {
    ll n, m;
    cin >> n >> m;

    // Use a 0-based grid for easier indexing
    vector<vector<char>> grid(n + 2, vector<char>(m + 2, '.'));
    bool got = false;

    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            cin >> grid[i][j];
            if ( !got && grid[i][j] == '+') {
                got = true;
            }
        }
    }

    if (!got) {
        cout << 0 << endl;
        return;
    }

    ll mx = -1;
    ll pmx = (min(n, m) * 2) - 1;

    //prefix approach try 1
    vector<vector<ll>> rp(n+2,vector<ll>(m + 2, 0));
    vector<vector<ll>> colp(n+2,vector<ll>(m + 2, 0));

    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            rp[i][j] = rp[i][j - 1] + (grid[i][j] == '+' ? 1 : 0);
            colp[i][j] = colp[i - 1][j] + (grid[i][j] == '+' ? 1 : 0);
        }
    }

    for (ll i = 2; i < n; i++) {
        for (ll j = 2; j < m; j++) {
            if (grid[i][j] == '+') {
                ll c = 0;

                while (i - c >= 1 && i + c <= n &&
                       j - c >= 1 && j + c <= m &&
                       rp[i][j + c] - rp[i][j - c - 1] == (2 * c + 1) &&
                       colp[i + c][j] - colp[i - c - 1][j] == (2 * c + 1)) {
                    c++;
                }

                ll sz = (4*(c-1))+1;
                mx = max(mx, sz);

                if (mx == pmx) {
                    cout << mx << endl;
                    return;
                }
            }
        }
    }
    if (mx == -1) {
        cout << 1 << endl;
    } else {
        cout << mx << endl;
    }
}

int main() {
    ALLAHU_AKBAR

    ll t;
    cin >> t;
    while (t--) {
        sir();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Contest
LU IUJPC : Sylhet Division 2024 Replay Contest
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-10 11:00:50
Judged At
2024-12-10 11:00:50
Judged By
Score
92
Total Time
≥2094ms
Peak Memory
≥65.902 MiB