Problem:


Score : 1300 points

Problem Statement

There is a square-shaped grid with N vertical rows and N horizontal columns.
We will denote the square at the i-th row from the top and the j-th column from the left as (i,\ j).

Initially, each square is either white or black.
The initial color of the grid is given to you as characters a_{ij}, arranged in a square shape.
If the square (i,\ j) is white, a_{ij} is .. If it is black, a_{ij} is #.

You are developing a robot that repaints the grid.
It can repeatedly perform the following operation:

Select two integers i, j (1 ≤ i,\ j ≤ N). Memorize the colors of the squares (i,\ 1), (i,\ 2), ..., (i,\ N) as c_1, c_2, ..., c_N, respectively. Then, repaint the squares (1,\ j), (2,\ j), ..., (N,\ j) with the colors c_1, c_2, ..., c_N, respectively.

Your objective is to turn all the squares black.
Determine whether it is possible, and find the minimum necessary number of operations to achieve it if the answer is positive.

Constraints

2 ≤ N ≤ 500

a_{ij} is either . or #.

Partial Score

In a test set worth 300 points, N ≤ 3.

Input

The input is given from Standard Input in the following format:

N
a_{11}...a_{1N}
:
a_{N1}...a_{NN}

Output

If it is possible to turn all the squares black, print the minimum necessary number of operations to achieve the objective.
If it is impossible, print -1 instead.

Sample Input 1

2
#.
.#

Sample Output 1

3

For example, perform the operation as follows:

Select i = 1, j = 2.

Select i = 1, j = 1.

Select i = 1, j = 2.

The transition of the colors of the squares is shown in the figure below:

Sample Input 2

2
..
..

Sample Output 2

-1

Sample Input 3

2
##
##

Sample Output 3

0

Sample Input 4

3
.#.
###
.#.

Sample Output 4

2

Sample Input 5

3
...
.#.
...

Sample Output 5

5



Sample input:
2
#.
.#


Sample output:
3

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
c=[]
x=[]
y=[]
dot=0
sharp=0
havePerfectRow=False
for i in range(n):
    s=raw_input()
    c.append(s)
    haveDot=False
    ss=0
    for j in range(n):
        if(s[j]=='.'):
            dot=dot+1
            haveDot=True
        else:
            ss=ss+1
            sharp=sharp+1
    x.append(ss)
    if not haveDot:
        havePerfectRow=True

if(dot==n*n):
    print -1
elif(sharp==n*n):
    print 0
elif(sharp==1):
    print n*2-1
elif(havePerfectRow):
    needColumn=0
    for j in range(n):
        need=False
        for i in range(n):
            if(c[i][j]=='.'):
                need=True
                break
        if(need):
            needColumn=needColumn+1
    print needColumn
else:
    for j in range(n):
        count=0
        for i in range(n):
            if(c[i][j]=='#'):
                count=count+1
        y.append(count)

    toPerfect=[]
    for i in range(n):
        count=0
        for j in range(n):
            if(c[i][j]=='.'):
                if(y[j]>0):
                    count=count+1
                else:
                    count=count+2
        toPerfect.append(count)
    cost=min(toPerfect)
    for j in range(n):
        if y[j]<n:
            cost=cost+1

    print cost

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
a = [[0]*n]*n
check = ['#']*n
check2 = ['.']*n

for i in range(n):
    tmp = input()
    a[i] = list(tmp)

flag = 0
flag2 = 0
for i in range(n):
    if a[i] != check:
        flag = 1
        break
for i in range(n):
    if a[i] != check2:
        flag2 = 1
        break

if flag == 0:
    print(0)
elif flag2 != 1:
    print(-1)
else:
    m = 0
    c = []
    tmpi = 0
    count = 0
    for i in range(n):
        if m < a[i].count('#'):
            m = a[i].count('#')
            count += 1
            tmpi = i
    for i in range(n):
        flag = 0
        for j in range(n):
            if a[j][i] != '#':
                flag = 1
                break
        if flag == 0:
            c.append(i)
    if m == n:                
        print(m-len(c))
        
    elif m == 1 and count == 1:
        if tmpi != a[tmpi].index('#'):
            for i in range(n):
                flag = 0
                for j in range(n):
                    if a[i][j] == '#':
                        if i == j:
                            print(n-1+n-len(c))
                            flag = 1
                            break
                if flag == 1:
                    break
            if flag == 0:
                print(n-m+n-len(c))
        else:
            print(n-m+n-len(c))

    else:
        ad = n-m
        print(ad + n - len(c))

Submission status: Wrong Answer

Solution code:
# coding: utf-8

num_n = int(input())
board = [list(input()) for j in range(num_n)]

print(num_n)
print(board)

def chage_board(i, j):
	global board
	list_mem = []
	list_men = board[i - 1]
	print(list_men)
	
	for item in list_mem:
		print(item)
		# board[index][j - 1] = item

chage_board(1, 2)
print(board)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
a = [[0]*n]*n
check = ['#']*n
check2 = ['.']*n

for i in range(n):
    tmp = input()
    a[i] = list(tmp)

flag = 0
flag2 = 0
for i in range(n):
    if a[i] != check:
        flag = 1
        break
for i in range(n):
    if a[i] != check2:
        flag2 = 1
        break

if flag == 0:
    print(0)
elif flag2 != 1:
    print(-1)
else:
    m = 0
    c = []
    tmpi = 0
    count = 0
    for i in range(n):
        if m < a[i].count('#'):
            m = a[i].count('#')
            count += 1
            tmpi = i
    for i in range(n):
        flag = 0
        for j in range(n):
            if a[j][i] != '#':
                flag = 1
                break
        if flag == 0:
            c.append(i)
    if m == n:                
        print(m-len(c))
        
    elif m == 1 and count == 1:
        if tmpi != a[tmpi].index('#'):
            for i in range(n):
                flag = 0
                for j in range(n):
                    if a[j][i] == '#':
                        if j == i:
                            print(n-1+n-len(c))
                            flag = 1
                            break
                if flag == 1:
                    break
            if flag == 0:
                print(n-m+n-len(c))
        else:
            print(n-m+n-len(c))

    else:
        ad = n-m
        print(ad + n - len(c))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys

def check(a, index):
    for i in xrange(len(a)):
        if a[i][index] == '#':
            return True
    return False

def main(argv):
    line = sys.stdin.readline().rstrip("\n")

    while line:
        n = int(line)
        a = [[0] * n for i in xrange(n)]
        for i in xrange(n):
            line = raw_input()
            for j in xrange(len(line)):
                a[i][j] = line[j]

        h = [0] * n
        v = [0] * n
        for i in xrange(n):
            for j in xrange(n):
                if a[i][j] == '.':
                    h[i] += 1
                    v[j] += 1

        result = -1
        for row in sorted(range(len(h)), key=lambda k: h[k]):

            flag = True
            for column, value in enumerate(a[row]):
                if value == '.' and not check(a, row):
                    flag = False

            if flag:
                result = h[row]
                for i in xrange(len(v)):
                    if v[i] > 0:
                        result += 1
                break
        print result

        line = sys.stdin.readline().rstrip("\n")

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
#-*- coding:utf-8 -*-
import numpy as np

N = raw_input()
N = int(N)
bw = []

for i in range(N):
    bw.append([1 if x =="#" else 0 for x in list(raw_input())])


#print bw
#print bw[0][:]
#print bw[:][1]

#a = max([bw[i][:].count(1) for i in range(N-1)])

#横を最大値を拾う
a = max([bw[i][:].count(1) for i in range(N)])
if a ==1 and [bw[i][i] for i in range(N)].count(1)==0:
    c=1
else:
    c=0
#print a
#縦の最大値
b = [bw[:][i].count(1) for i in range(N)].count(N)

if a == 0:
    print -1
else:
    res = 2*N-a-b+c
    print res

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [[0 if x == "." else 1 for x in input()] for i in range(N)]

if sum([sum(x) for x in A]) == 0:
    print(-1)
else:
    sum_list = [0] * N
    for i in range(N):
        s = 0
        for j in range(N):
            s += A[j][i]
        sum_list[i] = s

    count = N
    index = []
    flag2 = True
    for i in range(N):
        tmp = 0
        id = []
        flag1 = True
        for j in range(N):
            if A[i][j] == 1:
                continue
            elif sum_list[i] > 0:
                tmp += 1
                id.append(j)
            else:
                flag1 = False
                break

        if flag1:
            flag2 = False
            if tmp <= count:
                count = tmp
                index = id

        if count == 0:
            break

    if flag2:
        print(-1)
    else:
        result = 2 * count
        for i in range(N):
            if i not in index and sum_list[i] != N:
                result += 1

        print(result)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
a = []

total = 0
for i in range(n):
    ai = raw_input()
    ai = map(lambda x: x == '#', ai)
    a.append(ai)
    total += sum(ai)

if total == 0:
    print -1
    exit()

b = [0] * n
for i in range(n):
    flag = 0
    for j in range(n):
        flag |= a[j][i]
    b[i] = flag^1

col = 0
for j in range(n):
    flag = 1
    for i in range(n):
        flag &= a[i][j]
    col += flag

ans = float('inf')
for i in range(n):
    total = 0
    for j in range(n):
        if a[i][j] == 0:
            total += 1 + b[i]
    ans = min(ans, total + n-col)

print ans

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
a = [[0]*n]*n
check = ['#']*n
check2 = ['.']*n

def rep(i,j):
    c = ['']*n
    for k in range(n):
        c[k] = a[i][k]
    for k in range(n):
        a[k][j] = c[k]
    return 0

for i in range(n):
    tmp = input()
    a[i] = list(tmp)

flag = 0
flag2 = 0
for i in range(n):
    if a[i] != check:
        flag = 1
        break
for i in range(n):
    if a[i] != check2:
        flag2 = 1
        break

if flag == 0:
    print(0)
elif flag2 != 1:
    print(-1)
else:
    m = 0
    c = []
    tmpi = 0
    count = 0
    for i in range(n):
        if m < a[i].count('#'):
            m = a[i].count('#')
            count += 1
            tmpi = i
    for i in range(n):
        flag = 0
        for j in range(n):
            if a[j][i] != '#':
                flag = 1
                break
        if flag == 0:
            c.append(i)
    if m == n:                
        print(m-len(c))
        
    elif m == 1 and count == 1:
        flag = 0
        for i in range(n):
            for j in range(n):
                if a[i][j] == '#':
                    if i == j:
                        print(n-1+n-len(c))
                        flag = 1
                        break
            if flag == 1:
                break

        if flag == 0:
            print(n-m+n-len(c))

    else:
        ad = n-m
        print(ad + n - len(c))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [[0 if x == "." else 1 for x in input()] for i in range(N)]

if sum([sum(x) for x in A]) == 0:
    print(-1)
else:
    sum_list = [0] * N
    for i in range(N):
        s = 0
        for j in range(N):
            s += A[j][i]
        sum_list[i] = s

    count = N
    index = []
    for i in range(N):
        tmp = 0
        id = []
        flag = True
        for j in range(N):
            if A[i][j] == 1:
                continue
            elif sum_list[i] > 0:
                tmp += 1
                id.append(j)
            else:
                flag = False
                break

        if flag:
            if tmp <= count:
                count = tmp
                index = id

        if count == 0:
            break
    
    if count == N:
        print(-1)
    else:
        result = 2 * count
        print(count, index)
        for i in range(N):
            if i not in index and sum_list[i] != N:
                result += 1
    
        print(result)

Submission status: Wrong Answer

Solution code:
import numpy    
import sys

N = int(sys.stdin.readline())
Nsquared = N*N
masu = numpy.zeros((N,N), dtype=numpy.bool)
numoperation = 0

def check_filled():
    global masu, Nsquared
    return numpy.sum(masu) == Nsquared

def find_fillable_row(row):
    global masu

def find_max_filled_row():
    global masu, N
    max_n = 501
    max_n_row = -1
    for irow in range(N):
        tmp = numpy.sum(masu[irow])
        if max_n < tmp:
            max_n = tmp
            max_n_row = irow
    return max_n, max_n_row

if __name__ == '__main__':
    for irow in range(N):
        line = sys.stdin.readline().rstrip('\n')
        for icol, c in enumerate(line):
            if c == '#':
                masu[irow,icol] = True
            else:
                masu[irow,icol] = False

    if check_filled():
        print(0)
        sys.exit(0)
    if numpy.sum(masu) == 0:
        print(-1)
        sys.exit(0)

    while True:
        if check_filled():
            print(numoperation)
            sys.exit(0)
        max_n, max_n_row = find_max_filled_row()
        filled_rows = []
        for icol, v in enumerate(masu[max_n_row]):
            if not v:
                found = False
                # TODO find the row which fills masu the most
                for jrow, r in enumerate(masu[:, max_n_row]):
                    if r:
                        found = True
                        masu[icol,:] = masu[:, jrow]
                        numoperation += 1
                if not found:
                    # TODO fix infinite loop
                    masu[icol,: ] = masu[:, max_n_row]
                    numoperation += 1

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

def sampling_row(mat, row):
    row_str = copy.deepcopy(mat[row, :])
    return row_str

def writing_col(mat, row_str, col):

    row = 0
    for s in row_str:
        mat[row, col] = s
        row+=1

def check(mat, N):
    max_val = 0
    max_row = 0
    max_col = 0
    for i in range(N):
        for j in range(N):
            row = mat[i, :]
            col = mat[:, j]
            val = 0

            for k in range(N):
                if row[k] == "#" and col[k] == ".":  
                    val += 1
                elif row[k] == "." and col[k] == "#":
                    val -= 1

            if max_val < val:
                max_val = val
                max_row = i
                max_col = j

    return (max_val, max_row, max_col)


if __name__ == "__main__":
    mat_str = []

    N = raw_input()
    N = int(N)
    mat = np.zeros((N, N), str)
    for i in range(N):
        s = raw_input()
        for j in range(N):
            mat[i][j] = s[j]

    # row = sampling(mat, 0)
    # writing(mat, row, 1)

    is_ok = -1

    for s in mat.reshape(N*N):
        if s == "#":
            is_ok = 0

    if is_ok != -1:
        while True:
            max_val, max_row, max_col = check(mat, N)
            if max_val == 0:
                break
            else:
                writing_col(mat, sampling_row(mat, max_row), max_col)
                is_ok += 1
                # print mat
                
    print is_ok

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [[] for i in range(N)]
for i in range(N):
    a[i] = input()

res = -1
c = 0
for i in range(N):
    flag = 1
    for j in range(N):
        if a[j][i] == '.':
            flag = 0
    if flag:
        c += 1

for i in range(N):
    flag = 0
    for j in range(N):
        if a[j][i] == '#':
            flag = 1

    if not flag:
        continue
    cnt = 0
    for j in range(N):
#        print(a[i][j])
        if a[i][j] != '#':
            cnt += 1

#    print(i, cnt, c)
    if res == -1 or cnt + N - c < res:
        res = cnt + N - c

        
print(res)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
a = [[0]*n]*n
check = ['#']*n
check2 = ['.']*n

def rep(i,j):
    c = ['']*n
    for k in range(n):
        c[k] = a[i][k]
    for k in range(n):
        a[k][j] = c[k]
    return 0

for i in range(n):
    tmp = input()
    a[i] = list(tmp)

flag = 0
flag2 = 0
for i in range(n):
    if a[i] != check:
        flag = 1
        break
for i in range(n):
    if a[i] != check2:
        flag2 = 1
        break

if flag == 0:
    print(0)
elif flag2 != 1:
    print(-1)
else:
    m = 0
    c = []
    tmpi = 0
    count = 0
    for i in range(n):
        if m < a[i].count('#'):
            m = a[i].count('#')
            count += 1
            tmpi = i
    for i in range(n):
        flag = 0
        for j in range(n):
            if a[j][i] != '#':
                flag = 1
                break
        if flag == 0:
            c.append(i)
    if m == n:                
        print(m-len(c))
        
    elif m == 1 and count == 1:
        if tmpi != a[tmpi].index('#'):
            flag = 0
            for i in range(n):
                for j in range(n):
                    if a[i][j] == '#':
                        if i == j:
                            print(n-1+n-len(c))
                            break

        else:
            print(n-m+n-len(c))

    else:
        ad = n-m
        print(ad + n - len(c))

Submission status: Wrong Answer

Solution code:
#-*- coding:utf-8 -*-
import numpy as np

N = raw_input()
N = int(N)
bw = []

for i in range(N):
    bw.append([1 if x =="#" else 0 for x in list(raw_input())])


#print bw
#print bw[0][:]
#print bw[:][1]

#a = max([bw[i][:].count(1) for i in range(N-1)])

#横を最大値を拾う
a = max([bw[i][:].count(1) for i in range(N)])
#print a
#縦の最大値
b = [bw[:][i].count(1) for i in range(N)].count(N)

if a == 0:
    print -1
else:
    res = 2*N-a-b
    print res

Submission status: Wrong Answer

Solution code:
from itertools import product as prod

n = int(input())
als = [list(input()) for _ in range(n)]

def transpose_matrix(mat):
    newmat = [["@"] * n for _ in range(n)]
    for i, j in prod(range(n), repeat=2):
        newmat[i][j] = mat[i][j]
    return newmat

def count_black_dot(als):
    rowcnts = []
    colcnts = []
    for al in als:
        rowcnts.append(al.count("#"))

    t_als = transpose_matrix(als)
    for t_al in als:
        colcnts.append(t_al.count("#"))

    return rowcnts, colcnts

def count_dia_elem(mat):
    n = len(mat[0])
    cnt = 0
    for i in range(n):
        if mat[i][i] == "#":
            cnt += 1
    return cnt

ans = 0
maxcnt = float("inf")
rowcnts, colcnts = count_black_dot(als)
row_line, col_line = rowcnts.count(n), colcnts.count(n)
row_max, col_max = max(rowcnts), max(colcnts)
dia_cnt = count_dia_elem(als)

if row_max == 0:
    ans = -1
elif row_line != 0:
    ans = n - col_line
else:
    idx = rowcnts.index(row_max)
    if als[idx][idx] == ".":
        ans += (n - dia_cnt)
        ans += n - col_line
    else:
        ans += n - row_max
        ans += n - col_line

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

n = int(input())
field = [None] * n
for i in range(n):
    field[i] = [c == '#' for c in input().strip()]


def sort_row(field):
    return sorted(range(n), key=lambda i: -sum(field[i]))


def find_bk_col(field, row):
    for r in range(n):
        if field[r][row]:
            return r
    return None


def cnt_all_bk_col(field):
    cnt = 0
    for c in range(n):
        if all([field[r][c] for r in range(n)]):
            cnt += 1
    return cnt


def main():
    if sum([sum(r) for r in field]) == 0:
        return -1

    row_list = sort_row(field)
    for r in row_list:
        if sum(field[r]) == 0:
            break
        bc = find_bk_col(field, r)
        if bc is not None:
            cnt = n - sum(field[r])
            cnt += n - cnt_all_bk_col(field)
            return cnt
    return n * 2


print(main())

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
a = [[0]*n]*n
check = ['#']*n
check2 = ['.']*n

def rep(i,j):
    c = ['']*n
    for k in range(n):
        c[k] = a[i][k]
    for k in range(n):
        a[k][j] = c[k]
    return 0

for i in range(n):
    tmp = input()
    a[i] = list(tmp)

flag = 0
flag2 = 0
for i in range(n):
    if a[i] != check:
        flag = 1
        break
for i in range(n):
    if a[i] != check2:
        flag2 = 1
        break

if flag == 0:
    print(0)
elif flag2 != 1:
    print(-1)
else:
    m = 0
    c = []
    tmpi = 0
    count = 0
    for i in range(n):
        if m < a[i].count('#'):
            m = a[i].count('#')
            count += 1
            tmpi = i
    for i in range(n):
        flag = 0
        for j in range(n):
            if a[j][i] != '#':
                flag = 1
                break
        if flag == 0:
            c.append(i)
    if m == n:                
        print(m-len(c))
        
    elif m == 1 and count == 1:
        if tmpi != a[tmpi].index('#'):
            flag = 0
            for i in range(n):
                for j in range(n):
                    if a[i][j] == '#':
                        if i == j:
                            print(n-1+n-len(c))

        else:
            print(n-m+n-len(c))

    else:
        flag = 0
        for i in range(n):
            for j in range(n):
                if a[i][j] == '#':
                    if i == j:
                        print(n-1+n-len(c))
                        flag = 1
                        break
        if flag == 0:
            #print(tmpi,m)
            ad = n-m
            print(ad + n - len(c))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [[0 if x == "." else 1 for x in input()] for i in range(N)]

if sum([sum(x) for x in A]) == 0:
    print(-1)
else:
    sum_list = [0] * N
    for i in range(N):
        s = 0
        for j in range(N):
            s += A[j][i]
        sum_list[i] = s

    count = N
    index = []
    for i in range(N):
        tmp = 0
        id = []
        flag = True
        for j in range(N):
            if A[i][j] == 1:
                continue
            elif sum_list[i] > 0:
                tmp += 1
                id.append(j)
            else:
                flag = False
                break

        if flag:
            if tmp <= count:
                count = tmp
                index = id

        if count == 0:
            break

    result = 2 * count
    for i in range(N):
        if i not in index and sum_list[i] != N:
            result += 1

    print(result)

Submission status: Wrong Answer

Solution code:
from itertools import product as prod

n = int(input())
als = [list(input()) for _ in range(n)]

def transpose_matrix(mat):
    newmat = [["@"] * n for _ in range(n)]
    for i, j in prod(range(n), repeat=2):
        newmat[i][j] = mat[i][j]
    return newmat

def count_black_dot(als):
    rowcnts = []
    colcnts = []
    for al in als:
        rowcnts.append(al.count("#"))

    t_als = transpose_matrix(als)
    for t_al in als:
        colcnts.append(t_al.count("#"))

    return rowcnts, colcnts

def count_dia_elem(mat):
    n = len(mat[0])
    cnt = 0
    for i in range(n):
        if mat[i][i] == "#":
            cnt += 1
    return cnt

ans = 0
maxcnt = float("inf")
rowcnts, colcnts = count_black_dot(als)
row_line, col_line = rowcnts.count(n), colcnts.count(n)
row_max, col_max = max(rowcnts), max(colcnts)
dia_cnt = count_dia_elem(als)

if row_max == 0:
    ans = -1
elif row_line != 0:
    ans = n - col_line
else:
    ans += n - row_max
    ans += n - col_line
    idx = rowcnts.index(row_max)
    if als[idx][idx] == ".":
        ans += (n - dia_cnt)

print(ans)

Submission status: Wrong Answer

Solution code:
from queue import Queue
import numpy as np

n=int(input())
l=[]
for i in range(n):
	l.append(list(input()))

for i in range(n):
	for j in range(n):
		if l[i][j] == ".":
			l[i][j] = 0
		else:
			l[i][j] = 1

l=np.array(l)

if all([l[x][y]==0 for x in range(n) for y in range(n)]):
	print(-1)
	exit()

q = Queue()

q.put([l,0])

while not q.empty():
	t = q.get()
	flag = True
	for i in range(n):
		for j in range(n):
			if t[0][i][j] == 0:
				flag = False
				break
		if flag == False:
			break
	if flag:
		res = t[1]
		break
	for i in range(n):
		if any([x==1 for x in t[0][i,:]]):
			for j in range(n):		
				tmp = np.array(t[0])
				tmp[:,j] = tmp[i,:]
				q.put([tmp,t[1]+1])

print(res)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = [raw_input() for _ in xrange(N)]
counts = map(lambda x: x.count("#"), A)

if sum(counts) == 0:
	print -1
	exit(0)

for i in xrange(N):
	has_hash = False
	for j in xrange(N):
		if A[j][i] == "#":
			has_hash = True
	if not has_hash:
		counts[i] -=1
ans = N+N-max(counts)

for i in xrange(N):
	complete = True
	for j in xrange(N):
		if A[i][j] != "#":
			complete = False
	if complete:
		ans -= 1

print ans

Submission status: Wrong Answer

Solution code:
import numpy    
import sys

N = int(sys.stdin.readline())
masu = numpy.zeros((N,N), dtype=numpy.bool)

def find_fillable_row(row):
    global masu


for irow in range(N):
    line = sys.stdin.readline().rstrip('\n')
    for icol, c in enumerate(line):
        if c == '#':
            masu[irow,icol] = True
        else:
            masu[irow,icol] = False

max_n = 501
max_n_row = -1
filled_row = 0
for irow in range(N):
    tmp = numpy.sum(masu[irow])
    if tmp == N:
        filled_row+=1
    if max_n < tmp:
        max_n = tmp
        max_n_row = irow
if filled_row == N:
    print(0)
    sys.exit(0)
if max_n == 501:
    print(-1)
    sys.exit(0)

# for icol, v in enumerate(masu[row]):
#     if not masu[row, icol]:

Submission status: Wrong Answer

Solution code:
import numpy    
import sys

N = int(sys.stdin.readline())
masu = numpy.zeros((N,N), dtype=numpy.bool)

def find_fillable_row(row):
    global masu
    pass


for irow in range(N):
    line = sys.stdin.readline().rstrip('\n')
    for icol, c in enumerate(line):
        if c == '#':
            masu[irow,icol] = True
        else:
            masu[irow,icol] = False

max_n = -1
max_n_row = -1
filled_row = 0
for irow in range(N):
    tmp = numpy.sum(masu[irow])
    if tmp == N:
        filled_row+=1
    if max_n < tmp:
        max_n = tmp
        max_n_row = irow
if filled_row == N:
    print(0)
    sys.exit(0)
if max_n == -1:
    print(-1)
    sys.exit(0)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
a = [[0]*n]*n
check = ['#']*n
check2 = ['.']*n

def rep(i,j):
    c = ['']*n
    for k in range(n):
        c[k] = a[i][k]
    for k in range(n):
        a[k][j] = c[k]
    return 0

for i in range(n):
    tmp = input()
    a[i] = list(tmp)

flag = 0
flag2 = 0
for i in range(n):
    if a[i] != check:
        flag = 1
        break
for i in range(n):
    if a[i] != check2:
        flag2 = 1
        break

if flag == 0:
    print(0)
elif flag2 != 1:
    print(-1)
else:
    m = 0
    c = []
    tmpi = 0
    count = 0
    for i in range(n):
        if m < a[i].count('#'):
            m = a[i].count('#')
            count += 1
            tmpi = i
    for i in range(n):
        flag = 0
        for j in range(n):
            if a[j][i] != '#':
                flag = 1
                break
        if flag == 0:
            c.append(i)
    if m == n:                
        print(m-len(c))
        
    elif m == 1 and count == 1:
        if tmpi != a[tmpi].index('#'):
            print(2*n)
        else:
            print(n-m+n-len(c))
            
    else:
        #print(tmpi,m)
        ad = n-m
        print(ad + n - len(c))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [[0 if x == "." else 1 for x in input()] for i in range(N)]

if sum([sum(x) for x in A]) == 0:
    print(-1)
else:
    sum_list = [0] * N
    for i in range(N):
        s = 0
        for j in range(N):
            s += A[j][i]
        sum_list[i] = s

    count = N
    index = []
    for i in range(N):
        tmp = 0
        id = []
        flag = True
        for j in range(N):
            if A[i][j] == 1:
                continue
            elif sum_list[i] > 0:
                tmp += 1
                id.append(j)
            else:
                flag = False
                break

        if flag:
            if tmp < count:
                count = tmp
                index = id

        if count == 0:
            break

    result = 2 * count
    for i in range(N):
        if i not in index and sum_list[i] != N:
            result += 1

    print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
def change(a, i, j):
    b = np.copy(a)
    b[:,j] = a[i,:]
    return b
 
def isTrue(maxiter, current, a):
    n = a.shape[0]
    if np.all(a):
        return current
    current += 1
    ret = maxiter+1
    if maxiter < current:
        return ret
    for i in range(n):
        for j in range(n):
            b = change(a,i,j)
            if np.all(a==b) or np.all(b==False):
                ret = min(ret,maxiter+1)
            else:
                ret = min(ret,isTrue(maxiter, current, b))
            
    return ret
                
            
n = int(input())
a = []
for _ in range(n):
    a.append([num=='#' for num in input()])
a = np.array(a)
 
ret = isTrue(n*2-1,0,a)
if ret > n*2-1:
    ret = -1
print(ret)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n = int(input())
a = [[0]*n]*n
check = ['#']*n
check2 = ['.']*n

def rep(i,j):
    c = ['']*n
    for k in range(n):
        c[k] = a[i][k]
    for k in range(n):
        a[k][j] = c[k]
    return 0

for i in range(n):
    tmp = input()
    a[i] = list(tmp)

flag = 0
flag2 = 0
for i in range(n):
    if a[i] != check:
        flag = 1
        break
for i in range(n):
    if a[i] != check2:
        flag2 = 1
        break

if flag == 0:
    print(0)
elif flag2 != 1:
    print(-1)
else:
    m = 0
    c = []
    tmpi = 0
    for i in range(n):
        if m <= a[i].count('#'):
            m = a[i].count('#')
            tmpi = i
    for i in range(n):
        flag = 0
        for j in range(n):
            if a[j][i] != '#':
                flag = 1
                break
        if flag == 0:
            c.append(i)
    if m == n:                
        print(m-len(c))
        
    elif m ==1:
        print((n-m)*(n-len(c)))
    else:
        #print(tmpi,m)
        ad = n-m
        print(ad + n - len(c))

Submission status: Wrong Answer

Solution code:
from queue import Queue
import numpy as np

n=int(input())
l=[]
for i in range(n):
	l.append(list(input()))

for i in range(n):
	for j in range(n):
		if l[i][j] == ".":
			l[i][j] = 0
		else:
			l[i][j] = 1

l=np.array(l)

q = Queue()

q.put([l,0])

while not q.empty():
	t = q.get()
	if all([t[0][x][y]==1 for x in range(n) for y in range(n)]):
		res = t[1]
		break
	for i in range(n):
		for j in range(n):
			tmp = np.array(t[0])
			tmp[i,:] = tmp[:,j]
			q.put([tmp,t[1]+1])

print(res)