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 13:23:09
Task:Grid
Sender:Robotiimi
Submission time:2018-05-26 13:23:09
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#include <string>
#include <vector>
//#include <array>

using namespace std;


int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);


int n;
cin >> n;

int answer = 0;
vector <vector<int> > grid;
vector <int> paintedcol;
vector <int> paintedrow;
vector <int> owngrid (n*n,0);


for (int i=0; i<n; i++) {
    string tmp;
    cin >> tmp;
    int tmpsize = tmp.size();
    vector <int> tmpv;
    for (int j=0; j<tmpsize; j++) {
        tmpv.push_back((int) tmp[j] - (int) '0');
    }
    grid.push_back(tmpv);
}

int origsum = 0;

for (int i=0; i<n; i++) {
    int sumrow = 0;
    int sumcol = 0;
    for (int j=0; j<n; j++) {
        sumrow += grid[i][j];
        sumcol += grid[j][i];
        origsum += grid[i][j];
    }
    if (sumrow == n) {
        answer++;
        for (int j=0; j<n; j++) {
            owngrid[i*n+j] = 1;
        }
        paintedrow.push_back(i);
    }
    if (sumcol == n) {
        answer++;
        for (int j=0; j<n; j++) {
            owngrid[j*n+i] = 1;
        }
        paintedcol.push_back(i);
    }
}
if (answer == n+n) {
    answer = n;
}

int ownsum = 0;

for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
        //cout << grid[i][j];
        ownsum += owngrid[i*n+j];
        //if grid[i][j]
    }
    //cout << endl;
}

if (ownsum != origsum) {
    answer = -1;
}

cout << answer << "\n";
}