Skip to content

Instantly share code, notes, and snippets.

@whatalnk
whatalnk / abc122-c.rb
Created Apr 18, 2019
AtCoder ABC 122 C - GeT AC
View abc122-c.rb
n, q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
ss = Array.new(n-1, 0)
(n-1).times do |i|
if s[i..(i+1)] == "AC"
ss[i] = 1
end
end
sss = Array.new(n, 0)
@whatalnk
whatalnk / abc118-c.rb
Created Apr 18, 2019
AtCoder ABC #118 C - Monsters Battle Royale
View abc118-c.rb
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ret = a[0].gcd(a[1])
a.each do |x|
ret = ret.gcd(x)
end
puts ret
@whatalnk
whatalnk / abc117-c.rb
Created Apr 18, 2019
AtCoder ABC #117 C - Streamline
View abc117-c.rb
n, m = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map(&:to_i).sort
y = Array.new(m - 1, 0)
(m - 1).times do |i|
y[i] = x[i + 1] - x[i]
end
y.sort!
@whatalnk
whatalnk / abc116-c.rb
Created Apr 18, 2019
AtCoder ABC #116 - C Grand Garden
View abc116-c.rb
n = gets.chomp.to_i
h = gets.chomp.split(" ").map(&:to_i)
ans = 0
cnt = 0
while true
n.times do |i|
if h[i] > 0
cnt += 1
h[i] -= 1
else
@whatalnk
whatalnk / agc031-a.rb
Created Apr 18, 2019
AtCoder AGC #031 A - Colorful Subsequence
View agc031-a.rb
n = gets.chomp.to_i
s = gets.chomp
h = Hash.new(0)
n.times do |i|
h[s[i]] += 1
end
MOD = 10**9 + 7
ans = 1
h.each do |k, v|
@whatalnk
whatalnk / exawizards2019-b.rb
Created Apr 17, 2019
Exawizards 2019 B - Red or Blue
View exawizards2019-b.rb
n = gets.chomp.to_i
s = gets.chomp
r = 0
b = 0
n.times do |i|
if s[i] == "R"
r += 1
else
b += 1
end
@whatalnk
whatalnk / abc122-b.rb
Created Apr 17, 2019
AtCoder ABC #122 B - ATCoder
View abc122-b.rb
s = gets.chomp
n = s.length
base = ["A", "G", "C", "T"]
ans = 0
cur = 0
n.times do |i|
if base.include?(s[i])
cur += 1
else
ans = [ans, cur].max
@whatalnk
whatalnk / exawizards2019-a.rb
Created Apr 15, 2019
Exawizards 2019 A - Regular Triangle
View exawizards2019-a.rb
a, b, c = gets.chomp.split(" ").map(&:to_i)
if a == b && b == c
puts "Yes"
else
puts "No"
end
@whatalnk
whatalnk / abc122-a.rb
Created Apr 15, 2019
AtCoder ABC #122 A - Double Helix
View abc122-a.rb
b = gets.chomp
base = {
"A" => "T",
"T" => "A",
"G" => "C",
"C" => "G"
}
puts base[b]
@whatalnk
whatalnk / cf551-div2-c.rb
Created Apr 14, 2019
Codeforces #551 Div2 C - Serval and Parenthesis Sequence
View cf551-div2-c.rb
n = gets.chomp.to_i
s = gets.chomp
a = 0
b = 0
n.times do |i|
if s[i] == "("
a += 1
elsif s[i] == ")"
b += 1
end
You can’t perform that action at this time.