Skip to content

Instantly share code, notes, and snippets.

@whatalnk
whatalnk / a.rb
Created September 27, 2015 03:44
Code Festival 2015 Qual A
n = gets.chomp
puts n[0..-5] + "2015"
@whatalnk
whatalnk / arc001-a.rb
Last active December 20, 2015 05:54
ARC#001
n = gets.chomp.to_i
c = gets.chomp.split("").map(&:to_i)
ans = [1,2,3,4]
cnt = []
ans.each do |a|
cnt << c.count(a)
end
print cnt.max, " ", cnt.min, "\n"
@whatalnk
whatalnk / srm669-div2-a-LiveConcert.py
Last active January 10, 2016 04:03
TopCoder SRM 669 Div2
class LiveConcert():
def maxHappiness(self, h, s):
dict = {}
m = len(h)
for (key, val) in zip(s, h):
if dict.has_key(key):
dict[key].append(val)
else:
dict[key] = [val]
happiness = 0
@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(" ")
@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)))
# 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 / cf325_div2_A_alena_schedule.rb
Created October 12, 2015 15:24
Codeforces #325 Div2
# #325 Div2 A. Alena's Schedule
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
lesson = 0
rest = 0
a.each do |i|
if i == 1 then
if rest == 1 and lesson > 0 then
lesson += 1
end
@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