Created
June 4, 2017 07:49
-
-
Save whatalnk/5fd5e30384f1d40667dd9bf3eb2afdd4 to your computer and use it in GitHub Desktop.
AtCoder ARC #075 / ABC #063
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
a, b = gets.chomp.split(" ").map(&:to_i) | |
if a + b >= 10 then | |
puts "error" | |
else | |
puts a + b | |
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
s = gets.chomp.split("") | |
n = s.length | |
if s.uniq.length == n then | |
puts "yes" | |
else | |
puts "no" | |
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 | |
s = [] | |
ssum = 0 | |
n.times do | |
x = gets.chomp.to_i | |
ssum += x | |
s << x | |
end | |
s.sort! | |
if ssum % 10 == 0 then | |
while x = s.shift | |
if x % 10 != 0 then | |
puts ssum - x | |
exit | |
end | |
end | |
puts 0 | |
else | |
puts ssum | |
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, $a, $b = gets.chomp.split(" ").map(&:to_i) | |
$h = [] | |
n.times do | |
$h << gets.chomp.to_f | |
end | |
def enough(i) | |
ret = $h.map{|x| ([(x - i * $b), 0].max / ($a - $b)).ceil}.inject(:+) | |
return ret <= i | |
end | |
puts (1..$h.max.to_i).bsearch{|i| enough(i)} |
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
class BIT | |
attr_reader :bit | |
def initialize(n) | |
@n = n | |
@bit = Array.new(@n + 1, 0) | |
end | |
def sum(i) | |
s = 0 | |
while i > 0 | |
s += @bit[i] | |
i -= i & -i | |
end | |
return s | |
end | |
def add(i, x) | |
i += 1 | |
while i <= @n | |
@bit[i] += x | |
i += i & -i | |
end | |
end | |
end | |
n, k = gets.chomp.split(" ").map(&:to_i) | |
a = [0] | |
a += readlines.map{|x| x.chomp.to_i - k} | |
b = [0] | |
n.times do |i| | |
b << b[i] + a[i+1] | |
end | |
b_s = b.sort | |
c = b.map{|e| b_s.bsearch_index{|x| x >= e}} | |
bit = BIT.new(n+1) | |
ans = 0 | |
c.each do |i| | |
ans += bit.sum(i+1) | |
bit.add(i, 1) | |
end | |
puts ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment