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:45:40
2018-05-26 11:18:29
Task:Grid
Sender:Wave of Technology
Submission time:2018-05-26 11:18:29
Status:READY
Result:ACCEPTED

Show test data

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:36:8: warning: unused variable 'valid' [-Wunused-variable]
   bool valid = true;
        ^~~~~

Code

#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <vector>

using namespace std;

typedef long long ll;




int main() {
  ll n;
  cin >> n;

  vector<bitset<1000> > t (n);

  for (int i=0; i<n; i++) {
    cin >> t[i];
  }

  bitset<1000> rows;
  bitset<1000> cols;

  for (int i=0; i<n; i++) {
    cols[i] = true;
    rows[i] = true;
    for (int j=0; j<n; j++) {
      cols[i] = cols[i] && t[j][i];
      rows[i] = rows[i] && t[i][j];
    }
  }

  bool valid = true;
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      if (t[i][j] != (rows[i] || cols[j])) {
	cout << -1 << endl;
	return 0;
      }
    }
  }

  ll count = rows.count() + cols.count();

  if (count == 2*n) count = n;

  cout << count << endl;
  
  
  
}