389B - Fox and Cross - CodeForces Solution


greedy implementation *1100

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define lli long long int
#define ii pair<lli,int>
#define fi first
#define se second
#define vec vector<lli>
using namespace std;           
int main ()       ///
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int n; cin>>n;
	char a[n+1][n+1];
	bool check[n+1][n+1], flag=true;
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) cin>>a[i][j], check[i][j]=false;
	for (int i=1;i<=n;i++) for (int j=1;j<=n;j++)
	{
		if (a[i][j]=='#' && !check[i][j])
		{
			check[i][j]=true;
			int dem=0;
			if (i<n && a[i+1][j]=='#' && !check[i+1][j]) dem++, check[i+1][j]=true;
			if (i<n && j>1 && a[i+1][j-1]=='#' && !check[i+1][j-1]) dem++, check[i+1][j-1]=true;
			if (i<n && j<n && a[i+1][j+1]=='#' && !check[i+1][j+1]) dem++, check[i+1][j+1]=true;
			if (i+1<n && a[i+2][j]=='#' && !check[i+2][j]) dem++, check[i+2][j]=true;
			if (dem!=4) {flag=false; break;}
		}
	}
	if (flag) cout<<"YES"; else cout<<"NO";
}


Comments

Submit
0 Comments
More Questions

Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!