Accepted
Code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define bug(a) cout<<#a<<" : "<<a<<endl;
#define bug2(a,b) cout<<#a<<" : "<<a<<"\t"<<#b<<" : "<<b<<endl;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;cin>>t;
while(t--){
int n,m;cin>>n>>m;
vector<vector<char>>v(n,vector<char>(m));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>v[i][j];
}
}
vector<vector<int>>lp(n,vector<int>(m)),rp(n,vector<int>(m)),up(n,vector<int>(m)),dp(n,vector<int>(m));
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(v[i][j]=='-')lp[i][j]=0;
else{
if(j==0){
lp[i][j]=1;
}else{
lp[i][j]=1+lp[i][j-1];
}
}
}
}
for(int i=0;i<n;i++){
for(int j=m-1;j>=0;j--){
if(v[i][j]=='-')rp[i][j]=0;
else{
if(j==m-1){
rp[i][j]=1;
}else{
rp[i][j]=1+rp[i][j+1];
}
}
}
}
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(v[j][i]=='-')up[j][i]=0;
else{
if(j==0){
up[j][i]=1;
}else{
up[j][i]=1+up[j-1][i];
}
}
}
}
for(int i=0;i<m;i++){
for(int j=n-1;j>=0;j--){
if(v[j][i]=='-')dp[j][i]=0;
else{
if(j==n-1){
dp[j][i]=1;
}else{
dp[j][i]=1+dp[j+1][i];
}
}
}
}
// for(int i=0;i<m;i++){
// for(int j=n-1;j>=0;j--){
// cout<<dp[j][i]<<" ";
// }
// }
int ans=0;
bool got=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(v[i][j]!='+')continue;
if(i==0 || j==0 || i==n-1 || j==m-1){
ans=max(ans,1);
continue;
}
int ls=lp[i][j-1],rs=rp[i][j+1];
//cout<<ls<<" "<<rs<<endl;
int us=up[i-1][j],ds=dp[i+1][j];
//cout<<us<<" "<<ds<<endl;
int an=min({ls,rs,us,ds});
ans = max(ans,4*an+1);
}
}
cout<<ans<<endl;
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1143 Plus of Pluses
- Contest
- LU IUJPC : Sylhet Division 2024
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-12-09 07:13:09
- Judged At
- 2024-12-09 07:13:09
- Judged By
- Score
- 100
- Total Time
- 324ms
- Peak Memory
- 66.078 MiB