-
Notifications
You must be signed in to change notification settings - Fork 0
/
codejam2020.py
46 lines (39 loc) · 1.28 KB
/
codejam2020.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
def find_answer(my_array):
n = len(my_array)
my_cols = {}
num_rep_row = 0
num_rep_col = 0
trace = 0
for k in range(len(my_array)):
my_cols[k] = []
for k in range(len(my_array)):
row_safe = True
for y in range(len(my_array[k])):
if row_safe and my_array[k][y] in my_array[k][:y]:
num_rep_row += 1
row_safe = False
if my_cols[y] != -1 and my_array[k][y] in my_cols[y]:
my_cols[y] = -1
num_rep_col += 1
if my_cols[y] != -1:
my_cols[y].append(my_array[k][y])
if k == y:
trace += int(my_array[k][y].strip())
return ": " + str(trace) + " " + str(num_rep_row) + " " + str(num_rep_col)
my_array = sys.stdin.readlines()
num_tests = int(my_array[0].strip())
iter = 1
solution = ""
for k in range(num_tests):
size = int(my_array[iter].strip())
iter += 1
this_array = []
for z in range(size):
this_array.append(my_array[iter].split(" "))
iter += 1
if k < num_tests - 1:
solution = solution + "Case #" + str(k + 1) + find_answer(this_array) + "\n"
else:
solution = solution + "Case #" + str(k + 1) + find_answer(this_array)
print(solution)