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:32:06
Task:Grid
Sender:Tefyn virallinen maajoukkue
Submission time:2018-05-26 11:32:06
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;
string s[1010];
bool c[1010], r[1010];
int main(){
    int ans = 0;
    int n; cin >> n;
    vector<string> s2(n, string(n, '0'));
    for(int i = 0; i < n; ++i){
        cin >> s[i];
        bool ok = 1;
        for(int j = 0; j < n; ++j){
            ok &= (s[i][j] == '1');
        }
        r[i] = ok;
        ans+=ok;
    }  
    bool ok2 = 1;
     for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if((s[i][j] == '1' && r[i] != 1) || (s[i][j] == '0' && r[i] == 1))
                ok2 = false;
        }
    }  
    if(ok2){
        cout << ans << endl;
        return 0;
    }
    for(int j = 0; j < n; ++j){
         bool ok = 1;
         for(int i = 0; i < n; ++i){
            ok &= (s[i][j] == '1');
         }
         c[j] = ok;
         ans+=ok;
    }
    
    ok2 = 1;
     for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            if((s[i][j] == '1' && (r[i] | c[j]) != 1) || (s[i][j] == '0' && (r[i] | c[j]) == 1))
                ok2 = false;
        }
    }  
    if(ok2){
        cout << ans << endl;
        return 0;
    }
    cout << "-1" << endl;
    
    return 0;
}