Contest Duration: ~ (local time) (120 minutes)

Submission #1132716

Source Code Expand

Copy
```#include<bits/stdc++.h>

using namespace std;

const int INF = 1 << 30;

int main()
{
int N;
string S[500];

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

int ret = INF;

int tatefill = 0, yokofill = 0, malta = 0, ei = 0;
for(int i = 0; i < N; i++) {
int latte = 0;
for(int j = 0; j < N; j++) latte += S[j][i] == '#';
tatefill += latte == N;
latte = 0;
for(int j = 0; j < N; j++) latte += S[i][j] == '#';
yokofill += latte == N;
malta += S[i][i] == '#';
ei += count(S[i].begin(), S[i].end(), '#') > 0;

int hack = 0, poyo = 0;
for(int j = 0; j < N; j++) {
if(S[i][j] == '.') {
++poyo;
for(int k = 0; k < N; k++) {
if(S[k][j] == '#') {
++hack;
break;
}
}
}
}
if(hack == poyo) {
ret = min(ret, N + hack);
}

}

if(yokofill > 0) ret = min(ret, N - tatefill);
if(tatefill > 0) ret = min(ret, N - tatefill + 1);
if(malta > 0) ret = min(ret, N + N - 1);
if(ei > 0) ret = min(ret, N + N);
if(ret == INF) ret = -1;
cout << ret << endl;
}```

#### Submission Info

Submission Time 2017-02-25 22:37:48+0900 B - Row to Column ei13333 C++14 (GCC 5.4.1) 0 1165 Byte WA 245 ms 512 KB

#### Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
Subtask 0 / 300 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt
All 0 / 1000 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt, 2_16.txt, 2_17.txt, 2_18.txt, 2_19.txt, 2_20.txt, 2_21.txt, 2_22.txt
Case Name Status Exec Time Memory
0_00.txt 1 ms 256 KB
0_01.txt 1 ms 256 KB
0_02.txt 1 ms 256 KB
0_03.txt 1 ms 256 KB
0_04.txt 1 ms 256 KB
1_00.txt 1 ms 256 KB
1_01.txt 1 ms 256 KB
1_02.txt 1 ms 256 KB
1_03.txt 1 ms 256 KB
1_04.txt 1 ms 256 KB
1_05.txt 1 ms 256 KB
1_06.txt 1 ms 256 KB
1_07.txt 1 ms 256 KB
1_08.txt 1 ms 256 KB
1_09.txt 1 ms 256 KB
1_10.txt 1 ms 256 KB
1_11.txt 1 ms 256 KB
1_12.txt 1 ms 256 KB
1_13.txt 1 ms 256 KB
1_14.txt 1 ms 256 KB
2_00.txt 242 ms 512 KB
2_01.txt 11 ms 512 KB
2_02.txt 240 ms 512 KB
2_03.txt 242 ms 512 KB
2_04.txt 245 ms 512 KB
2_05.txt 241 ms 512 KB
2_06.txt 238 ms 512 KB
2_07.txt 58 ms 512 KB
2_08.txt 38 ms 512 KB
2_09.txt 122 ms 512 KB
2_10.txt 98 ms 512 KB
2_11.txt 43 ms 512 KB
2_12.txt 64 ms 512 KB
2_13.txt 60 ms 512 KB
2_14.txt 117 ms 512 KB
2_15.txt 101 ms 512 KB
2_16.txt 115 ms 512 KB
2_17.txt 96 ms 512 KB
2_18.txt 72 ms 512 KB
2_19.txt 10 ms 512 KB
2_20.txt 7 ms 512 KB
2_21.txt 7 ms 512 KB
2_22.txt 12 ms 512 KB