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:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
if N == 0:
    print(0)
    exit(0)

if N >= 0:
    b = bin(N)[2:]

    lst = [0 for _ in range(len(b)+10)]

    for e,s in enumerate(reversed(b)):
        if e % 2 == 0:
            lst[e] += int(s)
        elif e % 2 == 1:
            lst[e] += int(s)
            lst[e+1] += int(s)
    # print(list(map(str, reversed(lst))))

    for e,s in enumerate(lst):
        if s >= 2:
            if e % 2 == 0:
                while lst[e] > 1:
                    lst[e] -= 2
                    if lst[e+1] > 0:
                        lst[e+1] -= 1
                    else:
                        lst[e+1] += 1
                        lst[e+2] += 1
            else:
                # lst[e+1] += lst[e] // 2
                # lst[e+2] += lst[e] // 2
                # lst[e] = lst[e] % 2 
                while lst[e] > 1:
                    lst[e] -= 2
                    if lst[e+1] > 0:
                        lst[e+1] -= 1
                    else:
                        lst[e+1] += 1
                        lst[e+2] += 1

    # print(list(map(str, reversed(lst))))
    flag = False
    for s in "".join(map(str, reversed(lst))):
        if not flag and s=="0":
            continue
        else:
            flag = True
            print(s, end="")
    print()
else:
    b = bin(N)[3:]
    lst = [0 for _ in range(100)]
    for e,s in enumerate(reversed(b)):
        if e % 2 == 0:
            lst[e] ^= int(s)
            lst[e+1] ^= int(s)
        else:
            lst[e] ^= int(s)
    flag = False
    for s in "".join(map(str, reversed(lst))):
        if not flag and s == "0":
            continue
        else:
            flag = True
            print(s, end="")
    print()

# print("".join(map(str, reversed(lst))))

Submission status: Wrong Answer

Solution code:
n = int(input())

plus = []
minus = []
plus_sum = []
minus_sum = []

s_p = 0
s_m = 0
for i in range(31):
    if i % 2 == 0:
        plus.append(2**i)
        s_p += 2**i
        plus_sum.append(s_p)
    else:
        minus.append(2**i)
        s_m += 2**i
        minus_sum.append(s_m)

def ten_four(num):
    def for_four(num, arr):
        if num == 0:
            if arr == []:
                return '0'
            else:
                arr_str = map(str, arr[::-1])
                ans = (''.join(arr_str))
                return ans
        else:
            s = num // 4
            a = num % 4
            arr.append(a)
            return for_four(s, arr)
    
    arr = []
    return for_four(num, arr)


if n == 0:
    print(0)
elif n == 1:
    print(1)
elif n == -1:
    print(11)
elif n == -2:
    print(10)

elif n > 0:
    for i in range(len(plus_sum)):
        if n <= plus_sum[i]:
            max_4 = i - 1
            n_4 = n - 1 - plus_sum[max_4]
            break
        else:
            pass
    n_4zf = ten_four(n_4).zfill(max_4 + 1)
    n_ans = n_4zf.translate(str.maketrans({'0': '10', '1': '11', '2': '00', '3': '01'}))
    print('1'+n_ans)

elif n < 0:
    n_1 = n % 2
    n = int(abs((n - n_1)/2))
    print(n)
    for i in range(len(plus_sum)):
        if n <= plus_sum[i]:
            max_4 = i - 1
            n_4 = n - 1 - plus_sum[max_4]
            break
        else:
            pass
    n_4zf = ten_four(n_4).zfill(max_4 + 1)
    n_ans = n_4zf.translate(str.maketrans({'0': '10', '1': '11', '2': '00', '3': '01'}))
    print('1'+n_ans+str(n_1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
import bisect


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: 数
        """
        return int(input())

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数で合計
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if ((i >> j) & 1) == 1:
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """コピーコードです。https://atcoder.jp/contests/abc105/submissions/4088632 
    こちらを参考にテストを行っています。"""
    n = ip.I()
    # それぞれ半分全列挙
    list1 = [(-2) ** i for i in r(16)]
    list2 = [(-2) ** (i + 16) for i in r(16)]
    list1_bin, list1_val = id.Bfs2(list1)
    list2_bin, list2_val = id.Bfs2(list2)

    # 2分探索
    ans = 0
    for i in r(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])

        if j < len(list2_val) and list1_val[i] + list2_val[j] == n:
            ans = list2_bin[j] + list1_bin[i]
            print(j)
            break
    print(int(ans))


main()

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
#template input
import bisect

def IT():
    return int(input())
def IL():
    return [int(_) for _ in input().split()]
def SL():
    return [int(_) for _ in input().split()]
def ILS(n):
    return [int(input()) for _ in range(n)]
def SLS(n):
    return [input() for _ in range(n)]
def ILSS(n):
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)

def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        #print(output)
        value.append([format(i, 'b'), sum(output)])
#    print(value)
    return value


"""ここからメインコード"""
def main():
    n = IT()
    #それぞれ半分全列挙
    list1 = [(-2) **  i for i in range(17)]
    list2 = [(-2) ** (i + 17) for i in range(17)]

    list1 = bit_full_search2(list1)
    list1.sort(key=lambda x:x[1])
    list1_bin = [list1[i][0] for i in range(len(list1))]
    list1_val = [list1[i][1] for i in range(len(list1))]

    list2 = bit_full_search2(list2)
    list2.sort(key=lambda x:x[1])
    list2_bin = [list2[i][0] for i in range(len(list2))]
    list2_val = [list2[i][1] for i in range(len(list2))]

    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                ans = list2_bin[j] +list1_bin[i]
                break

    print(int(ans))

main()

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
#template input
import bisect

def IT():
    return int(input())
def IL():
    return [int(_) for _ in input().split()]
def SL():
    return [int(_) for _ in input().split()]
def ILS(n):
    return [int(input()) for _ in range(n)]
def SLS(n):
    return [input() for _ in range(n)]
def ILSS(n):
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)

def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        #print(output)
        value.append([format(i, 'b'), sum(output)])
#    print(value)
    return value


"""ここからメインコード"""
def main():
    n = IT()
    #それぞれ半分全列挙
    list1 = [(-2) **  i for i in range(16)]
    list2 = [(-2) ** (i + 16) for i in range(16)]

    list1 = bit_full_search2(list1)
    list1.sort(key=lambda x:x[1])
    list1_bin = [list1[i][0] for i in range(len(list1))]
    list1_val = [list1[i][1] for i in range(len(list1))]

    list2 = bit_full_search2(list2)
    list2.sort(key=lambda x:x[1])
    list2_bin = [list2[i][0] for i in range(len(list2))]
    list2_val = [list2[i][1] for i in range(len(list2))]

    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                ans = list2_bin[j] +list1_bin[i]
                break

    print(int(ans))

main()

Submission status: Wrong Answer

Solution code:
n = int(input())

base = [(-2)**i for i in range(33)]

if n > 0:
  for i in range(len(base)):
    if base[i] > n:
      print(base[i])
      num = i
      break
elif n < 0:
  for i in range(len(base)):
    if base[i] < n:
      num = i
      break
  
else:
  print(0)
  exit()
  
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
minus_bit = ''
if N == 0:
    minus_bit = '0'
while N != 0:
    mod = N % 4
    if mod == 0:
        minus_bit = minus_bit + '00'
        N = N//4
        print(N)
    elif mod == 1:
        minus_bit = minus_bit + '10'
        N = (N-1)//4
        print(N)
    elif mod == 2:
        minus_bit = minus_bit + '01'
        N = (N+2)//4
        print(N)
    else:
        minus_bit = minus_bit + '11'
        N = (N+1)//4
        print(N)

if minus_bit[-1] == '0':
    minus_bit = minus_bit[:-1]
print(minus_bit[::-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

if N==0:
    print(0)
else:
    ans = []
    
    while N!=0:
        now = str(N%2)
        ans.append(now)
        N = -1*(N//2)
    
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
i=0
s=[]
n=N
while 1:
    k=pow(2,i+1)
    d=n%k
    if d!=0:
        s.append(1)
        n=n-pow(-2,i)
    elif n//k!=0:
        s.append(0)
    else:
        break
    i=i+1
while s:
    print(s.pop(),end="")
print("")

Submission status: Wrong Answer

Solution code:
N=int(input())
i=0
s=[]
n=N
while 1:
    k=pow(2,i+1)
    d=n%k
    if d!=0:
        s.append(1)
        n=n-pow(-2,i)
    elif n//k!=0:
        s.append(0)
    else:
        break
    i=i+1
while s:
    print(s.pop())

Submission status: Wrong Answer

Solution code:
n=int(input())
x=""
while n!=0:
    x+=str(n%2)
    n=-(n//2)
print("0" if x=="" else x)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []

while n // -2 != 0:
    if n % -2 != 0:
        A.append('1')
        n = n // -2 + 1
    else:
        A.append('0')
        n = n // -2

A.reverse()
print(''.join(A))

Submission status: Wrong Answer

Solution code:
N=int(input())

m = 2
s = ""
sgn = 1
while N!=0:
    r = N % m
    s += "1" if r != 0 else "0"
    m *= -2
    N = N -r 
if N == 0:
    print(0)
else:
    print(s[::-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
if N==0:
    a=0
elif N>0:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2==1:
                a+=2**(i+1)+2**i
                break
            else:
                a+=2**i
                break
        else:
            if N>2**i:
                N-=2**i
                if i%2==1:
                    a+=2**(i+1)+2**i
                else:
                    a+=2**i
            i-=1
else:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2!=1:
                a+=2**(i+1)+2**i
                break
            else:
                a+=2**i
                break
        else:
            if -N>2**i:
                N+=2**i
                if i%2!=1:
                    a+=2**(i+1)+2**i
                else:
                    a+=2**i
            i-=1
print(int(format(a,"b")))

Submission status: Wrong Answer

Solution code:
N=int(input())
if N==0:
    print(0)
elif N>0:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2==1:
                a+=10**(i+1)+10**i
                break
            else:
                a+=10**i
                break
        else:
            if N>2**i:
                N-=2**i
                if i%2==1:
                    a+=10**(i+1)+10**i
                else:
                    a+=10**i
            i-=1
    b=str(a)
    for j in range(len(b)):
        if b[j]=="2":
            b=b[:j]+"10"+b[j+1:]
    print(int(b))
else:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2!=1:
                a+=10**(i+1)+10**i
                break
            else:
                a+=10**i
                break
        else:
            if -N>2**i:
                N+=2**i
                if i%2!=1:
                    a+=10**(i+1)+10**i
                else:
                    a+=10**i
            i-=1
    b=str(a)
    for j in range(len(b)):
        if b[j]=="2":
            b=b[:j]+"10"+b[j+1:]
    print(int(b))

Submission status: Wrong Answer

Solution code:
N=int(input())
if N==0:
    print(0)
elif N>0:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2==1:
                a+=10**(i+1)+10**i
                break
            else:
                a+=10**i
                break
        else:
            if N>2**i:
                N-=2**i
                if i%2==1:
                    a+=10**(i+1)+10**i
                else:
                    a+=10**i
            i-=1
    print(a)
else:
    a=0
    i=31
    while i>=0:
        if N%(2**i)==0:
            if i%2!=1:
                a+=10**(i+1)+10**i
                break
            else:
                a+=10**i
                break
        else:
            if -N>2**i:
                N+=2**i
                if i%2!=1:
                    a+=10**(i+1)+10**i
                else:
                    a+=10**i
            i-=1
    print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())


def f(n):
    if n == 0:
        return "0"

    if n % 2 == 0:
        return f(n // (-2)) + "0"
    else:
        return f((n - 1) // (-2)) + "1"


ans = f(N)
if ans[0] == "0":
    ans = ans[1:]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = 0
while n != 0:
    c = (-2) ** b
    if n % (c*(-2)) != 0:
        n -= c
        a.append("1")
    else:
        a.append("0")
    b += 1
ans = "".join(reversed(a))
if ans == None:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = 0
while n != 0:
    c = (-2) ** b
    if n % (c*(-2)) != 0:
        n -= c
        a.append("1")
    else:
        a.append("0")
    b += 1
else:
    a.append("0")
ans = "".join(reversed(a))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
b = 0
while n != 0:
    c = (-2) ** b
    if n % (c*(-2)) != 0:
        n -= c
        a.append("1")
    else:
        a.append("0")
    b += 1
ans = "".join(reversed(a))
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
quat=[]

while N>0:
    quat.append(N%4)
    N//=4
quat.append(0)

ans = [0]*(2*len(quat)+2)

for i in range(len(quat)):
    if quat[i]<=1:
        ans[2*i]=quat[i]
    elif quat[i]<=3:
        ans[2*i]=quat[i]%2
        ans[2*i+1]=1
        quat[i+1]+=1
    else:
        quat[i+1]+=1

ansstr=''

i=len(ans)-1

while ans[i]==0:
    i-=1
    if i==-1:
        break

while i>=0:
    ansstr += str(ans[i])
    i-=1


if len(ansstr)>0:
    print(ansstr)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=''
while a:
 b=str(a&1)+b
 a= (a>>1)
print(b if b else 0)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=''
while a:
 b=str(a&1)+b
 a= a>>1
print(b if b else 0)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = []

while n != 0:
    if n % -2 == -1:
        n = n // -2 + 1
        ans.append('1')
    else:
        n = n // -2
        ans.append('0')
    
ans.reverse()

if n == 0:
    print('0')
else:
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
def hoge(n):
    for i in range(30):
        if(minList[i] <= n and n <= maxList[i]):
            break
    return i

N = int(input().strip())

minList = [0]
maxList = [1]
for d in range(1, 30):
    minList.append(min(minList[-1] + (-2)**d, minList[-1]))
    maxList.append(max(maxList[-1], maxList[-1] + (-2)**d))
    
residual = N
index = hoge(residual)
ans = [0 for i in range(index + 1)]
ans[0] = 1
residual = residual - (-2)**index

while(residual != 0):
    index = hoge(residual)
    ans[len(ans) - 1 - index] = 1
    residual = residual - (-2)**index

if(N == 0):
    ans = [0]
    
print("".join(str(e) for e in ans))

Submission status: Wrong Answer

Solution code:
def hoge(n):
    while(True):
        for i in range(30):
            if(minList[i] <= n and n <= maxList[i]):
                break
        return i

N = int(input().strip())

minList = [0]
maxList = [1]
for d in range(1, 30):
    minList.append(min(minList[-1] + (-2)**d, minList[-1]))
    maxList.append(max(maxList[-1], maxList[-1] + (-2)**d))
    
residual = N
index = hoge(residual)
ans = [0 for i in range(index + 1)]
ans[0] = 1
residual = residual - (-2)**index

while(residual != 0):
    index = hoge(residual)
    ans[len(ans) - 1 - index] = 1
    residual = residual - (-2)**index

if(N == 0):
    ans = [0]
    
print("".join(str(e) for e in ans))

Submission status: Wrong Answer

Solution code:
from math import *

#N = int(input())
N = int(input().strip())

def search_n(N):
    if N == 0 or N == 1:
        return 1
    minN = 0
    maxN = 1
    for i in range(1, 40):
        a1 = minN + (-2)**i
        a2 = maxN + (-2)**i
        minN = min(minN, min(a1, a2))
        maxN = max(maxN, max(a1, a2))
        if N <= maxN and N >= minN:
            return i

result = []
while N != 0 and N != 1:
    n = search_n(N)
    N -= (-2)**n
    if len(result) == 0:
        result = ['0' for i in range(0, n+1)]
    result[n] = '1'

if N==1:
    result[0] = '1'

result.reverse()
print(''.join(result))

Submission status: Wrong Answer

Solution code:
from math import *

#N = int(input())
N = int(input().strip())

def search_n(N):
    if N == 0 or N == 1:
        return 1
    minN = 0
    maxN = 1
    for i in range(1, 32):
        a1 = minN + (-2)**i
        a2 = maxN + (-2)**i
        minN = min(minN, min(a1, a2))
        maxN = max(maxN, max(a1, a2))
        if N <= maxN and N >= minN:
            return i

result = []
while N != 0 and N != 1:
    n = search_n(N)
    N -= (-2)**n
    if len(result) == 0:
        result = ['0' for i in range(0, n+1)]
    result[n] = '1'

if N==1:
    result[0] = '1'

result.reverse()
print(''.join(result))

Submission status: Wrong Answer

Solution code:
N=int(input())

x=[]
if N != 0:
	flag = N // abs(N)
N=abs(N)
while N != 0:
	x.insert(0,N % 2 * flag )
	N //= 2
	flag *= -1
x.insert(0,0)
x.insert(0,0)

# 2 = (-1)*(-2) = (-2+1)*(-2) = (-2)^2+(-2)
for i in range(len(x))[::-1]:
	if x[i] == -1:
		x[i] = 1
		x[i-1] += 1
	if x[i] == 2:
		x[i] = 0
		x[i-1] += 1
		x[i-2] += 1

if x[0]==1:
	print(1,end="")
elif len(x)==1:
	print(0)
for i in range(1,len(x)):
	print(x[i],end="")
"""
print()
check=0
count=1
for i in range(len(x))[::-1]:
	check +=  x[i] * count
	count *= -2
print(check)
"""

Submission status: Wrong Answer

Solution code:
num_dec = int(input())
num_bin = ''

while num_dec != 0:
  if num_dec % 2:
    num_dec -= 1
    num_bin += '1'
  else:
    num_bin += '0'
  num_dec /= -2

print(num_bin[::-1])

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    if n == 0:
        print(0)
        return

    r0 = r1 = 0
    rs = []
    m = 1
    while True:
        if len(rs) > 0:
            r = (r0 + m, r1 + m)
        else:
            r = (0, 1)
        rs.append(r)
        if r[0] <= n <= r[1]:
            break
        r0 = min(r0, r[0])
        r1 = max(r1, r[1])
        m *= -2

    s = []
    for r in reversed(rs):
        if r[0] <= n <= r[1]:
            s.append('1')
            n -= m
        else:
            s.append('0')
        m //= -2
    print(''.join(s))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
x = []

if n == 0:
    print(0)
else:
    if n > 0:
        a = math.ceil(math.log2(n * 3 + 1) / 2) 
        b = 2 * a - 1
        print(b)
        x = [[]] * (b)
        print(x)
    else:
        a = math.ceil(math.log2((-3 * n + 2) / 2) / 2)
        b = 2 * a
        x = [[]] * (b)
        print(x)
    while n != 0:
        if n > 0:
            a = math.ceil(math.log2(n * 3 + 1) / 2) 
            b = 2 * a - 1 
            n = n - (2) ** (b-1)
            print(n)
            print(b-1)
            x[-b] = "1"  
        else:
            a = math.ceil(math.log2((-3 * n + 2) / 2) / 2)
            b = 2 * a
            n = n - (-2) ** (b-1)
            print(n)
            print(b-1)
            x[-b] = "1"
print(x)
x_replace = ["0" if i != "1" else i for i in x]
x_replace = "".join(x_replace)
print(x_replace)

Submission status: Wrong Answer

Solution code:
n = int(input())
binary = []
flag = 0

if n == 0:
    print(0)
    flag = 1
    
while n != 0:
    if n % -2 != 0:
        binary.append('1')
        n = n // -2 + 1
    else:
        binary.append('0')
        n = n // -2
        
if flag == 0:
    print(''.join(binary))

Submission status: Wrong Answer

Solution code:
N = int(input())
binarys = []
flag = 0

if N == 0:
    print(0)
    flag = 1
    
while N != 0:
    if N % -2 != 0:
        binarys.append('1')
        N = N // -2
    else:
        binarys.append('0')
        N = N // -2

binarys.reverse()

if flag == 0:
    print(''.join(binarys))

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = []
while n != 0:
    if n % -2 == -1:
        n -= 1
        ans += ['1']
    else:
        ans += ['0']
    n //= -2
ans.reverse()
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
result = '1'

if N > 0:
    s = 1
    e = 1
    r = 4
    degit = 0
    
    while True:
        if N <= e:
            for i in range(degit):
                if i % 2 == 0:
                    if N <= (s+e)//2:
                        result += '1'
                        e = (s+e)//2
                    else:
                        result += '0'
                        s = (s+e)//2+1
                else:
                    if N <= (s+e)//2:
                        result += '0'
                        e = (s+e)//2
                    else:
                        result += '1'
                        s = (s+e)//2+1
            break
            
        s = e + 1
        e = e + r
        r *= 4
        degit += 2
        

elif N < 0:
    s = -1
    e = -2
    r = -8
    degit = 1

    while True:
        if N >= e:
            for i in range(degit):
                print((s+e)//2+1)
                if i % 2 == 0:
                    if N >= (s+e)//2+1:
                        result += '1'
                        e = (s+e)//2+1
                    else:
                        result += '0'
                        s = (s+e)//2
                else:
                    if N >= (s+e)//2+1:
                        result += '0'
                        e = (s+e)//2+1
                    else:
                        result += '1'
                        s = (s+e)//2
            break
                    
        s = e - 1
        e = e + r
        r *= 4
        degit += 2
    

else:
    result = '0'

print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())

result = '1'

if N > 0:
    num = 1
    x = 1
    digit = 0
    while True:
        if N <= num:        
            for i in range(digit):
                if i % 2 == 0:
                    if N <= num - (x / 2):
                        result += '1'
                        x //= 2
                        num -= x
                    else:
                        result += '0'
                        x //= 2
                else:
                    if N >= num - (x / 2) + 1:
                        result += '1'
                        x //= 2
                    else:
                        result += '0'
                        x //= 2
                        num -= x
            break

        x *= 4
        num += x
        digit += 2

elif N < 0:
    num = -2
    x = -2
    digit = 1
    while True:
        if N >= num:        
            for i in range(digit):
                if i % 2 == 0:
                    if N >= num - (x / 2):
                        result += '1'
                        x //= 2
                    else:
                        result += '0'
                        x //= 2
                        num += x
                else:
                    if N >= num - (x / 2) + 1:
                        result += '1'
                        x //= 2
                        num += x
                    else:
                        result += '0'
                        x //= 2
            break

        x *= 4
        num += x
        digit += 2
        
else:
    result = '0'

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n ==0:
  print(0)
s=''
while n !=0:
  if n%2==1:
    s="1"+s
    n-=1
  else:
    s='0'+s
  n-=n//2
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = []
x = 2
i = 0
while n != 0:
    if n%x!=0:
        ans.append(1)
        n = n - (-2)**i
    else:
        ans.append(0)
    i += 1
    x *= 2
print(''.join([ str(x) for x in ans[::-1]]))

Submission status: Wrong Answer

Solution code:
x=int(input())

LIST2=[1]
LIST2X=[-2]

N=1
for i in range(1,30):
    N=N+4**i
    LIST2.append(N)
N=-2
for i in range(1,30):
    N=N-2*4**i
    LIST2X.append(N)



LIST=[0]*60

def nex(N):
    if N>0:
        for i in range(30):
            if N<=LIST2[i]:
                break
        LIST[i*2]+=1
        return N-(-2)**(i*2)

    if N<0:
        for i in range(30):
            if N>=LIST2X[i]:
                break
        LIST[i*2+1]+=1
        return N-(-2)**(i*2+1)

while x!=0:
    x=nex(x)
    print(x)

for i in range(59,-1,-1):
    if LIST[i]==1:
        break

for j in range(i,-1,-1):
    print(LIST[j],end="")

Submission status: Wrong Answer

Solution code:
n = int(input())
li = []
res = n % (-2)
ans = n // (-2)
li.append(res)
p = 0
while p == 0:
  res = ans % (-2)
  ans = ans // (-2)
  li.append(res)
  if ans == 0 or ans == 1:
    p = 1
    if ans == 1:
      li.append(ans)
li = [str(n) for n in li]
pr = ""
for i in range(len(li)):
  pr += li[-1-i]
print(pr)

Submission status: Wrong Answer

Solution code:
a = []
aa = (int)(input())
if(aa == 0):
  print(0)
else:
  while(aa!=0):
    a.append(aa%(-2))
    aa/=(-2)
  print(a[::-1])

Submission status: Wrong Answer

Solution code:
def base2_number(n):
    result = ""
    while True:
        print(n)
        rem = n % 2
        if rem:
            n -= 1
        n = n // -2
        result += str(abs(rem))
        if n == 0:
            break
    return int(result[::-1])
n = int(input())
print(base2_number(n))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = ''
ans_l = []
while N != 0:
	if N % 2 == 0:
		N = N // (-2)
		S = '0' + S
	else:
		N = (N-1) // (-2)
		S = '1' + S
print(S)

Submission status: Wrong Answer

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

def minus_2(n):
    ans = ''
    
    if n == 1:
        ans += '1'
    elif n == 0:
        ans += '0'
    else:
        for i in range(10**9):
            if n % 2 == 0:
                ans += '0'
            else:
                ans += '1'
            n = math.ceil(n/-2)
            if n == 1:
                break
            ans += '1'
            ans = ans[::-1]
        
    return ans

print(minus_2(N))

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = N
result = []
while ans != 0:
    if(ans % 2 == 1):
        ans = (ans-1)/(-2)
        result.append(1)
    else:
        ans = ans/(-2)
        result.append(0)

result.reverse()
nishin = ''
for i in range(len(result)):
    nishin = nishin+str(result[i])
print(nishin)

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 0:
    print('0')
else:
    k = 0
    ans = []
    while(True):
        if N % (-2) ** k == 0:
            ans.append('0')
        else:
            ans.append('1')
            N -= (-2) ** (k - 1)
        if N == 0:
            break
        else:
            k += 1
    print(''.join(ans[::-1]))

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = []
while N != 0:
    ans.append(N % 2)
    N = (N - N % 2) // -2

print(''.join(map(str, reversed(ans))))