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:41:09
Task:Grid
Sender:Karhukopla
Submission time:2018-05-26 11:41:09
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

#define ll long long
#define lll __int128
#define pii pair<int, int>
#define M 1000000007
#define N (1001)
using namespace std;

char t[N][N];
int rows[N], cols[N];

int main () {
	int n; cin >> n;
	for(int i=0; i<n; ++i) rows[i] = cols[i] = 1;
	
	for(int i=0; i<n; ++i){
		for(int j=0; j<n; ++j){
			cin >> t[i][j];
			if(t[i][j]=='0') cols[j] = rows[i] = 0;
		}
	}
	int V = 0;
	for(int i=0; i<n; ++i) if(rows[i]) ++V;
	if(V < n) {
		for(int i=0; i<n; ++i) if(cols[i]) ++V;
	}
	
	for(int i=0; i<n; ++i){
		for(int j=0; j<n; ++j) {
			if(t[i][j] == '1' && rows[i]+cols[j] == 0) V=-1;
		}
	}
	cout << V;
}