Skip to content

Instantly share code, notes, and snippets.

View ninoseki's full-sized avatar

Manabu Niseki ninoseki

View GitHub Profile
@ninoseki
ninoseki / gist:2828283
Created May 29, 2012 13:07
Codeforce121(Div2.B)
n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|e| e.to_i}
days = 0
loop do
break if a[0] == 0 or a[-1] == 0
bang = false
for i in 1 .. (n - 2) do
bang = true if a[i] == 0 and a[i + 1] == 0
# codeforce#122(Div2.A)
n, k = gets.chomp.split(" ").map{|e| e.to_i}
0.upto(n) do |i|
if (i * 2 + 5 * (n - i)) >= k and (i * 2 + 3 * (n - i)) <= k
puts i
break
end
end
@ninoseki
ninoseki / gist:3115316
Created July 15, 2012 06:15
Codefoces#129(Dv2.A)
n = gets.chomp.to_i
times = gets.chomp.split(" ").map{|e| e.to_i}
min = times.min
if times.count(min) == 1
puts times.index(min) + 1
else
puts "Still Rozdil"
end
@ninoseki
ninoseki / 285-div2-a.rb
Created January 14, 2015 22:24
Codeforces#285 Div2-A
def max_score(p, t)
[3 * p / 10, p - (p / 250 * t)].max
end
a, b, c, d = gets.chomp.split.map(&:to_i)
diff = max_score(a, c) - max_score(b, d)
case
when diff > 0
puts 'Misha'
@ninoseki
ninoseki / 285-div2-b.rb
Last active August 29, 2015 14:13
Codeforces#285 Div2-B
# http://codeforces.com/contest/501/problem/B
q = gets.chomp.to_i
queries = []
q.times { queries << gets.chomp.split }
hash = Hash.new { |h, k| h[k] = [] }
queries.each do |old_name, new_name|
root = hash.keys.select { |key| hash[key].last == old_name }.first
if root.nil?
hash[old_name] << new_name
@ninoseki
ninoseki / 290-div2-a.rb
Last active August 29, 2015 14:14
Codeforces#290 Div2-A
# http://codeforces.com/contest/510/problem/A
class Snake
def initialize(n, m)
@n, @m = n, m
end
def draw
rows.each { |row| puts row.join }
end
@ninoseki
ninoseki / 295-div2-a.rb
Last active August 29, 2015 14:16
Codeforces#295 Div2-A
# http://codeforces.com/contest/520/problem/A
class Pangram
def initialize(s)
@chars = s.downcase.chars
end
def is_pangram?
@chars.uniq.length >= ('a'..'z').to_a.length
end
@ninoseki
ninoseki / gist:6161d08436ba1faa12c8
Created March 7, 2015 23:30
Codeforces#294 Div2-A
# http://codeforces.com/contest/519/problem/A
class Board
WEIGHTS = { q: 9, r: 5, b: 3, n: 3, p: 1 }
def initialize(lines)
@pieces = lines.join.chars
end
def which_to_win?
case
@ninoseki
ninoseki / gist:04ee494239d2ec7b1e08
Created March 8, 2015 00:12
Codeforces#294 Div2-B
# http://codeforces.com/contest/519/problem/B
class Errors
def initialize(a, b, c)
@errors = [a, b, c].map(&:sort)
end
def corrected_error(n)
(0..@errors[n - 1].length).each do |idx|
return @errors[n - 1][idx] if @errors[n][idx] != @errors[n - 1][idx]
end
@ninoseki
ninoseki / gist:5b81903b941580200717
Created March 14, 2015 21:08
Codeforces#291 Div2-A
# http://codeforces.com/contest/514/problem/A
digits = gets.chomp.chars.map(&:to_i)
inverted = digits.map.with_index do |n, idx|
case idx
when 0
(9 - n) < n && n != 9 ? 9 - n : n
else
(9 - n) < n ? 9 - n : n
end