-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy patha.py
More file actions
executable file
·26 lines (25 loc) · 763 Bytes
/
a.py
File metadata and controls
executable file
·26 lines (25 loc) · 763 Bytes
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
#!/usr/bin/env python3
# https://codejam.withgoogle.com/2018/challenges/0000000000007765/dashboard
def f(a, b, l, t, i):
if i == l:
x = ''.join(t)
if x not in a: return x
return
for c in b[i]:
t.append(c)
x = f(a, b, l, t, i + 1)
if x is not None: return x
t.pop()
for T in range(int(input())):
n, l = map(int, input().split())
a = [input() for _ in range(n)]
b = [set() for _ in range(l)]
c = [None] * l
for i in range(l):
for j in range(n):
b[i].add(a[j][i])
c[i] = sorted(b[i])
p = 1
for i in range(l): p *= len(b[i])
if p == n: print('Case #{}: {}'.format(T + 1, '-'))
else: print('Case #{}: {}'.format(T + 1, f(a, c, l, [], 0)))