At first check the middle * (point tat connected to east,west,south,north)
then * connected to the last of every four direction if (.) occurs then break.
///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
ll h,w,traitor=-1,on=-1;
cin>>h>>w;
string str[h+2];
ll vis[h+2][w+2];
for(ll i=0; i<h; i++)
cin>>str[i];
for(ll i=0; i<h; i++)
for(ll j=0; j<w; j++)
vis[i][j]=0;
for(ll i=0; i<h; i++)
for(ll j=0; j<w; j++)
if(str[i][j]=='*')
vis[i][j]=1;
for(ll i=1; i<h-1; i++)
for(ll j=1; j<w-1; j++)
if(str[i][j]=='*' && str[i-1][j]=='*' && str[i][j-1]=='*' && str[i][j+1]=='*' && str[i+1][j]=='*')
{
traitor=i,on=j;
break;
}
if(traitor!=(-1) && on!=(-1))
{
for(ll i=traitor; i<=traitor; i++)
for(ll j=on+1; j<w; j++)
{
if(str[i][j]=='.')
break;
else
vis[i][j]=0;
}
for(ll i=traitor; i<=traitor; i++)
for(ll j=on-1; j>=0; j--)
{
if(str[i][j]=='.')
break;
else
vis[i][j]=0;
}
ll go=0;
for(ll i=traitor+1; i<h && go!=1 ; i++)
for(ll j=on; j<=on; j++)
{
if(str[i][j]=='.')
{
go=1;
break;
}
else
vis[i][j]=0;
}
go=0;
for(ll i=traitor; i>=0 && go!=1; i--)
for(ll j=on; j<=on; j++)
{
if(str[i][j]=='.')
{
go=1;
break;
}
else
vis[i][j]=0;
}
}
ll flag=1;
for(ll i=0;i<h;i++)
for(ll j=0;j<w;j++)
if(vis[i][j])
{
flag=0;
break;
}
if(flag && traitor!=(-1) && on!=(-1)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
///Alhamdulillah
Problem Link:https://codeforces.com/contest/1182/problem/B
Comments
Post a Comment