Last active
January 29, 2016 04:50
-
-
Save whatalnk/3cce09300747ec822d4c to your computer and use it in GitHub Desktop.
TopCoder SRM 680 Div 2
This file contains 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
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 |
This file contains 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
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