825B - Five-In-a-Row - CodeForces Solution


brute force implementation *1600

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
// long long int n,m,k,flag=0,sz=0,v[51][51],dx[]={0,0,0,1},dy[]={1,0,0,0};
// string s[51];
// vector<pair<long long int,pair<long long int,long long int>>>vv;
// void dfschng(long long int x,long long int y)
// {
//  if(x<0 || y<0 || x>=n || y>=m)
//  {
//   return;
//  }
//  if(v[x][y] || s[x][y]=='*')
//  {
//   return;
//  }
//  //cout<<x<<" "<<y<<"\n";
//  v[x][y]=1;s[x][y]='*';
//  for(long long int i=0;i<4;i++)
//  {
//   long long int xx=x+dx[i],yy=y+dy[i];
//   dfschng(xx,yy);
//  }
// }
// void dfs(long long int x,long long int y)
// {
//  if(x<0 || y<0 || x>=n || y>=m)
//  {
//   return;
//  }
//  if(v[x][y] || s[x][y]=='*')
//  {
//   return;
//  }
//  v[x][y]=1;sz++;
//  if(x==0 || y==0 || x==(n0) || y==(m0))
//  {
//   flag=1;
//  }
//  for(long long int i=0;i<4;i++)
//  {
//   long long int xx=x+dx[i],yy=y+dy[i];
//   dfs(xx,yy);
//  }
// }
// long long int n;
//  cin>>n;
//  for(long long int i=1;i<=n;i+=2)
//  {
//   cout<<i<<" ";
//  }
//  for(long long int i=n-(n&1);i>=1;i-=2)
//  {
//   cout<<i<<" ";
//  }
//  cout<<"\n";
void solve()
{
 long long int n,cnt=0,op=0;
 n=10;
 string ss[10];
 for(auto&s:ss)
 {
  cin>>s;
 }
 //horizontal
 for(long long int i=0;i<n;i++)
 {
  for(long long int j=0;j<=5;j++)
  {
   cnt=0;
   for(long long int k=j;k<j+5;k++)
   {
    cnt+=(ss[i][k]=='X')-(ss[i][k]=='O');
   }
   if(cnt==4)
   {
    op=1;break;
   }
  }
  if(op)
  {
   break;
  }
 }
 if(op)
 {
  cout<<"YES";return;
 }
 //verticle
 for(long long int j=0;j<n;j++)
 {
  for(long long int i=0;i<=5;i++)
  {
   cnt=0;
   for(long long int k=i;k<i+5;k++)
   {
    cnt+=(ss[k][j]=='X')-(ss[k][j]=='O');
   }
   if(cnt==4)
   {
    op=1;break;
   }
  }
  if(op)
  {
   break;
  }
 }
 if(op)
 {
  cout<<"YES";return;
 }
 for(long long int i=0;i<=5;i++)
 {
  for(long long int j=0;j<=5;j++)
  {
   cnt=0;
   for(long long int k=0;k<5;k++)
   {
    cnt+=(ss[i+k][j+k]=='X')-(ss[i+k][j+k]=='O');
   }
   if(cnt==4)
   {
    op=1;break;
   }
  }
  if(op)
  {
   break;
  }
 }
 if(op)
 {
  cout<<"YES";return;
 }
 for(long long int i=0;i<=5;i++)
 {
  for(long long int j=4;j<n;j++)
  {
   cnt=0;
   for(long long int k=0;k<5;k++)
   {
    cnt+=(ss[i+k][j-k]=='X')-(ss[i+k][j-k]=='O');
   }
   if(cnt==4)
   {
    op=1;break;
   }
  }
  if(op)
  {
   break;
  }
 }
 if(op)
 {
  cout<<"YES";return;
 }
 cout<<"NO";
}
int main()
{
    fast_cin();
    long long int t;
    //cin>>t;
    t=1;
    while(t--)
    {
     solve();
    }
   return 0;
}


Comments

Submit
0 Comments
More Questions

1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves