Submission #4074830


Source Code Expand

N = int(input())
if N == 0:
    print(0)
    exit()
L = []
M = []

def bit_range(bit_length,maximum=0,minimal=0):
    for i in range(bit_length-1,-1,-1):
        if i % 2 == 0:
            maximum += pow(2,i)
        else:
            minimal += pow(-2,i)
    L.append(minimal)
    M.append(maximum)

for i in range(1,41):
    bit_range(i)

identify = []
for i in range(40):
    if i == 0:
        ap_list = [L[0],M[0]]
    elif i % 2 == 1:
        ap_list = [L[i],L[i-1]]
    elif i % 2 == 0:
        ap_list = [M[i-1],M[i]]
    identify.append(ap_list)

bit = [0]*40
for i in range(39,-1,-1):
    left = identify[i][0]
    right = identify[i][1]
    if i % 2 == 0 and left < N <= right:
        bit[39-i] = 1
        N -= pow(-2,i)
    elif i % 2 == 1 and left <= N < right:
        bit[39-i] = 1
        N -= pow(-2,i)

ans = "".join(str(e) for e in bit).lstrip("0")
print(ans)

Submission Info

Submission Time
Task C - Base -2 Number
User pynomi
Language Python (3.4.3)
Score 300
Code Size 921 Byte
Status AC
Exec Time 19 ms
Memory 3064 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 18
Set Name Test Cases
Sample sample_01, sample_02, sample_03
All 0_small0, 0_small1, 0_small2, 0_small3, 0_small4, 1_large0, 1_large1, 1_large2, 1_large3, 1_large4, 1_large5, 1_large6, 1_large7, 2_max0, 2_max1, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_small0 AC 18 ms 3064 KB
0_small1 AC 18 ms 3064 KB
0_small2 AC 18 ms 3064 KB
0_small3 AC 18 ms 3064 KB
0_small4 AC 19 ms 3064 KB
1_large0 AC 18 ms 3064 KB
1_large1 AC 18 ms 3064 KB
1_large2 AC 18 ms 3064 KB
1_large3 AC 18 ms 3064 KB
1_large4 AC 18 ms 3064 KB
1_large5 AC 18 ms 3064 KB
1_large6 AC 18 ms 3064 KB
1_large7 AC 18 ms 3064 KB
2_max0 AC 19 ms 3064 KB
2_max1 AC 18 ms 3064 KB
sample_01 AC 19 ms 3064 KB
sample_02 AC 18 ms 3064 KB
sample_03 AC 18 ms 3064 KB