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:37:29
Task:Grid
Sender:Ukkonen Fan Club
Submission time:2018-05-26 11:37:29
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
using namespace std;
int n;

string m[1010];
bool ch[1010][1010];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    for (int i=0;i<n;++i)cin>>m[i];
    int no=0;
    for (int i=0;i<n;++i){
        bool tk=1;
        for (int j=0;j<n;++j){
            if (m[i][j]!='1') tk=0;
        }
        if (tk){
            ++no;
            for (int j=0;j<n;++j){
                ch[i][j]=1;
            }
        }
    }
    for (int j=0;j<n;++j){
        bool tk=1;
        for (int i=0;i<n;++i){
            if (m[i][j]!='1') tk=0;
        }
        if (tk){
            ++no;
            for (int i=0;i<n;++i){
                ch[i][j]=1;
            }
        }
    }
    for (int i=0;i<n;++i){
        for (int j=0;j<n;++j){
            if (m[i][j]=='1' && !ch[i][j]) no=-1;
        }
    }
    if (no==2*n) no=n;
    cout << no << "\n";
}