Created
April 22, 2017 08:14
-
-
Save whatalnk/f89974b683570f394ca500b3a932a6b1 to your computer and use it in GitHub Desktop.
Codeforces #410 Div2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = gets.chomp | |
n = s.length | |
ret = 0 | |
if n == 1 then | |
puts "YES" | |
exit | |
elsif n.odd? then | |
((n - 1) / 2).times do |i| | |
if s[i] != s[n - 1 - i] then | |
ret += 1 | |
end | |
end | |
if ret <= 1 then | |
puts "YES" | |
else | |
puts "NO" | |
end | |
else | |
(n / 2).times do |i| | |
if s[i] != s[n - 1 - i] then | |
ret += 1 | |
end | |
end | |
if ret == 1 then | |
puts "YES" | |
else | |
puts "NO" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# WA | |
n = gets.chomp.to_i | |
a = [] | |
h = Hash.new{|hash, key| hash[key] = Array.new()} | |
n.times do | |
s = gets.chomp | |
a << s | |
end | |
nn = a[0].length | |
a.each do |s| | |
nn.times do |i| | |
ss = s[i...nn] + s[0...i] | |
h[ss] << i | |
end | |
end | |
if h.size != nn then | |
puts -1 | |
else | |
puts h.values.map{|v| v.inject(:+)}.min | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment