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
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 |
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
# 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 |
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
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 |
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
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' |
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
# 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 |
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
# 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 |
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
# 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 |
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
# 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 |
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
# 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 |
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
# 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 |
OlderNewer