Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created May 20, 2017 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/aa8f6518da295158ba44cc8e46f8c14f to your computer and use it in GitHub Desktop.
Save whatalnk/aa8f6518da295158ba44cc8e46f8c14f to your computer and use it in GitHub Desktop.
AtCoder ABC #062
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
g3 = [2]
x, y = gets.chomp.split(" ").map(&:to_i)
if (g1.include?(x) && g1.include?(y)) || (g2.include?(x) && g2.include?(y)) || (g3.include?(x) && g3.include?(y)) then
puts "Yes"
else
puts "No"
end
H, W = gets.chomp.split(" ").map(&:to_i)
puts "#" * (W + 2)
H.times do
row = "#"
row += gets.chomp
row += "#"
puts row
end
puts "#" * (W + 2)
H, W = gets.chomp.split(" ").map(&:to_i)
if H % 3 == 0 || W % 3 == 0 then
puts 0
exit
end
ret = H * W
short, long = [H, W].minmax
long.times do |i|
a = (i + 1) * short
b = (short / 2) * (long - (i + 1))
c = (short - short / 2) * (long - (i + 1))
if a > 0 && b > 0 && c > 0 then
ret = [([a, b, c].max - [a, b, c].min), ret].min
end
b = ((long - i) / 2) * short
c = (long - (i + 1) - ((long - i) / 2)) * short
if b > 0 && c > 0 then
ret = [([a, b, c].max - [a, b, c].min), ret].min
end
end
short, long = long, short
long.times do |i|
a = (i + 1) * short
b = (short / 2) * (long - (i + 1))
c = (short - short / 2) * (long - (i + 1))
if b > 0 && c > 0 then
ret = [([a, b, c].max - [a, b, c].min), ret].min
end
b = ((long - i) / 2) * short
c = (long - (i + 1) - ((long - i) / 2)) * short
if a > 0 && b > 0 && c > 0 then
ret = [([a, b, c].max - [a, b, c].min), ret].min
end
end
puts ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment