Skip to content

Instantly share code, notes, and snippets.

@whatalnk
whatalnk / cf328_div2_a_PawnChess.rb
Last active November 5, 2015 16:38
Codeforces #328 Div2
# [Problem - 592A - Codeforces](http://codeforces.com/problemset/problem/592/A)
field = []
while line = gets
field << line.chomp.split("")
end
field = field.transpose
stepA = []
stepB = []
field.each do |r|
a = r.rindex("W")
@whatalnk
whatalnk / cf329-div2-a-2Char.rb
Last active November 5, 2015 16:39
Codeforces #329 Div2
# [Problem - A - Codeforces](http://codeforces.com/contest/593/problem/A)
n = gets.chomp.to_i
d = Hash.new(0)
n.times do
word = gets.chomp
k = word.split("").uniq.sort
v = word.length
d[k] += v if k.length <= 2
end
res = 0
@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 / CodeFes20115-QualB-a-DoubleString.rb.rb
Last active November 7, 2015 17:19
Code Festival 2015 予選 B
# [A: ダブル文字列/Double String - CODE FESTIVAL 2015 予選B | AtCoder](http://code-festival-2015-qualb.contest.atcoder.jp/tasks/codefestival_2015_qualB_a)
s = gets.chomp
puts s.split("").uniq.join("")*2
@whatalnk
whatalnk / getExampleCases.user.js
Last active November 9, 2015 02:27
AtCoderの入出力を取得
// ==UserScript==
// @name getExampleCases
// @namespace what_alnk
// @description AtCoderの入力例と出力例をコピーするボタンを設置する
// @include /^http://[0-9a-zA-Z]+\.contest\.atcoder\.jp/tasks/[A-D]/
// @version 1.2
// @grant none
// ==/UserScript==
// 通知許可確認
@whatalnk
whatalnk / cf330-div2-a.rb
Last active November 10, 2015 04:07
Codeforces #330 Div2
# [Problem - A - Codeforces](http://codeforces.com/contest/595/problem/A)
n, m = gets.chomp.split(" ").map(&:to_i)
ans = 0
n.times do |i|
rooms = gets.chomp.split(" ").map(&:to_i)
rooms.each_slice(2) do |a, b|
if (a == 1) or (b == 1) then
ans += 1
end
end
@whatalnk
whatalnk / Vagrantfile
Last active November 18, 2015 09:29
Vagrantfile for iRuby
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
$forbuild = <<SCRIPT
apt-get update -y
apt-get install -y git
@whatalnk
whatalnk / srm673-easy-BearSong.py
Last active November 19, 2015 05:55
TopCoder SRM 673 Div 2
from collections import defaultdict
class BearSong():
def countRareNotes(self, notes):
d = defaultdict(int)
for i in notes:
d[i] += 1
return(len([i for i in d.values() if i == 1]))
@whatalnk
whatalnk / cfEdu1-a-TrickySum.rb
Created November 19, 2015 10:39
Educational Codeforces Round 1
t = gets.chomp.to_i
t.times do
n = gets.chomp.to_i
power2 = []
snd = 1
i = 1
while snd <= n
power2 << snd
snd = 2**i
i += 1
n = gets.chomp.to_i
coors = []
n.times do
coors << gets.chomp.split(" ").map(&:to_i)
end
if n == 3 or n == 4 then
coors_t = coors.transpose
dx = coors_t[0].max - coors_t[0].min
dy = coors_t[1].max - coors_t[1].min
puts dx * dy