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:34:24
2018-05-26 13:23:08
2018-05-26 13:21:54
2018-05-26 12:55:29
2018-05-26 12:46:14
Task:Grid
Sender:El Numero Uno
Submission time:2018-05-26 13:34:24
Status:READY
Result:ACCEPTED

Show test data

Code

def main():
	ans = True
	n = int(input())
	rows = 0
	col = None
	for i in range(n):
		if not ans:
			input()
			continue
		l = list(map(int, list(input())))
		if sum(l) == n:
			rows += 1
		else:
			if col == None:
				col = l
			else:
				for j in range(len(l)):
					if l[j] != col[j]:
						print("-1")
						ans = False
	if not ans:
		return
	sr = rows
	sc = sum(col) if col is not None else 0
	if sr == n or sc == n:
		print(n)
	else:
		print(sr + sc)
		

main()