Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 11:52:55
2018-05-26 11:40:40
2018-05-26 11:39:18
Task:Grid
Sender:KnowYourArchitecture
Submission time:2018-05-26 11:52:55
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
int c[1000];
int main(){
	int n;
	cin>>n;
	vector<string> m(n);
	int rows=0;
	for(int i=0;i<n;++i){
		cin>>m[i];
	}
	for(int i=0;i<n;++i){
		bool row_ok=true;
		for(int j=0;j<n;++j){
			if(m[i][j]=='1')++c[j];
			if(m[i][j]!=m[i][0]){
				row_ok=false;
			}
		}
		if(row_ok && m[i][0]=='1')++rows;
	}
	int tmp=rows;
	if(rows!=n){
		for(int i=0;i<n;++i){
			if(c[i] == 0)continue;
			else if(c[i] == n) ++rows;
			else if(c[i] != tmp) {
				cout<<"-1\n";
				return 0;
			}
		}
	}
	cout<<rows<<'\n';
	// Check rows
	/*int rows = 0;
	for (int row = 0; row < n; row++) {
		bool issome = false;
		bool isall = true;
		for (int col = 0; col < n; col++) {
			if (m[row][col] == '1') {
				issome = true;
			} else {
				isall = false;
			}
		}
		if (isall) {
			rows++;
		} else if (issome) {
			rows = -10000;
		}
	}
	// Check cols
	int cols = 0;
	for (int col = 0; col < n; col++) {
		bool issome = false;
		bool isall = true;
		for (int row = 0; row < n; row++) {
			if (m[row][col] == '1') {
				issome = true;
			} else {
				isall = false;
			}
		}
		if (isall) {
			cols++;
		} else if (issome) {
			cols = -10000;
		}
	}
	
	if (rows < 0 && cols < 0) {
		cout << "-1\n";
		return 0;
	}*/
	
			
	return 0;
}