Time Exceeded
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];
}
}
// for(int i=0;i<n;i++){
// for(int j=0;j<m;j++){
// if(v[i][j]==' ')continue;
// cout<<v[i][j]<<' ';
// }
// cout<<endl;
// }
// return 0;
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(v[i][j]!='+')continue;
int l=0,r=min({i,j,n-i-1,m-j-1});
// bug("hi")
while(l<=r){
bool ok=1;
int mid=(l+r)/2;
int cur=0;
while(cur<=mid){
if(v[i][j+cur]!='+'){
ok=0;
break;
}
cur++;
}
// bug(ok,mid);
// return 0;
cur=0;
while(cur<=mid){
if(v[i][j-cur]!='+'){
ok=0;
break;
}
cur++;
}
cur=0;
while(cur<=mid){
if(v[i+cur][j]!='+'){
ok=0;
break;
}
cur++;
}
cur=0;
while(cur<=mid){
if(v[i-cur][j]!='+'){
ok=0;
break;
}
cur++;
}
if(ok)l=mid+1;
else r=mid-1;
if(ok)ans=max(ans,4*mid+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 06:25:48
- Judged At
- 2024-12-09 06:25:48
- Judged By
- Score
- 44
- Total Time
- ≥2090ms
- Peak Memory
- ≥1.535 MiB