Skip to content

Instantly share code, notes, and snippets.

@kierendavies
Created April 15, 2013 21:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kierendavies/5391400 to your computer and use it in GitHub Desktop.
Save kierendavies/5391400 to your computer and use it in GitHub Desktop.
Google Code Jam 2013 Qualification Round Problem B
#!/usr/bin/python3
from itertools import product
T = int(input())
for t in range(T):
N, M = list(map(int, input().split()))
grid = [list(map(int, input().split())) for n in range(N)]
rowmax = list(map(max, grid))
colmax = list(map(max, map(list, zip(*grid))))
for n, m in product(range(N), range(M)):
if grid[n][m] != rowmax[n] and grid[n][m] != colmax[m]:
print("Case #{}: NO".format(t + 1))
break
else:
print("Case #{}: YES".format(t + 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment