Submission #3743455


Source Code Expand

Copy
N, X = gets.split.map(&:to_i)

Len = [1]
Pat = [1]

(1..N).each do |i|
    Len[i] = Len[i-1] * 2 + 3
    Pat[i] = Pat[i-1] * 2 + 1
end

def rec(n, x)
    return 1 if n == 0
    ans = 0
    x -= 1
    if x > 0
        if x >= Len[n-1]
            ans += Pat[n-1]
            x -= Len[n-1]
        else
            ans += rec(n-1, x)
            return ans
        end
    end
    if x > 0
        ans += 1
        x -= 1
    end
    if x > 0
        if x >= Len[n-1]
            ans += Pat[n-1]
            x -= Len[n-1]
        else
            ans += rec(n-1, x)
            return ans
        end
    end
    ans
end

puts rec(N, X)

Submission Info

Submission Time
Task D - Christmas
User betrue12
Language Ruby (2.3.3)
Score 400
Code Size 673 Byte
Status
Exec Time 7 ms
Memory 1788 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 a01, a02, a03
All 400 / 400 a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16
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
b16 7 ms 1788 KB