Created
April 30, 2018 10:20
-
-
Save jakab922/8dfc6e77b62ba1f533be743220e96e74 to your computer and use it in GitHub Desktop.
Mysterious road signs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict as dd | |
def show(i, key, count): | |
print "Case #%s: %s %s" % (i, key, count) | |
t = int(raw_input().strip()) | |
for ct in xrange(1, t + 1): | |
s = int(raw_input().strip()) | |
east, west = [], [] | |
for _ in xrange(s): | |
di, ai, bi = map(int, raw_input().strip().split()) | |
east.append(di + ai) | |
west.append(di - bi) | |
sol = dd(set) | |
stuffs = [east, west] | |
for i in xrange(2): | |
stuff, ostuff = stuffs[i], stuffs[(i + 1) % 2] | |
start, was = 0, [False] * s | |
while start < s: | |
while start < s and was[start]: | |
start += 1 | |
if start == s: | |
break | |
one, other = stuff[start], None | |
curr = start | |
while curr < s and (stuff[curr] == one or other is None or ostuff[curr] == other): | |
if stuff[curr] != one: | |
if other is None: | |
other = ostuff[curr] | |
else: | |
was[curr] = True | |
curr += 1 | |
sol[curr - start].add(start) | |
if other is not None: # Clearing the last block if there are more than 2 | |
curr -= 1 | |
while stuff[curr] == one: | |
was[curr] = False | |
curr -= 1 | |
max_key = max(sol.keys()) | |
show(ct, max_key, len(sol[max_key])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment