/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 13ms 796.0 KiB
#3 Accepted 16ms 872.0 KiB
#4 Accepted 18ms 1.074 MiB
#5 Accepted 20ms 1.066 MiB
#6 Accepted 16ms 940.0 KiB
#7 Accepted 43ms 1.039 MiB
#8 Accepted 42ms 1.027 MiB
#9 Accepted 55ms 3.98 MiB
#10 Accepted 54ms 3.75 MiB
#11 Accepted 64ms 3.754 MiB
#12 Accepted 84ms 32.043 MiB
#13 Accepted 50ms 32.039 MiB
#14 Accepted 42ms 32.031 MiB
#15 Accepted 46ms 32.23 MiB
#16 Accepted 50ms 32.023 MiB
#17 Accepted 36ms 32.035 MiB
#18 Accepted 78ms 32.191 MiB
#19 Accepted 49ms 32.27 MiB
#20 Accepted 86ms 32.461 MiB
#21 Wrong Answer 298ms 127.07 MiB
#22 Accepted 248ms 127.0 MiB
#23 Accepted 226ms 127.078 MiB
#24 Accepted 207ms 127.0 MiB
#25 Accepted 236ms 127.105 MiB
#26 Wrong Answer 423ms 127.074 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 = 500, best = 1;
                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:44:09
Judged At
2024-12-14 12:44:09
Judged By
Score
76
Total Time
423ms
Peak Memory
127.105 MiB