/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 4.512 MiB
#2 Wrong Answer 22ms 6.527 MiB
#3 Accepted 26ms 6.859 MiB
#4 Accepted 28ms 6.719 MiB
#5 Wrong Answer 48ms 6.906 MiB

Code

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

const ll MX = 2e3 + 5;
ll A[MX][MX], B[MX][MX], n, m;
char C[MX][MX];

ll get1(ll i, ll j, ll left, ll right) {
  ll res = 1;
  while (left <= right) {
    ll mid = (left + right) / 2;
    ll sm = A[i][mid];
    if (j) sm -= A[i][j - 1];
    if (sm == mid - j + 1) {
      res = mid - j + 1;
      left = mid + 1;
    }
    else right = mid - 1;
  }
  return res;
}

ll get2(ll i, ll j, ll left, ll right) {
  ll res = 1;
  while (left <= right) {
    ll mid = (left + right) / 2;
    ll sm = A[i][j];
    if (mid) sm -= A[i][mid - 1];
    if (sm == j - mid + 1) {
      res = j - mid + 1;
      right = mid - 1;
    }
    else left = mid + 1;
  }
  return res;
}

ll get3(ll i, ll j, ll left, ll right) {
  ll res = 1;
  while (left <= right) {
    ll mid = (left + right) / 2;
    ll sm = B[mid][j];
    if (i) sm -= B[i - 1][j];
    if (sm == mid - i + 1) {
      res = mid - i + 1;
      left = mid + 1;
    }
    else right = mid - 1;
  }
  return res;
}

ll get4(ll i, ll j, ll left, ll right) {
  ll res = 1;
  while (left <= right) {
    ll mid = (left + right) / 2;
    ll sm = B[i][j];
    if (mid) sm -= B[mid - 1][j];
    if (sm == i - mid + 1) {
      res = i - mid + 1;
      right = mid - 1;
    }
    else left = mid + 1;
  }
  return res;
}

void solve() {
  cin >> n >> m;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      char c; cin >> c;
      C[i][j] = c;
      if (c == '+') {
        A[i][j] = 1;
        B[i][j] = 1;
      }
    }
  }
  for (ll i = 0; i < n; i++) for (ll j = 1; j < m; j++) A[i][j] += A[i][j - 1];
  for (ll i = 0; i < m; i++) for (ll j = 1; j < n; j++) B[j][i] += B[j - 1][i];
  ll res = 0;
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < m; j++) {
      if (C[i][j] == '+') {
        ll res1 = get1(i, j, j, m - 1);
        ll res2 = get2(i, j, 0, j);
        ll res3 = get3(i, j, i, n - 1);
        ll res4 = get4(i, j, 0, i);
        // cout << i << " " << j << " " << res3 << " " << res4 << endl;
        ll d = min({res1, res2, res3, res4});
        res = max(res, ((d - 1) * 4) + 1);
      }
    }
  }
  cout << res << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int tt;
  cin >> tt;
  while (tt--) {
    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 12:08:44
Judged At
2024-12-10 12:08:44
Judged By
Score
6
Total Time
48ms
Peak Memory
6.906 MiB