Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active January 29, 2016 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/3cce09300747ec822d4c to your computer and use it in GitHub Desktop.
Save whatalnk/3cce09300747ec822d4c to your computer and use it in GitHub Desktop.
TopCoder SRM 680 Div 2
import itertools
class BearPair:
def bigDistance(self, s):
n = len(s)
res = -1
for e in itertools.combinations(xrange(n), 2):
i = e[0]
j = e[1]
if s[i] != s[j]:
res = max(res, abs(i - j))
return res
import bisect
class BearChairs:
def findPositions(self, atLeast, d):
res = []
occupied = []
for i in atLeast:
tmp = i
for j in occupied:
if j - d < tmp < j + d:
tmp = j + d
res.append(tmp)
bisect.insort_left(occupied, tmp)
return tuple(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment