Codeforces Round #385 (Div. 2), problem: (B) Hongcow Solves A Puzzle Solution in C/C++

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
#include <limits.h>
#include <stdio.h>

int main() {
	int i, j, n, m, cnt, imin, jmin, imax, jmax;
	static char cc[500][501];

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	imin = jmin = INT_MAX;
	imax = jmax = 0;
	cnt = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			if (cc[i][j] == 'X') {
				cnt++;
				if (imin > i)
					imin = i;
				if (imax < i)
					imax = i;
				if (jmin > j)
					jmin = j;
				if (jmax < j)
					jmax = j;
			}
	printf("%s\n", (imax - imin + 1) * (jmax - jmin + 1) != cnt ? "NO" : "YES");
	return 0;
}
[the_ad id="1072"]




Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.
#include <limits.h>
#include <stdio.h>

int main() {
	int i, j, n, m, cnt, imin, jmin, imax, jmax;
	static char cc[500][501];

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	imin = jmin = INT_MAX;
	imax = jmax = 0;
	cnt = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			if (cc[i][j] == 'X') {
				cnt++;
				if (imin > i)
					imin = i;
				if (imax < i)
					imax = i;
				if (jmin > j)
					jmin = j;
				if (jmax < j)
					jmax = j;
			}
	printf("%s\n", (imax - imin + 1) * (jmax - jmin + 1) != cnt ? "NO" : "YES");
	return 0;
}
[the_ad id="1072"]




More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Amala meal: Kogi probes deaths of four family members

The Kogi State Government has officially commenced an exhaustive investigation following the tragic demise of four family members in Ihima, located within the Okehi...

I Tried Viral Kitchen Gadgets For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases.There comes a point when you realise that tolerating a frustrating situation is costing you...

ROSIE SERENADES THE DON…

Comedian and television personality Rosie O’Donnell wrapped up her week-long stint as guest host on Jimmy Kimmel Live! with an unforgettable, razor-sharp send-off aimed...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!