/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 21ms 832.0 KiB
#3 Accepted 26ms 540.0 KiB
#4 Accepted 30ms 616.0 KiB
#5 Accepted 48ms 616.0 KiB
#6 Accepted 19ms 540.0 KiB
#7 Accepted 70ms 796.0 KiB
#8 Accepted 83ms 768.0 KiB
#9 Accepted 89ms 1.551 MiB
#10 Accepted 88ms 1.289 MiB
#11 Accepted 88ms 1.316 MiB
#12 Accepted 105ms 8.238 MiB
#13 Accepted 63ms 8.02 MiB
#14 Accepted 24ms 8.461 MiB
#15 Accepted 65ms 8.027 MiB
#16 Accepted 25ms 8.23 MiB
#17 Accepted 26ms 8.238 MiB
#18 Accepted 104ms 8.238 MiB
#19 Accepted 54ms 8.027 MiB
#20 Accepted 171ms 8.219 MiB
#21 Accepted 452ms 31.133 MiB
#22 Accepted 453ms 31.281 MiB
#23 Accepted 603ms 31.207 MiB
#24 Accepted 896ms 31.32 MiB
#25 Accepted 410ms 31.215 MiB
#26 Accepted 1954ms 31.219 MiB
#27 Accepted 1244ms 31.27 MiB
#28 Accepted 1004ms 31.219 MiB
#29 Accepted 1608ms 31.215 MiB
#30 Accepted 1347ms 31.215 MiB

Code

//#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;

// Author: Mohamed Bakr

#define ll long long
#define INT int32_t
#define int ll
#define vct vector
//#define int128 number<cpp_int_backend<128, 128, unsigned_magnitude, unchecked, void>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sum(v) accumulate(all(v), 0LL)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define ln "\n"
#define lln cout<<ln
#define umap unordered_map
#define yes cout<<"YES"<<ln
#define no cout<<"NO"<<ln
#define precision(x,y) fixed<<setprecision(y)<<x
#define fastio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dbg(ele) cout << #ele <<" : "<< ele << '\n'
#define PI 3.141592653589793238462643383279502884197
#define toDeg(theta) theta*(180.0/PI)
#define toRad(theta) theta*(PI/180.0)

template <typename T, typename C>
istream& operator>>(istream& istream, pair<T, C>& pi) { cin >> pi.first >> pi.second; return istream; }
template <typename T, typename C>
ostream& operator<<(ostream& ostream, pair<T, C>& pi) { cout << pi.first << " " << pi.second;  return ostream; }
template <typename T>
istream& operator>>(istream& istream, vector<T>& v) { for (T& it : v) cin >> it; return istream; }
template <typename T>
ostream& operator<<(ostream& ostream, vector<T>& v) { for (T it : v) cout << it << " "; return ostream; }
template <typename T>
ostream& operator<<(ostream& ostream, set<T>& v) { for (T it : v) cout << it << " "; return ostream; }

bool prime(int num) { if (num <= 1) return false; int ch = 2; while (ch * ch <= num) { if (!(num % ch)) return false; ch++; }return true; }
int fact(int n) { if (n == 0) return 1; return n * fact(n - 1); }
int nPr(int n, int r) { int val = 1; for (int i = n - r + 1; i <= n; i++) val *= i; return val; }
int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int biPow(int x, int y) { int val = 1; while (y) { if (y % 2) { val *= x; y--; } else { x *= x; y /= 2; } }return val; }
int modPow(int x, int y, int m) { int val = 1; x %= m; while (y) { if (y % 2) { val *= x; val %= m; y--; } else { x *= x; x %= m; y /= 2; } }return val % m; }
int sumRng(int l, int r) { return (r - l + 1) * (l + r) / 2; }

string mv[8] = { "U", "R", "D", "L", "UR","UL","DR","DL" };
int xd[9] = { -1, 0, 1,  0, -1, -1, 1,  1, 0 };
int yd[9] = { 0, 1, 0, -1,  1, -1, 1, -1, 0 };
int xk[9] = { -1, 1, 2, -2, -1, 1, 2, -2, 0 };
int yk[9] = { 2, -2, 1, -1, -2, 2, -1, 1, 0 };



void answer(int test)
{
	int n,m;cin>>n>>m;
	vct<vct<int>>a(n,vct<int>(m,0));
	for(int i=0;i<n;i++){
		for(int j = 0;j<m;j++){
			char c;cin>>c;
			if(c=='+') a[i][j]=1;
			if(i) a[i][j]+=a[i-1][j];
			if(j) a[i][j]+=a[i][j-1];
			if(i&&j) a[i][j]-=a[i-1][j-1];
		}
	}
	auto rng = [&](int r1, int c1, int r2, int c2){
		int val = a[r2][c2];
		if(r1) val-=a[r1-1][c2];
		if(c1) val-=a[r2][c1-1];
		if(r1&&c1) val+=a[r1-1][c1-1];
		return val;
	};
	int ans = 0;
	for(int i = 0;i<n;i++){
		for(int j = 0;j<m;j++){
			if(rng(i,j,i,j) == 1){
				int u=0,d=0,rf=0,lf=0;
				{
					int l = 0, r = i-1;
					while(l<=r){
						int mid = (l+r)/2;
						int sz = i-mid;
						int cur = rng(mid,j,i-1,j);
						if(cur==sz) r=mid-1,u=sz;
						else l=mid+1;
					}
				}
				{
					int l = i+1, r = n-1;
					while(l<=r){
						int mid = (l+r)/2;
						int sz = mid-i;
						int cur = rng(i+1,j,mid,j);
						if(cur==sz) l=mid+1,d=sz;
						else r=mid-1;
					}
				}
				{
					int l = 0, r = j-1;
					while(l<=r){
						int mid = (l+r)/2;
						int sz = j-mid;
						int cur = rng(i,mid,i,j-1);
						if(cur==sz) r=mid-1,lf=sz;
						else l=mid+1;
					}
				}
				{
					int l = j+1, r = m-1;
					while(l<=r){
						int mid = (l+r)/2;
						int sz = mid-j;
						int cur = rng(i,j+1,i,mid);
						if(cur==sz) l=mid+1,rf=sz;
						else r=mid-1;
					}
				}
				int mn = min(u,min(d,min(lf,rf)));
				ans=max(ans,1+mn*4);
			}
		}
	}
	cout<<ans<<ln;
}
bool multiTests = true;
INT main()
{
#ifdef Mhmd_Bakr
	//Contest : -
	//Problem : -
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	fastio;
	int tests = 1;
	if (multiTests) cin >> tests;
	for (int test = 1; test <= tests; test++)
	{
		//cout << "Case #" << test << ": ";
		answer(test);
	}
}

Information

Submit By
Type
Submission
Problem
P1143 Plus of Pluses
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-11 08:59:04
Judged At
2024-12-11 08:59:04
Judged By
Score
100
Total Time
1954ms
Peak Memory
31.32 MiB