Skip to content

Instantly share code, notes, and snippets.

@sorah

sorah/a.rb Secret

Created December 16, 2011 08:25
Show Gist options
  • Save sorah/c08760759dd483f48aab to your computer and use it in GitHub Desktop.
Save sorah/c08760759dd483f48aab to your computer and use it in GitHub Desktop.
Codeforces Beta Round #98 (Div. 2)
chrs= STDIN.gets.chomp.chars
i = 0
c = 0
last = nil
chrs.each do |type|
if last != type || c >= 5
i += 1
c = 0
end
c += 1
last = type
end
p i
n = STDIN.gets.chomp.to_i
ary = STDIN.gets.chomp.chars.map(&:to_i)[0...n]
uni = ary.uniq
wrong = ary.size - uni.size
wrong += uni.select{|x| x > n }.size
wrong += uni.select{|x| x < 1 }.size
p wrong
# Time limit exceeded on test 9
n = STDIN.gets.chomp.to_i
events = n.times.map { STDIN.gets.chomp.split(' ').map(&:to_i) }
answer = []
events.each do |event|
ae = events.select{|e| event[0] < e[0] && e[1] < event[1] }
ae.each do |ano|
answer << events.index(ano)
end
end
p answer.uniq.size
# Time limit exceeded on test 13 (practice)
def is_good(str)
ary = str.kind_of?(Array) ? str : str.split('')
vowels = ary.select{|x| ["a","i","u","e","o"].include?(x.downcase) }.size
consonants = ary.size-vowels
vowels <= consonants*2
end
def subst(str,len)
i = 0
while (_=str[i,len]).size == len
yield _
i += 1
end
end
def check(str)
ary = str.kind_of?(Array) ? str : str.split('')
len = ary.size
flag = false
answers = 0
while len > 0
subst(ary,len) do |sub|
answers += 1 if (flag=is_good(sub))
end
break if flag
len -= 1
end
[len, answers]
end
ans = check(STDIN.gets.chomp)
puts ans.all?{|x| x.zero?} ? "No solution" : ans.join(' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment