Instantly share code, notes, and snippets.

View abc071-d.rb
n = gets.chomp.to_i
s1 = gets.chomp
s2 = gets.chomp
MOD = 10**9 + 7
ans = 1
left = ""
right = ""
i = 0
loop do
View abc110-d.rb
require 'prime'
MAX = 10**6
MOD = 10**9 + 7
@fac = []
@faci = []
@inv = []
@fac[0] = @fac[1] = 1
View abc110-a.rb
a, b, c = gets.chomp.split(" ").map(&:to_i).sort
puts c * 10 + b + a
View abc110-b.rb
n, m, x, y = gets.chomp.split(" ").map(&:to_i)
xx = gets.chomp.split(" ").map(&:to_i)
yy = gets.chomp.split(" ").map(&:to_i)
xxmax = [xx.max, x].max
yymin = [yy.min, y].min
if xxmax < yymin
puts "No War"
View abc110-c.rb
s = gets.chomp
t = gets.chomp
n = s.length
sh = Hash.new()
th = Hash.new()
("a".."z").each do |c|
x = c.ord
sh[x] = -1
View abc051-d.rb
# ABC051 D
INF = 10**6
n, m = gets.chomp.split(" ").map(&:to_i)
cost = Array.new(n + 1){Array.new(n + 1, INF)}
(n+1).times do |i|
cost[i][i] = 0
end
m.times do
a, b, c = gets.chomp.split(" ").map(&:to_i)
cost[a][b] = c
View abc049-d.rb
# ABC049 D
n, k, l = gets.chomp.split(" ").map(&:to_i)
roads = Array.new(n+1){Array.new()}
rails = Array.new(n+1){Array.new()}
k.times do
p_, q_ = gets.chomp.split(" ").map(&:to_i)
roads[p_] << q_
roads[q_] << p_
end
View abc047-d.rb
# ABC047 D
n, t = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
h = Hash.new(0)
amin = a[0]
bmax = a[1] - a[0]
(n - 1).times do |i|
amin = [amin, a[i]].min
b = a[i+1] - amin
bmax = [b, bmax].max
View abc045-d.rb
# ABC045 D
h, w, n = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
n.times do
a, b = gets.chomp.split(" ").map(&:to_i)
a -= 1
b -= 1
(a-2).upto(a) do |i|
(b-2).upto(b) do |j|
if i >= 0 && i + 2 < h && j >= 0 && j + 2 < w
View agc027-a.rb
# AGC027 A
n, x = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort
s = a.inject(:+)
if s == x
puts n
elsif s < x
puts n - 1