Last active
January 31, 2016 04:37
-
-
Save whatalnk/d8a831ce8b9838a66c03 to your computer and use it in GitHub Desktop.
DDPC 2016 予選
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 = "DiscoPresentsDiscoveryChannelProgrammingContest2016" | |
w = gets.chomp.to_i | |
n = s.length | |
a = n / w | |
b = n % w | |
i = 0 | |
a.times do | |
puts s[i...(i + w)] | |
i += w | |
end | |
if b > 0 then | |
puts s[(n - b)...n] | |
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
n = gets.chomp.to_i | |
a = gets.chomp.split(" ").map(&:to_i) | |
h = Hash.new{|h,k| h[k] = []} | |
n.times do |i| | |
h[a[i]] << i | |
end | |
pos = 0 | |
res = 1 | |
h.keys.sort.each do |k| | |
v = h[k] | |
if v.first < pos && v.last > pos then | |
res += 1 | |
pos = (v.select{|x| x < pos}).last | |
elsif v.last < pos then | |
res += 1 | |
pos = v.last | |
else | |
pos = v.last | |
end | |
end | |
res -= 1 if pos == 0 | |
puts res | |
# ref: Submission #624244 |
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 | |
k = gets.chomp.to_i | |
def f(s, k) | |
if k <= 0 then | |
return [s] | |
end | |
res = [] | |
(0...(s.length)).each do |i| | |
res << s[0...i] + s[(i+1)..-1] | |
res << s[0...i] + "a" + s[(i + 1)..-1] | |
end | |
res << s[0...-1] | |
res << "a" + s | |
rr = [] | |
res.each do |r| | |
rr += f(r, k-1) | |
end | |
return rr | |
end | |
if s.length > 10 then | |
puts -1 | |
exit | |
end | |
ans = f(s, k).min | |
if ans == "" then | |
ans = "a" | |
end | |
puts ans | |
# ref: Submission #625127 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment