Skip to content

Instantly share code, notes, and snippets.

@whatalnk
whatalnk / SRM670_Div2_Easy_Cdgame.py
Created October 11, 2015 04:02
TopCoder SRM 670
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)))
@whatalnk
whatalnk / arc045_a.rb
Last active October 11, 2015 08:38
ARC #045
s = gets.chomp.split(" ")
res = []
s.each do |i|
case i
when "Left" then res << "<"
when "Right" then res << ">"
when "AtCoder" then res << "A"
end
end
puts res.join(" ")
# ALDS1_1_D Maximum Profit
n = gets.chomp.to_i
r = []
n.times do
r << gets.chomp.to_i
end
maxv = r[1] - r[0]
minv = r[0]
(1..n-1).each do |i|
maxv = [maxv, r[i] - minv].max
@whatalnk
whatalnk / alds1_1_a_insertion_sort.rb
Last active October 12, 2015 05:43
『プログラミングコンテスト攻略のためのアルゴリズムとデータ構造』3章
# ALDS1_1_A Insertion Sort
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
def insertionSort(a, n)
puts a.join(" ")
(1..n-1).each do |i|
v = a[i]
j = i - 1
while j >= 0 and a[j] > v
a[j+1] = a[j]
@whatalnk
whatalnk / srm645_div2_easy_BacteriesColony.py
Last active October 13, 2015 04:00
TopCoder SRM 645 Div2
# SRM #645 Div2 Easy
class BacteriesColony():
def performTheExperiment(self, c):
while True:
diff = [0] * len(c)
for i in range(1, len(c)-1):
if c[i] > c[i-1] and c[i] > c[i+1]:
diff[i] = -1
elif c[i] < c[i-1] and c[i] < c[i+1]:
diff[i] = 1
# SRM 646 Div2 Easy
class TheConsecutiveIntegersDivTwo():
def find(self, numbers, k):
if k == 1:
return 0
else:
n_sorted = sorted(numbers)
n_diff = [n_sorted[i+1] - n_sorted[i] for i in range(len(numbers)-1)]
return min(n_diff) - 1
@whatalnk
whatalnk / srm647_div2_easy_PeacefulLine.py
Created October 13, 2015 11:58
TopCoder SRM 647 Div2
# SRM 647 Div2 Easy
# http://community.topcoder.com/stat?c=problem_statement&pm=13632
class PeacefulLine():
def makeLine(self, x):
d = {}
for i in x:
if i in d.keys():
d[i] += 1
else:
@whatalnk
whatalnk / srm648_div2_easy_KitayutaMart2.py
Created October 14, 2015 04:09
TopCoder SRM 648 Div2
# SRM 648 Div2 Easy
#http://community.topcoder.com/stat?c=problem_statement&pm=13650
class KitayutaMart2():
def numBought(self, k, t):
n = 1
ksum = k
while True:
if ksum == t:
return n
n += 1
@whatalnk
whatalnk / srm671_div2_easy_BearPaints.py
Last active October 20, 2015 11:47
TopCoder SRM 671 Div2
# SRM 671 Div2 Easy
# [Very short Editorial of SRM #671 - Codeforces](http://codeforces.com/blog/entry/20939)
class BearPaints():
def maxArea(self, w, h, m):
area = 1
for i in range(1,w+1):
area = max(area, i * min(m/i, h))
return area
@whatalnk
whatalnk / srm672_div2_a_SetPartialOrder.py
Last active October 22, 2015 05:45
TopCoder SRM672 Div2
# SRM 672 Div2 Easy
class SetPartialOrder():
def compareSets(self, a, b):
seta = set(a)
setb = set(b)
if seta == setb:
return "EQUAL"
elif seta.issubset(setb):
return "LESS"
elif setb.issubset(seta):