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 12:50:20
2018-05-26 12:42:43
Task:Grid
Sender:DROP TABLE
Submission time:2018-05-26 12:50:20
Status:READY
Result:ACCEPTED

Show test data

Code

n = int(input())

table = []
for _ in range(n):
	table.append(list(input().rstrip()))
#print(table)

def areAllOnes(row):
	for j in range(len(row)):
		if row[j] == "0":
			return False
	return True

rowDict = {}
neededMoves = 0
for row in range(n):
	if areAllOnes(table[row]):
		rowDict[row] = True
		neededMoves += 1
colDict = {}
for i in range(n):
	allOnes = True
	for j in range(n):
		if table[j][i] == "0":
			allOnes = False
			break
	if allOnes == True:
		colDict[i] = True
		#print("COL FOUND")
		neededMoves += 1
	
if neededMoves == n*2:
	neededMoves = n
for i in range(n):
	for j in range(n):
		if table[i][j] == "1" and i not in rowDict and j not in colDict:
			neededMoves = -1
			break
print(neededMoves)