Problem:


Score : 300 points

Problem Statement

Given an integer N, find the base -2 representation of N.

Here, S is the base -2 representation of N when the following are all satisfied:

S is a string consisting of 0 and 1.

Unless S = 0, the initial character of S is 1.

Let S = S_k S_{k-1} ... S_0, then S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S_k \times (-2)^k = N.

It can be proved that, for any integer M, the base -2 representation of M is uniquely determined.

Constraints

Every value in input is integer.

-10^9 \leq N \leq 10^9

Input

Input is given from Standard Input in the following format:

N

Output

Print the base -2 representation of N.

Sample Input 1

-9

Sample Output 1

1011

As (-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9, 1011 is the base -2 representation of -9.

Sample Input 2

123456789

Sample Output 2

11000101011001101110100010101

Sample Input 3

0

Sample Output 3

0



Sample input:
-9


Sample output:
1011

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, log

N = int(input())

# O(logN)
def base10to(n, b):
    if n // b > 0:
        return base10to(n // b, b) + str(n % b)
    else:
        return str(n % b)

def calc_base_for_pos_N(N):
    S_base4 = base10to(N, 4) # str

    S_raw = list(map(int, tuple(''.join([digit + '0' for digit in S_base4])[:-1])))[::-1]

    # transformation. takes O(logN)
    position = 0
    while position <= len(S_raw) - 3:
        digit = S_raw[position]
        # -2のところだったら
        if position % 2 == 1:
            position += 1
            continue
        if digit in {0, 1}:
            position += 1
            continue
        elif digit == 2:
            S_raw[position] = 0
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        elif digit == 3:
            S_raw[position] = 1
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        else: #4
            S_raw[position] = 0
            S_raw[position + 2] += 1
        position += 2

    # postprocessing
    if S_raw[-1] == 2:
        S_raw[-1] = 0
        S_raw += [1, 1]
    elif S_raw[-1] == 3:
        S_raw[-1] = 1
        S_raw += [1, 1]
    elif S_raw[-1] == 4:
        S_raw[-1] = 0
        S_raw += [0, 1]

    S = ''.join([str(digit) for digit in S_raw])[::-1]
    return S

if N >= 0:
    print(calc_base_for_pos_N(N))
else:
    pos_N = abs(N)
    pos_S = list(map(int, list(calc_base_for_pos_N(pos_N))))
    pos_S = pos_S[::-1]
    shifted_S = [0] + pos_S
    pos_S = pos_S + [0]
    assert len(pos_S) == len(shifted_S)
    S_raw = [shifted_S[i] + pos_S[i] for i in range(len(pos_S))]
    position = 0
    while position <= len(S_raw) - 3:
        digit = S_raw[position]
        if digit in {0, 1}:
            position += 1
            continue
        elif digit == 2:
            S_raw[position] = 0
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        elif digit == 3:
            S_raw[position] = 1
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        else: #4
            S_raw[position] = 0
            S_raw[position + 2] = 1
        position += 1
    # postprocessing
    last_two_digits = S_raw[-2:]
    if last_two_digits == [2, 1]:
        S_raw = S_raw[:-2]
    elif last_two_digits == [3, 1]:
        S_raw[-2:] = [1]
    elif last_two_digits == [1, 2]:
        S_raw[-2:] = [1, 0, 1, 1]
    elif last_two_digits == [2, 2]:
        S_raw[-2:] = [0, 1]
    elif last_two_digits == [3, 2]:
        S_raw[-2:] = [1, 1]
    elif last_two_digits == [4, 1]:
        S_raw[-2:] = [0, 0, 1]
    elif last_two_digits == [4, 2]:
        S_raw = S_raw[:-2]
    S = ''.join([str(digit) for digit in S_raw])[::-1]
    print(S)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil, log

N = int(input())

# O(logN)
def base10to(n, b):
    if n // b > 0:
        return base10to(n // b, b) + str(n % b)
    else:
        return str(n % b)

def calc_base_for_pos_N(N):
    S_base4 = base10to(N, 4) # str

    S_raw = list(map(int, tuple(''.join([digit + '0' for digit in S_base4])[:-1])))[::-1]

    # transformation. takes O(logN)
    position = 0
    while position <= len(S_raw) - 3:
        digit = S_raw[position]
        # -2のところだったら
        if position % 2 == 1:
            position += 1
            continue
        if digit in {0, 1}:
            position += 1
            continue
        elif digit == 2:
            S_raw[position] = 0
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        elif digit == 3:
            S_raw[position] = 1
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        else: #4
            S_raw[position] = 0
            S_raw[position + 2] += 1
        position += 2

    # postprocessing
    if S_raw[-1] == 2:
        S_raw[-1] = 0
        S_raw += [1, 1]
    elif S_raw[-1] == 3:
        S_raw[-1] = 1
        S_raw += [1, 1]
    elif S_raw[-1] == 4:
        S_raw[-1] = 0
        S_raw += [0, 1]

    S = ''.join([str(digit) for digit in S_raw])[::-1]
    return S

if N >= 0:
    print(calc_base_for_pos_N(N))
else:
    pos_N = abs(N)
    pos_S = list(map(int, list(calc_base_for_pos_N(pos_N))))
    print(pos_S)
    pos_S = pos_S[::-1]
    shifted_S = [0] + pos_S
    pos_S = pos_S + [0]
    assert len(pos_S) == len(shifted_S)
    S_raw = [shifted_S[i] + pos_S[i] for i in range(len(pos_S))]
    position = 0
    while position <= len(S_raw) - 3:
        digit = S_raw[position]
        if digit in {0, 1}:
            position += 1
            continue
        elif digit == 2:
            S_raw[position] = 0
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        elif digit == 3:
            S_raw[position] = 1
            S_raw[position + 1] += 1
            S_raw[position + 2] += 1
        else: #4
            S_raw[position] = 0
            S_raw[position + 2] = 1
        position += 1
    # postprocessing
    last_two_digits = S_raw[-2:]
    if last_two_digits == [2, 1]:
        S_raw = S_raw[:-2]
    elif last_two_digits == [3, 1]:
        S_raw[-2:] = [1]
    elif last_two_digits == [1, 2]:
        S_raw[-2:] = [1, 0, 1, 1]
    elif last_two_digits == [2, 2]:
        S_raw[-2:] = [0, 1]
    elif last_two_digits == [3, 2]:
        S_raw[-2:] = [1, 1]
    elif last_two_digits == [4, 1]:
        S_raw[-2:] = [0, 0, 1]
    elif last_two_digits == [4, 2]:
        S_raw = S_raw[:-2]
    S = ''.join([str(digit) for digit in S_raw])[::-1]
    print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = ""
while N != 0 :
    if N % (-2) == 0 :
        S = "0"+S
    else :
        S = "1"+S
        N -= 1
    N = N / 2
if len(S) != 0 :
    print(S)
else :
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

if N == 0:
    print (0)
    exit(0)

flag = N < 0
N = N - 1
ans = ''

for i in range(100,0,-1):
    if N == 0:
        break;
    if (flag and i % 2 == 0) or (not(flag) and i%2 == 1):
        if len(ans):
            ans = ans + '0'
        continue
    x = (-2) ** i
    if abs(N) >= abs(x):
        N = N - x
        ans = ans + '1'
    else:
        if len(ans):
            ans = ans + '0'
    
ans = ans + '1'
print (ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

if N == 0:
    print (0)
    exit(0)

flag = N < 0
N = N + 1
ans = ''
for i in range(100,0,-1):
    if N == 0:
        break;
    if (flag and i % 2 == 0) or (not(flag) and i%2 == 1):
        ans = ans + '0'
        continue
    x = (-2) ** i
    if abs(N) >= abs(x):
        N = N - x
        ans = ans + '1'
    else:
        ans = ans + '0'
    


print (ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = ""
while(N != 0):
    mod = N % (-2)
    if(mod != 0):
        ans = "1" + ans
    else:
        ans = "0" + ans
    N = (N+mod) // (-2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = ""

while N != 0:
    if N % 2 != 0:
        N -= 1
        ans = "1" + ans
    else:
        ans = "0" + ans
        N /= -2
    if ans == "":
        ans = "0"

print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
if a==0:
	print(0)
while a:
	b.append(a&1)
	a-=a&1
	a=int(a/-2)
print(''.join(map(str,b)))

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
if a==0:
	print(0)
while a:
	b.append(a&1)
	a=int((a-(a&1))/(-2))
print(''.join(map(str,b)))

Submission status: Wrong Answer

Solution code:
a=int(input())
b=[]
while a:
	print(str(a)+' '+str(a&1))
	b.append(a&1)
	a=int((a-(a&1))/(-2))
print(''.join(map(str,b)))

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = ""
if N == 0:
    ans = "0"
while N != 0:
    if N % 2 != 0:
        N -= 1
        ans = "1" + ans
    else:
        ans = "0" + ans
        N //= -2

print(int(ans))

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())
answer = ""

def kenzan(ans):
    val = 0
    ans.reverse()
    for i in range(len(ans)):
        val += answer[i]*(-2)**i
    return int(val)

i = 1

while(n != 0):
    if n % 2 == 0:
        answer = "0" + answer
    else:
        answer = "1" + answer
        n -= 1
    n /= 2
if answer == "":
    answer = 0
print(answer)
# print(kenzan(answer))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

if(N == 0):
    print(0)
    sys.exit()
elif(N < 0):
    mask = 1
    N = -1 * N
else:
    mask = 0
S = bin(N)[2:]

ans = ""

i = 0
up1 = 0
up2 = 0
for c in (reversed(S)):
    if((i + mask) % 2 == 0):
        if(up1 == 1 or up2 == 1):
            if(c == "0"):
                up2 = 0
                ans = "1" + ans
            else:
                up2 = 1
                ans = "0" + ans
        else:
            up2 = 0
            up1 = 0
            ans = c + ans
    else:
        if(up2 == 0):
            up1 = int(c)
            ans = c + ans
        else:
            up1 = 0
            if(c == "0"):
                ans = "1" + ans
            else:
                ans = "0" + ans

    # print(c, i, ans)
    i += 1

# print(up2, up1)
if(up2 == 1):
    ans = "11" + ans
elif(up1 == 1):
    ans = "1" + ans
print(ans)

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())
m=n
answer = []

def kenzan(ans):
    val = 0
    for i in range(len(ans)):
        val += answer[i]*(-2)**i
    return int(val)

i = 1
while(n != 0):
    # print(n)
    if n % (2**i) == 0:
        answer.append(0)
    else:
        answer.append(1)
        n = n-((-2)**(i-1))
    i += 1
answer.reverse()
print("".join(str(i) for i in answer))
# if m == kenzan(answer):
#     print("AC")
# else:
#     print("WA")

Submission status: Wrong Answer

Solution code:
#encoding utf-8

n = int(input())
m=n
answer = []

def kenzan(ans):
    val = 0
    for i in range(len(ans)):
        val += answer[i]*(-2)**i
    return int(val)

i = 1
while(n != 0):
    print(n)
    if n % (2**i) == 0:
        answer.append(0)
    else:
        answer.append(1)
        n = n-((-2)**(i-1))
    i += 1
answer.reverse()
print("".join(str(i) for i in answer))

Submission status: Wrong Answer

Solution code:
N = int(input())
n = 0
k = 0
even = True
if N == 0:
    print(0)
elif N > 0:
    while N > 0:
        if N & 1:
            if even:
                if n & 1 << k:
                    n = n + (5<<k)
                else:
                    n = n + (1<<k)
            else:
                if n & 1 << k:
                    n = n - (1<<k)
                else:
                    n = n + (3<<k)
        even = not even
        N = N >> 1
        k += 1
else:
    N = -N
    while N > 0:
        if N & 1 != 0:
            if even:
                if n & 1 << k:
                    n = n - (1<<k)
                else:
                    n = n + (3<<k)
            else:
                if n & 1 << k:
                    n = n + (5<<k)
                else:
                    n = n + (1<<k)
        even = not even
        N = N >> 1
        k += 1
b = bin(n)
print(b[2:])

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = ""
while n != 0:
    if n % 2 == 0:
        ans = "0" + ans
    else:
        ans = "1" + ans
    n = -(n // 2)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def n():
    return int(input())


N = n()
ans = ''
while N != 0:
    if abs(N%2) == 1:
        ans = '1' + ans
        N -= 1
    else:
        ans = '0' + ans
    N = N//(-2)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def solve(N):
    result = ""
    n = N
    i = 0
    while n:
        k = (-2)**i
        if n & (1 << i):
            n -= k
            result = "1" + result
        else:
            result = "0" + result
        i += 1
    return result

print(solve(N))

Submission status: Wrong Answer

Solution code:
N=-int(input())

tmp=[]
while N!=0:
    tmp.insert(0,N%(2))
    N=-N//2
s=''.join([str(_) for _ in tmp])
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = str()
i = 0
while n != 0:
  b = n%2
  if (b==1 or b== -1):
    ans = "1" + ans
  else:
    ans = "0" + ans
  n -= abs(b) *(-1) ** (i)
  n = n//2
  i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = ''
i = 0
while(abs(n) > 1):
    if(n % 2 ** (i+1) == 0): ans += '0'
    else:
        ans += '1'
        n -= (-2) ** i
    i += 1

print(ans[::-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
res=""
while N!=0:
	if N%2==0:
		res+="0"
	else:
		N-=1
		res+="1"
	print(N)
	N//=-2
if len(res)==0:
	res="0"
print(res[::-1])

Submission status: Wrong Answer

Solution code:
# C
N = int(input())

data = N
re = ''

while True:
    if data % 2 == 1:
        data -= 1 #data // abs(data) # 1加算・減算
        re = '1' + re
    else:
        if data // -2 != 0:
            re = '0' + re
        else:
            break
    data = data // -2
    
print(re)

Submission status: Wrong Answer

Solution code:
N = int(input())
i = 0
while(1):
  i_str = str(format(i, 'b'))
  j = 0
  x = 0
  for j in range(len(i_str)-1):
    x = x + int(i_str[-1-j])*(-2)**j
    j = j + 1
  if(x == N):
    print(i_str if N > 0 else int(i_str)*(-1))
    break
  i = i + 1 if N > 0 else i - 1

Submission status: Wrong Answer

Solution code:
N = int(input())
i = 0
while(1):
  i_str = str(format(i, 'b'))
  j = 0
  x = 0
  for j in range(len(i_str)-1):
    x = x + int(i_str[-1-j])*(-2)**j
    j = j + 1
  if(x == N):
    print(i_str if N > 0 else i_str[1:])
    break
  i = i + 1 if N > 0 else i - 1

Submission status: Wrong Answer

Solution code:
# C
N = int(input())

data = N
re = ''

while True:
    print(data)
    if data == 1:
        re = '1' + re
        break
    elif data == -1:
        re = '11' + re
        break
    elif data % -2 != 0:
        data += data // abs(data) # 1加算・減算
        re = '1' + re
    else:
        if data // -2 != 0:
            re = '0' + re
        else:
            break
    data = data // -2
    
print(re)

Submission status: Wrong Answer

Solution code:
import random
import bisect
import math

option = 0     # 0:PSO 1:CFA 2:CFArank
max_or_min = 0 # 0:minimize 1:maxmize

iter=3

N = 50 #粒子の数
T = 800 #世代数(ループの回数)
maximum=1
minimum=0

dimension, limit = 32, float("inf")

pi = [0 for i in range(dimension)]
ci = [0 for i in range(dimension)]
       
value = int(input())

#print(pi)
#print(ci)
#print(tot)


#--------粒　子　群　最　適　化------------------------------

#評価関数
def criterion(x):
    
    z = abs (sum([(-2)** i * x[i] for i in range(dimension)]) - value)
    return z

#粒子の位置の更新を行う関数
def update_position(x, v, x_min, x_max):
#    new_x = [x_min[i] if x[i]+ v[i] < x_min[i] else x_max[i] if x[i]+ v[i] > x_max[i] else x[i]+ v[i] for i in range(dimension)]
    new_x = [1 if random.uniform(0, 1)< 1/(1+math.e**(-v[i])) else 0 for i in range(dimension)]
    return new_x

#粒子の速度の更新を行う関数
def update_velocity(x, v, p, g, w, ro_max=1.0, c1=2.00, c2=0.75):
    #パラメーターroはランダムに与える
    phi=c1+c2
    K=2/abs(2-phi-(phi*phi-4*phi)**0.5)
    
    #粒子速度の更新を行う
    if option!=0:
        new_v = [K * ( w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) ) for i in range(dimension)]
    else:
        new_v = [w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) for i in range(dimension)]

    return new_v

def main():
    w = 1.0
    w_best, w_worst = 1.25, 0.25
    x_min = [minimum for i in range(dimension)]
    x_max = [maximum for i in range(dimension)]
    
    #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
    ps = [[random.randint(x_min[j], x_max[j]) for j in range(dimension)] for i in range(N)]
    vs = [[0.0 for j in range(dimension)] for i in range(N)]

    personal_best_positions = ps[:] 
    personal_best_scores = [criterion(p) for p in ps]

    if max_or_min == 1:
        best_particle = personal_best_scores.index(max(personal_best_scores))
    elif max_or_min == 0:
        best_particle = personal_best_scores.index(min(personal_best_scores))
    global_best_position = personal_best_positions[best_particle][:]

    for t in range(T):
        for n in range(N):
            x = ps[n][:]
            v = vs[n][:]
            p = personal_best_positions[n][:]

            if option>=2:
                best_list = sorted(personal_best_positions)
                mu = bisect.bisect_left( best_list, p ) + 1
                w = w_best - mu * (w_best - w_worst) / (N - 1)


            #粒子の位置の更新を行う
            new_x = update_position(x, v, x_min, x_max)
            ps[n] = new_x[:]

            #粒子の速度の更新を行う
            new_v = update_velocity(new_x, v, p, global_best_position, w)
            vs[n] = new_v[:]

            #評価値を求め, パーソナルベストの更新を行う
            score = criterion(new_x)

            if max_or_min == 1:
                if score > personal_best_scores[n]:
                    personal_best_scores[n] = score
                    personal_best_positions[n] = new_x[:]
            elif max_or_min == 0:
                if score < personal_best_scores[n]:
                    personal_best_scores[n] = score
                    personal_best_positions[n] = new_x[:]

        #グローバルベストの更新を行う
        if max_or_min == 1:
            best_particle = personal_best_scores.index(max(personal_best_scores))
            global_best_position = personal_best_positions[best_particle][:]

        elif max_or_min == 0:
            best_particle = personal_best_scores.index(min(personal_best_scores))
            global_best_position = personal_best_positions[best_particle][:]
                     
    #最適解
    if max_or_min == 1:
        return max(personal_best_scores)
    elif max_or_min == 0:
        return min(personal_best_scores), global_best_position

#--------------------------------------------------------------
    
if max_or_min == 1:
    best=-float("inf")
    for i in range(iter):
        best=max(best, main())

elif max_or_min == 0:
    best=float("inf")
    for i in range(iter):
        best2, answer2 =  main()
        if best2 <= best:
          best = best2
          answer = answer2
        
#print(best, answer)
flag = 0
s = ""
for i in range(len(answer)):
  if answer[len(answer)-1-i] ==1:
    flag = 1
  if flag ==1:
    s+=str(answer[len(answer)-1-i])
    
if value ==0:
  print(0)
else:
  print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())

N1 = N
N2 = N
result1 = []
result2 = []
count = 0
result = ""

while(N1 != 0):
  if count % 2 == 0:
    if int(N1 / -2) >= 0:
      if N1 % -2 == 0:
        result1.append(0)
      else:
        result1.append(1)
    else:
      if N1 % -2 == 0:
        result1.append(1)
      else:
        result1.append(0)
    if int(N2 / 2) >= 0:
      if N2 % 2 == 0:
        result2.append(0)
      else:
        result2.append(1)
    else:
      if N2 % 2 == 0:
        result2.append(1)
      else:
        result2.append(0)
    N1 = int(N1 / -2)
    N2 = int(N2 / 2)
  else:
    if int(N2 / -2) >= 0:
      if N2 % -2 == 0:
        result2.append(0)
      else:
        result2.append(1)
    else:
      if N2 % -2 == 0:
        result2.append(1)
      else:
        result2.append(0)
    if int(N1 / 2) >= 0:
      if N1 % 2 == 0:
        result1.append(0)
      else:
        result1.append(1)
    else:
      if N1 % 2 == 0:
        result1.append(1)
      else:
        result1.append(0)
    N1 = int(N1 / 2)
    N2 = int(N2 / -2)
  count += 1

if count % 2 == 0:
  for i in range(len(result1)):
    result += str(result1[i])
  print(result)
else:
  for i in range(len(result2)):
    result += str(result2[i])
  print(result)

Submission status: Wrong Answer

Solution code:
N = abs(int(input()))
count = abs(N)
result = ''
if N == 0:
    print('0')
else:
    for n in range(N):
        count -= 2
        if count < 2:
            break
        if count % 2 == 0 and count / 2 == 1:
            result = result + '1'
        elif count % 2 == 0 and count / 2 != 1:
            result = result + '0'
        else:
            result = result + '1'
            count -= 1
    print(result + '1')

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
R = ""

N = abs(N)

while True:
    r = abs(N%(-2))
    N = int((N-abs(N%(-2)))/-2)
    print(N)
    R = R + str(int(r))

    if N == 1 or N == 0:
        R = R + "1"
        print(R)
        exit()

Submission status: Wrong Answer

Solution code:
def fa(): #final answer
    global ans
    print(ans)
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
N = input()
if N[0] == "-":
    hugou = False
    N = N[1:]
else:
    hugou = True
N = int(N)
deci = []
carry = False
a  = bin(N)[2:]
if hugou:
    while(len(a) > 1):
        d = a[-2]+a[-1]
        if carry:
            if d == "00":
                d = "01"
            elif d == "01":
                d = "10"
            elif d == "10":
                d = "11"
            elif d == "11":
                deci.append("00")
                carry = True
                a = a[:-2]
                continue
        if d == "01":
            deci.append("01")
            carry = False
        elif d == "00":
            deci.append("00")
            carry = False
        elif d == "10":
            deci.append("10")
            carry = True
        elif d == "11":
            deci.append("11")
            carry = True
        a = a[:-2]

    if len(a) == 1:
        if a[0] == "0":
            deci.append("0")
        else:
            if carry:
                deci.append("110")
            else:
                deci.append("1")
    if len(a) == 0 and carry:
        if len(deci) != 0:
            deci.append("1")
        else:
            deci.append("0")

if not hugou:
    while (len(a) > 1):
        d = a[-2] + a[-1]
        if carry:
            if d == "00":
                deci.append("11")
                carry = False
            elif d == "01":
                deci.append("10")
                carry = False
            elif d == "10":
                deci.append("01")
                carry = True
            elif d == "11":
                deci.append("00")
                carry = True
        else:
            if d == "01":
                deci.append("11")
                carry = False
            elif d == "00":
                deci.append("00")
                carry = False
            elif d == "10":
                deci.append("10")
                carry = False
            elif d == "11":
                deci.append("01")
                carry = True
        a = a[:-2]
    if len(a) == 0 and carry:
        deci.append("11")
    if len(a) == 1:
        if a[0] == "0":
            deci.append("0")
        else:
            if carry:
                
                deci.append("11")
            else:
                deci.append("1")

deci.reverse()

print("".join(deci))
"""
   1 11 01 01 10 11 11 00 11 01 00 01 01 01
1 10 00 10 10 11 00 11 01 11 01 00 01 01 01
1 10 00 10 10 11 00 11 01 11 01 00 01 01 01
"""

Submission status: Wrong Answer

Solution code:
N = int(input())

N1 = N
N2 = N
result1 = []
result2 = []
count = 0
result = ""

while(N1 != 0):
  if count % 2 == 0:
    if int(N1 / -2) >= 0:
      if N1 % -2 == 0:
        result1.append(0)
      else:
        result1.append(1)
    else:
      if N1 % -2 == 0:
        result1.append(1)
      else:
        result1.append(0)
    if int(N2 / 2) >= 0:
      if N2 % 2 == 0:
        result2.append(0)
      else:
        result2.append(1)
    else:
      if N2 % 2 == 0:
        result2.append(1)
      else:
        result2.append(0)
    N1 = int(N1 / -2)
    N2 = int(N2 / 2)
  else:
    if int(N2 / -2) >= 0:
      if N2 % -2 == 0:
        result2.append(0)
      else:
        result2.append(1)
    else:
      if N2 % -2 == 0:
        result2.append(1)
      else:
        result2.append(0)
    if int(N1 / 2) >= 0:
      if N1 % 2 == 0:
        result1.append(0)
      else:
        result1.append(1)
    else:
      if N1 % 2 == 0:
        result1.append(1)
      else:
        result1.append(0)
    N1 = int(N1 / 2)
    N2 = int(N2 / -2)
  count += 1

if count % 2 == 0:
  for i in range(len(result1)):
    result += str(result1[i])
  print(result)
  print(1)
else:
  for i in range(len(result2)):
    result += str(result2[i])
  print(result)

Submission status: Wrong Answer

Solution code:
def fa(): #final answer
    global ans
    print(ans)
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
N = input()
if N[0] == "-":
    hugou = False
    N = N[1:]
else:
    hugou = True
N = int(N)
deci = []
carry = False
a  = bin(N)[2:]
if hugou:
    while(len(a) > 1):
        d = a[-2]+a[-1]
        if carry:
            if d == "00":
                d = "01"
            elif d == "01":
                d = "10"
            elif d == "10":
                d = "11"
            elif d == "11":
                deci.append("00")
                carry = True
                a = a[:-2]
                continue
        if d == "01":
            deci.append("01")
            carry = False
        elif d == "00":
            deci.append("00")
            carry = False
        elif d == "10":
            deci.append("10")
            carry = True
        elif d == "11":
            deci.append("11")
            carry = True
        a = a[:-2]

    if len(a) == 1:
        if a[0] == "0":
            deci.append("0")
        else:
            if carry:
                deci.append("110")
            else:
                deci.append("1")
    if len(a) == 0 and carry:
        if len(deci) != 0:
            deci.append("1")
        else:
            deci.append("0")

if not hugou:
    while (len(a) > 1):
        d = a[-2] + a[-1]
        if carry:
            if d == "00":
                deci.append("11")
                carry = False
            elif d == "01":
                deci.append("10")
                carry = False
            elif d == "10":
                deci.append("01")
                carry = True
            elif d == "11":
                deci.append("00")
                carry = True
        else:
            if d == "01":
                deci.append("11")
                carry = False
            elif d == "00":
                deci.append("00")
                carry = False
            elif d == "10":
                deci.append("10")
                carry = False
            elif d == "11":
                deci.append("01")
                carry = True
        a = a[:-2]
    if len(a) == 0 and carry:
        deci.append("11")
    if len(a) == 1:
        if a[0] == "0":
            deci.append("0")
        else:
            if carry:
                pass
                #deci.append("10")
            else:
                deci.append("1")

deci.reverse()

print("".join(deci))
"""
   1 11 01 01 10 11 11 00 11 01 00 01 01 01
1 10 00 10 10 11 00 11 01 11 01 00 01 01 01
1 10 00 10 10 11 00 11 01 11 01 00 01 01 01
"""

Submission status: Wrong Answer

Solution code:
def fa(): #final answer
    global ans
    print(ans)
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
N = input()
if N[0] == "-":
    hugou = False
    N = N[1:]
else:
    hugou = True
N = int(N)
deci = []
carry = False
a  = bin(N)[2:]
if hugou:
    while(len(a) > 1):
        d = a[-2]+a[-1]
        if carry:
            if d == "00":
                d = "01"
            elif d == "01":
                d = "10"
            elif d == "10":
                d = "11"
            elif d == "11":
                deci.append("00")
                carry = True
                a = a[:-2]
                continue
        if d == "01":
            deci.append("01")
            carry = False
        elif d == "00":
            deci.append("00")
            carry = False
        elif d == "10":
            deci.append("10")
            carry = True
        elif d == "11":
            deci.append("11")
            carry = True
        a = a[:-2]

    if len(a) == 1:
        if a[0] == "0":
            deci.append("0")
        else:
            if carry:
                deci.append("110")
            else:
                deci.append("1")
    if len(a) == 0 and carry:
        if len(deci) != 0:
            deci.append("1")
        else:
            deci.append("0")

if not hugou:
    while (len(a) > 1):
        d = a[-2] + a[-1]
        if carry:
            if d == "00":
                deci.append("11")
                carry = False
            elif d == "01":
                deci.append("10")
                carry = False
            elif d == "10":
                deci.append("01")
                carry = True
            elif d == "11":
                deci.append("00")
                carry = True
        else:
            if d == "01":
                deci.append("11")
                carry = False
            elif d == "00":
                deci.append("00")
                carry = False
            elif d == "10":
                deci.append("10")
                carry = False
            elif d == "11":
                deci.append("01")
                carry = True
        a = a[:-2]
    if len(a) == 0 and carry:
        deci.append("11")
    if len(a) == 1:
        if a[0] == "0":
            deci.append("0")
        else:
            if carry:
                deci.append("10")
            else:
                deci.append("1")

deci.reverse()

print("".join(deci))
"""
   1 11 01 01 10 11 11 00 11 01 00 01 01 01
1 10 00 10 10 11 00 11 01 11 01 00 01 01 01
1 10 00 10 10 11 00 11 01 11 01 00 01 01 01
"""

Submission status: Wrong Answer

Solution code:
n=int(input())
i=0
q=n
ans=""
b=[]

while 1:
  r=q%(-2)
  q=int(q/(-2))


  if r==0:
    b.append(0)
    if q==0:
      break
  else:
    
    b.append(1)
    if q==0:
      break
    if q>0:
      q=q+1

  i=i+1

b.reverse()
for j in range(i+1):
  ans=ans+str(b[j])

print(ans)

Submission status: Wrong Answer

Solution code:
from math import *
a = int(input())

# imax =
flag1 = a%2!=0
flag2 = a <=0

if flag1:
    a -=1

def Base_10_to_n(X, n):

    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(abs(X%n))
    return str(abs(X%n))

x2 = Base_10_to_n(a, -2)

if flag1:
    print(x2[:-1]+"1")
else:
    print(x2)

Submission status: Wrong Answer

Solution code:
from math import *
a = int(input())

# imax =
flag1 = a%2!=0
flag2 = a <=0

if flag1:
    a -=1

def Base_10_to_n(X, n):
    print(int(X/n))
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(abs(X%n))
    return str(abs(X%n))

x2 = Base_10_to_n(a, -2)

if flag1:
    print(x2[:-1]+"1")
else:
    print(x2)