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:34:55
Task:Grid
Sender:barely div 2.8 burgeria
Submission time:2018-05-26 11:34:55
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long LL;

int main(){
	LL n; cin >> n;
	vector<string> v;
	vector<bool> rowb(n);
	vector<bool> colb(n);
	int tot = 0;
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		v.emplace_back(s);
		for (char c : s) {
			if (c == '1') tot++;
		}
	}
	int rowtrue = 0;
	int coltrue = 0;
	for (int row = 0; row < n; row++) {
		int col = 0;
		for (; col < n; col++) {
			if (v[row][col] == '0') break;
		}
		if (col == n) { rowb[row] = true; rowtrue++; }
	}
	for (int col = 0; col < n; col++) {
		int row = 0;
		for (; row < n; row++) {
			if (v[row][col] == '0') break;
		}
		if (row == n) { colb[col] = true; coltrue++; }
	}
	if (rowtrue * n + coltrue * n - rowtrue*coltrue != tot) {
		cout << -1; return 0;
	}
	if (rowtrue == n || coltrue == n) {
		cout << n; return 0;
	}
	cout << rowtrue + coltrue;

}