Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created November 4, 2017 16:10
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/7c16ded52cc195a3283859246797ca60 to your computer and use it in GitHub Desktop.
Save whatalnk/7c16ded52cc195a3283859246797ca60 to your computer and use it in GitHub Desktop.
AtCoder ABC #077
s1 = gets.chomp
s2 = gets.chomp
if s1 == s2.reverse && s2 == s1.reverse
puts "YES"
else
puts "NO"
end
n = gets.chomp.to_i
a = Math.sqrt(n).to_i
puts a**2
N = gets.chomp.to_i
A = gets.chomp.split(" ").map(&:to_i).sort
B = gets.chomp.split(" ").map(&:to_i).sort
C = gets.chomp.split(" ").map(&:to_i).sort
memo = Array.new(N, 0)
N.times do |ib|
ic = C.bsearch_index{|x| x > B[ib]}
next if ic.nil?
memo[ib] = (N - ic)
end
(N-1).downto(1) do |i|
memo[i - 1] += memo[i]
end
ans = 0
A.each do |a|
ib = B.bsearch_index{|x| x > a}
next if ib.nil?
ans += memo[ib]
end
puts ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment