Created
October 11, 2015 04:02
-
-
Save whatalnk/81a24db510c370fe56fd to your computer and use it in GitHub Desktop.
TopCoder SRM 670
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
class Cdgame(): | |
def rescount(self, a, b): | |
sum_a = sum(a) | |
sum_b = sum(b) | |
res = [] | |
for i in a: | |
for j in b: | |
res.append((sum_a-i+j)*(sum_b-j+i)) | |
return(len(set(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
class Drbalance(): | |
def lesscng(self, s, k): | |
l = list(s) | |
res = 0 | |
while True: | |
costs = [l.count("+") - l.count("-")] | |
for i in range(len(l)): | |
ll = l[:-i] | |
costs.append(ll.count("+") - ll.count("-")) | |
costs_sum = len([i for i in costs if i < 0]) | |
if costs_sum > k: | |
i = l.index("-") | |
l[i] = "+" | |
res += 1 | |
else: | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment