Skip to content

Instantly share code, notes, and snippets.

@rmmh
Created May 9, 2011 02:46
Show Gist options
  • Save rmmh/961961 to your computer and use it in GitHub Desktop.
Save rmmh/961961 to your computer and use it in GitHub Desktop.
Google Code Jam 2011 Prelim Round A
n_cases = input()
for case in xrange(1, n_cases + 1):
bot = {'O': [1, 0], 'B': [1, 0]}
buttons = raw_input().split()[1:]
buttons = zip(buttons[::2], map(int, buttons[1::2]))
time = 0
for color, pos in buttons:
last_pos, last_time = bot[color]
time += 1 + max(0, abs(pos - last_pos) - (time - last_time))
bot[color] = [pos, time]
print "Case #%d: %d" % (case, time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment