/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 7ms 540.0 KiB
#3 Accepted 13ms 796.0 KiB
#4 Accepted 14ms 1.105 MiB
#5 Accepted 12ms 992.0 KiB
#6 Accepted 14ms 1.062 MiB
#7 Accepted 87ms 1008.0 KiB
#8 Accepted 23ms 796.0 KiB
#9 Accepted 23ms 804.0 KiB
#10 Accepted 24ms 972.0 KiB
#11 Accepted 163ms 4.312 MiB
#12 Accepted 564ms 19.621 MiB
#13 Accepted 16ms 1.527 MiB
#14 Accepted 14ms 1.527 MiB
#15 Accepted 20ms 1.527 MiB
#16 Accepted 15ms 1.324 MiB
#17 Accepted 16ms 1.551 MiB
#18 Accepted 519ms 19.652 MiB
#19 Accepted 18ms 1.566 MiB
#20 Accepted 521ms 19.648 MiB
#21 Time Exceeded ≥2096ms ≥70.465 MiB
#22 Accepted 187ms 70.605 MiB
#23 Accepted 194ms 70.543 MiB
#24 Accepted 189ms 70.535 MiB
#25 Accepted 88ms 7.648 MiB
#26 Accepted 690ms 70.539 MiB
#27 Accepted 201ms 70.527 MiB
#28 Accepted 164ms 70.68 MiB
#29 Accepted 1284ms 70.539 MiB
#30 Accepted 1526ms 70.535 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ALLAHU_AKBAR ios::sync_with_stdio(false); cin.tie(nullptr);

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

    vector<vector<char>> grid(n + 1, vector<char>(m + 1));
    bool got = false;
    ll cp = 0;

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

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

    vector<pair<ll, ll>> point;
    for (ll i = 2; i < n; i++) {
        for (ll j = 2; j < m; j++) {
            if (grid[i][j] == '+' &&
                grid[i][j + 1] == '+' && grid[i][j - 1] == '+' &&
                grid[i - 1][j] == '+' && grid[i + 1][j] == '+') {
                point.emplace_back(i, j);
            }
        }
    }

    if (point.empty()) {
        cout << 1 << endl;
        return;
    }

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

    for (auto &p : point) {
        ll f = p.first;
        ll s = p.second;
        ll c = 0;
        ll x = 1;

        while (f + x <= n && f - x >= 1 &&
               s + x <= m && s - x >= 1 &&
               grid[f + x][s] == '+' && grid[f - x][s] == '+' &&
               grid[f][s + x] == '+' && grid[f][s - x] == '+') {
            c++;
            x++;
        }

        mx = max(mx, ((4 * c) + 1));
        if (mx == pmx) {
            cout << mx << endl;
            return;
        }
    }

    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 10:27:36
Judged At
2024-12-10 10:27:36
Judged By
Score
96
Total Time
≥2096ms
Peak Memory
≥70.68 MiB