/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 2.777 MiB
#2 Accepted 11ms 5.027 MiB
#3 Accepted 15ms 5.07 MiB
#4 Accepted 17ms 5.027 MiB
#5 Accepted 20ms 4.852 MiB
#6 Accepted 13ms 5.203 MiB
#7 Accepted 45ms 4.828 MiB
#8 Accepted 32ms 4.828 MiB
#9 Accepted 37ms 13.246 MiB
#10 Accepted 35ms 8.113 MiB
#11 Accepted 55ms 7.098 MiB
#12 Accepted 85ms 30.988 MiB
#13 Accepted 47ms 32.297 MiB
#14 Accepted 27ms 30.066 MiB
#15 Accepted 40ms 31.555 MiB
#16 Accepted 29ms 31.562 MiB
#17 Accepted 28ms 30.812 MiB
#18 Accepted 86ms 30.77 MiB
#19 Accepted 34ms 32.102 MiB
#20 Accepted 108ms 30.863 MiB
#21 Accepted 453ms 62.109 MiB
#22 Accepted 286ms 62.078 MiB
#23 Accepted 236ms 62.059 MiB
#24 Accepted 238ms 62.02 MiB
#25 Accepted 146ms 62.059 MiB
#26 Accepted 627ms 62.188 MiB
#27 Accepted 373ms 62.066 MiB
#28 Accepted 299ms 62.121 MiB
#29 Accepted 607ms 62.113 MiB
#30 Accepted 611ms 62.125 MiB

Code

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

typedef int64_t ll;

#ifdef LOCAL
#include "debug.hpp"
#else
#define debug(...) 42
#endif

const ll N = 2009;
ll a[N][N], pref[N][N];

ll query(ll y1, ll y2, ll x1, ll x2) {
    return pref[x2][y2] - pref[x1 - 1][y2] - pref[x2][y1 - 1] + pref[x1 - 1][y1 - 1];
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T;
    cin >> T;
    while (T--) {
        ll n, m;
        cin >> n >> m;
        for (ll i = 1; i <= n; i++) {
            for (ll j = 1; j <= m; j++) {
                char c;
                cin >> c;
                if (c == '+') {
                    a[i][j] = 1;
                } else {
                    a[i][j] = 0;
                }
            }
        }
        for (ll i = 1; i <= n; i++) {
            for (ll j = 1; j <= m; j++) {
                pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i][j];
            }
        }
        ll res = 0;
        for (ll i = 1; i <= n; i++) {
            for (ll j = 1; j <= m; j++) {
                if (a[i][j] == 0)
                    continue;
                ll l = 0, r = min(j - 1, m - j), ret = 0;
                while (l <= r) {
                    ll m = l + r >> 1;
                    if (m == 0 || (query(j - m, j - 1, i, i) == m && query(j + 1, j + m, i, i) == m)) {
                        ret = m;
                        l = m + 1;
                    } else {
                        r = m - 1;
                    }
                }
                l = 0, r = min({ret, i - 1, n - i});
                while (l <= r) {
                    ll m = l + r >> 1;
                    if (m == 0 || (query(j, j, i - m, i - 1) == m && query(j, j, i + 1, i + m) == m)) {
                        ret = m;
                        l = m + 1;
                    } else {
                        r = m - 1;
                    }
                }
                res = max(res, ret * 4 + 1);
            }
        }
        cout << res << '\n';
    }
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-12 13:41:54
Judged At
2024-12-12 13:41:54
Judged By
Score
100
Total Time
627ms
Peak Memory
62.188 MiB