Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active October 30, 2016 02:56
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/281dbac506e05b8eb8eea5ab34032b34 to your computer and use it in GitHub Desktop.
Save whatalnk/281dbac506e05b8eb8eea5ab34032b34 to your computer and use it in GitHub Desktop.
AtCoder AGC #006 [Ruby]
n = gets.chomp.to_i
s = gets.chomp
t = gets.chomp
ncommon = 0
n.downto(1) do |i|
if s[(n - i)..(n - 1)] == t[0..(i - 1)] then
ncommon = i
break
end
end
puts (n - ncommon) * 2 + ncommon
n, x = gets.chomp.split(" ").map(&:to_i)
if x == 1 || x == 2*n-1 then
puts "No"
elsif n == 2 then
puts "Yes"
puts [1,2,3]
else
if x == 2 then
a2 = [x+1, x, x-1, x+2]
else
a2 = [x-1, x, x+1, x-2]
end
puts "Yes"
a1 = (1..(2*n-1)).to_a
a1 -= a2
puts a1[0..(n-3)] + a2 + a1[(n-2)..(2*n-2-4)]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment