/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 12ms 1.066 MiB
#3 Accepted 11ms 796.0 KiB
#4 Accepted 12ms 1.008 MiB
#5 Accepted 14ms 1.027 MiB
#6 Accepted 12ms 896.0 KiB
#7 Accepted 36ms 900.0 KiB
#8 Accepted 38ms 1.027 MiB
#9 Accepted 51ms 3.805 MiB
#10 Accepted 56ms 3.754 MiB
#11 Accepted 58ms 3.723 MiB
#12 Accepted 61ms 32.062 MiB
#13 Accepted 41ms 32.27 MiB
#14 Accepted 35ms 32.074 MiB
#15 Accepted 42ms 32.188 MiB
#16 Accepted 37ms 32.035 MiB
#17 Accepted 37ms 32.254 MiB
#18 Accepted 60ms 32.062 MiB
#19 Accepted 45ms 32.066 MiB
#20 Accepted 81ms 32.258 MiB
#21 Accepted 264ms 127.219 MiB
#22 Accepted 207ms 127.051 MiB
#23 Accepted 198ms 126.949 MiB
#24 Accepted 217ms 127.074 MiB
#25 Accepted 227ms 127.02 MiB
#26 Accepted 250ms 127.078 MiB
#27 Accepted 237ms 126.922 MiB
#28 Accepted 233ms 126.953 MiB
#29 Accepted 255ms 127.07 MiB
#30 Accepted 254ms 126.844 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> a(n, vector<char>(m));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> a[i][j];

    // Precompute directional lengths
    vector<vector<int>> left(n, vector<int>(m, 0)), right(n, vector<int>(m, 0));
    vector<vector<int>> up(n, vector<int>(m, 0)), down(n, vector<int>(m, 0));

    // Fill 'left' and 'up'
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == '+') {
                left[i][j] = (j > 0 ? left[i][j - 1] : 0) + 1;
                up[i][j] = (i > 0 ? up[i - 1][j] : 0) + 1;
            }
        }
    }

    // Fill 'right' and 'down'
    for (int i = n - 1; i >= 0; i--) {
        for (int j = m - 1; j >= 0; j--) {
            if (a[i][j] == '+') {
                right[i][j] = (j < m - 1 ? right[i][j + 1] : 0) + 1;
                down[i][j] = (i < n - 1 ? down[i + 1][j] : 0) + 1;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] == '+') {
                int l = 1, r = min({left[i][j], right[i][j], up[i][j], down[i][j]});
                int best = 0;
                while (l <= r) {
                    int mid = (l + r) / 2;
                    if (left[i][j] >= mid && right[i][j] >= mid &&
                        up[i][j] >= mid && down[i][j] >= mid) {
                        best = mid;
                        l = mid + 1;
                    } else {
                        r = mid - 1;
                    }
                }
                ans = max(ans, 4 * (best - 1) + 1);
            }
        }
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}

Information

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