/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 8ms 844.0 KiB
#3 Accepted 11ms 796.0 KiB
#4 Accepted 12ms 540.0 KiB
#5 Accepted 10ms 812.0 KiB
#6 Accepted 12ms 588.0 KiB
#7 Accepted 56ms 2.777 MiB
#8 Accepted 28ms 840.0 KiB
#9 Accepted 28ms 3.07 MiB
#10 Accepted 28ms 844.0 KiB
#11 Accepted 149ms 1.027 MiB
#12 Accepted 385ms 4.008 MiB
#13 Accepted 19ms 2.777 MiB
#14 Accepted 15ms 2.777 MiB
#15 Accepted 20ms 3.324 MiB
#16 Accepted 16ms 3.77 MiB
#17 Accepted 15ms 2.812 MiB
#18 Accepted 384ms 3.023 MiB
#19 Accepted 21ms 3.547 MiB
#20 Accepted 321ms 2.828 MiB
#21 Time Exceeded ≥2100ms ≥4.332 MiB
#22 Accepted 241ms 4.379 MiB
#23 Accepted 258ms 4.383 MiB
#24 Accepted 257ms 4.27 MiB
#25 Accepted 112ms 4.328 MiB
#26 Accepted 670ms 4.371 MiB
#27 Accepted 228ms 4.219 MiB
#28 Accepted 157ms 4.273 MiB
#29 Accepted 1357ms 4.379 MiB
#30 Accepted 1848ms 4.383 MiB

Code

#include <bits/stdc++.h>
#define nl '\n'
#define ll long long int
#define all(v) v.begin(),v.end()
#define print(v) for(auto data : v) cout << data << " "; cout << nl
using namespace std;
const int N = 2e3 + 5;
char mat[N][N];
int n, m;
bool is_valid_i(int i)
{
    return !(i > n || i <= 0);
}
bool is_valid_j(int j)
{
    return !(j > m || j <= 0);
}
void solve()
{
    cin >> n >> m;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> mat[i][j]; mat[i][j] == '+'? ans = 1 : ans;
        }
    }
    if(ans ==  0)
    {
        cout << 0 << nl; return;
    }

    // prefix sum?! 
    int mx_cnt = min(n,m) + min(n,m) - 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if(mat[i][j] == '+')
            {
                int r = i+1, l = i-1, upor = j+1, nich = j-1;
                int cnt = 0;
                if(is_valid_i(l) && is_valid_i(r) && is_valid_j(upor) && is_valid_j(nich) &&
                mat[l][j] == '+' && mat[r][j] == '+' && mat[i][upor] == '+' && mat[i][nich] == '+' &&
                ((ans+1)/4 > n-i || (ans+1)/4 > m-j)) break;
                while (is_valid_i(l) && is_valid_i(r) && is_valid_j(upor) && is_valid_j(nich) &&
                mat[l][j] == '+' && mat[r][j] == '+' && mat[i][upor] == '+' && mat[i][nich] == '+')
                {
                    cnt += 4; r++, l--, upor++, nich--;
                }
                ans = max(ans, cnt + 1);
                if(ans == mx_cnt)
                {
                    cout << ans << nl; return;
                }
            }
        }
    }
    cout << ans << nl;
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int t; cin >> t; 
    while (t--) solve();

    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 13:49:50
Judged At
2024-12-10 13:49:50
Judged By
Score
96
Total Time
≥2100ms
Peak Memory
≥4.383 MiB