Submission #14400598


Source Code Expand

Copy
class Range
  def &(other)
    if last <= other.first || other.last <= first
      nil
    else
      a = [first, other.first].max
      b = [last, other.last].min
      a...b
    end
  end
end

# a = 1..10
# b = 5..15
# c = 10..20
# p a & b
# p a & c
# p c & b

c,d = gets.split.map(&:to_i)
cd = c...d
s = 140
t = 170
q = []

while s <= d
  q << (s...t)
  s *= 2
  t *= 2
end

ans = q.map{|r|r & cd}
  .compact
  .map(&:size)
  .inject(0,:+)

p ans

Submission Info

Submission Time
Task A - Feel the Beat
User tamura2004
Language Ruby (2.3.3)
Score 300
Code Size 485 Byte
Status
Exec Time 7 ms
Memory 1788 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 a01, a02, a03
All 300 / 300 a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15
Case Name Status Exec Time Memory
a01 7 ms 1788 KB
a02 7 ms 1788 KB
a03 7 ms 1788 KB
b04 7 ms 1788 KB
b05 7 ms 1788 KB
b06 7 ms 1788 KB
b07 7 ms 1788 KB
b08 7 ms 1788 KB
b09 7 ms 1788 KB
b10 7 ms 1788 KB
b11 7 ms 1788 KB
b12 7 ms 1788 KB
b13 7 ms 1788 KB
b14 7 ms 1788 KB
b15 7 ms 1788 KB