/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 4.527 MiB
#2 Accepted 20ms 6.527 MiB
#3 Accepted 26ms 6.527 MiB
#4 Accepted 29ms 8.77 MiB
#5 Accepted 48ms 8.777 MiB
#6 Accepted 18ms 6.52 MiB
#7 Accepted 62ms 8.527 MiB
#8 Accepted 73ms 8.527 MiB
#9 Accepted 84ms 20.566 MiB
#10 Accepted 81ms 12.77 MiB
#11 Accepted 77ms 8.828 MiB
#12 Accepted 104ms 37.898 MiB
#13 Accepted 67ms 36.262 MiB
#14 Accepted 29ms 37.855 MiB
#15 Accepted 69ms 38.066 MiB
#16 Accepted 28ms 36.805 MiB
#17 Accepted 29ms 36.816 MiB
#18 Accepted 103ms 37.836 MiB
#19 Accepted 58ms 36.816 MiB
#20 Accepted 156ms 37.297 MiB
#21 Accepted 433ms 65.773 MiB
#22 Accepted 429ms 65.766 MiB
#23 Accepted 616ms 65.777 MiB
#24 Accepted 963ms 65.777 MiB
#25 Accepted 705ms 65.77 MiB
#26 Accepted 1826ms 65.766 MiB
#27 Accepted 1162ms 65.77 MiB
#28 Accepted 955ms 65.77 MiB
#29 Accepted 1334ms 65.773 MiB
#30 Accepted 1153ms 65.773 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;
      }
      else {
        A[i][j] = 0;
        B[i][j] = 0;
      }
    }
  }
  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:10:39
Judged At
2024-12-10 12:10:39
Judged By
Score
100
Total Time
1826ms
Peak Memory
65.777 MiB