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: Accepted

Solution code:
n=int(input());s=''
while n:s=str(n%2)+s;n=-(n//2)
print(s or 0)

Submission status: Accepted

Solution code:
import numpy as np


N = input()
N = int(N)

def make_base_list(N):
    base_list = []
    for i in range(100):
        if N == 0:
            break
        if abs(N) % 2 == 0:
            base_list.append(int(0))
        else:
            base_list.append(int(1))
            if i % 2 == 0:
                N -= 1
            else:
                N += 1
        N = int(N)
        N = N // 2

        #print(N)
    # print(base_list)
    return base_list

def base_list_to_str(list):
    list = list[::-1]
    return ''.join([str(n) for n in list])


if __name__ == '__main__':
    if N == 0:
        print(str(0))
    else:
        print(base_list_to_str(make_base_list(N)))

Submission status: Accepted

Solution code:
n=int(input())
if n==0:
  print(0)
  exit()
ans=[]
for i in range(10**5):
  if n==0:
    break
  k=n%(pow(2,i+1))
  if k==0:
    ans.append(0)
  else:
    ans.append(1)
    n-=pow(-2,i)
ans.reverse()
print("".join(map(str,ans)))

Submission status: Accepted

Solution code:
n=int(input())
if n==0:
  print(0)
  exit()
if n>0:
  x=list(map(int,bin(n)[2:]))
  x.reverse()
  y=[0]*(len(x)+3-len(x)%2)
  for i in range(len(x)):
    if i%2==1 and x[i]==1:
      y[i]+=1
      y[i+1]+=1
    elif i%2==0 and x[i]==1:
      y[i]+=1
  for i in range(len(y)):
    if i%2==0 and y[i]==2:
      y[i]=0
      y[i+1]+=1
      y[i+2]+=1
    elif i%2==1 and y[i]==2:
      y[i]=0
      y[i+1]-=1
  y.reverse()
  print(int("".join(map(str,y))))
  exit()
if n<0:
  x=list(map(int,bin(abs(n))[2:]))
  x.reverse()
  y=[0]*(len(x)+3-len(x)%2)
  for i in range(len(x)):
    if i%2==0 and x[i]==1:
      y[i]+=1
      y[i+1]+=1
    elif i%2==1 and x[i]==1:
      y[i]+=1
  for i in range(len(y)):
    if i%2==1 and y[i]==2:
      y[i]=0
      y[i+1]+=1
      y[i+2]+=1
    elif i%2==0 and y[i]==2:
      y[i]=0
      y[i+1]-=1
  y.reverse()
  print(int("".join(map(str,y))))
  exit()

Submission status: Accepted

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: Accepted

Solution code:
N = int(input())
if N == 0:
  print(0)
else:
  ans = ''
  flag = False
  while flag == False:
    if N%2 == 0:
      ans = '0'+ans
      N = N/(-2)
    else:
      ans = '1'+ans
      N -= 1
      if N == 0:
        flag = True
      else:
        N = N/(-2)
  print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip())
to4 = []
while N !=1 and N!=-1 and N!=0:
  #print(N)
  if N%2==0:
    to4.append("0")
    N = N//(-2)
  else:
    to4.append("1")
    N = int((N-1)/(-2))
  #print(to4[-1])

if N==1:
  to4.append("1")
elif N==0:
  to4.append("0")
else:
  to4.append("11")
to4 = to4[::-1]
ans = "".join(to4)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = ""

if n == 0:
  ans += "0"

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

Submission status: Accepted

Solution code:
N = int(input())
if N == 0:
    print("0")
    exit()
a = []
#N = abs(N)
for i in range(1000000000):
    if N == 0:
        break
    else:
        if abs(N) % pow(2,i+1) != 0:
            a.append(1)
            N -= pow(-2,i)
        else:
            a.append(0)
        #print(N)
#print(a)
s = 0
for i in range(len(a)):
    s += a[i] * pow(10,i)
print(s)

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
	print(0)
	exit()
res = ""
while True:
	if n == 0:
		break
	else:
		if n%2 == 0:
			res += '0'
		else:
			res += '1'
			n -= 1
		n //= -2
print(res[::-1])

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = ""

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

Submission status: Accepted

Solution code:
n=int(input())
a=True
if n==0:
    print(0)
    a=False

lst=[]
while a:
    if n%-2==-1:
        n=n//-2 +1
        lst.append(1)
    else:
        n=n//-2
        lst.append(0)
    if n==1 :
        lst.append(1)
        lst.reverse()
        print(int("".join(list(map(str,lst)))))
        break

Submission status: Accepted

Solution code:
def main():
    a = int(input())
    ans = ""

    if a == 0:
        print (0)
        return 
    while a != 0:
        ans += str(int(abs(a) % 2))
        if int(abs(a)) & 1:
            a -= 1
        a /= (-2)

    print (ans[::-1])

main()

Submission status: Accepted

Solution code:
N=int(input())
P=N
Q=0
R=0
L=''
if N==0:
    ans=0
else:
    while abs(P)>1:
        if P%2==0:
            Q=P/(-2)
            L+='0'
        else:
            Q=(P-1)/(-2)
            L+='1'
        P=Q
    if P==1:
        L+='1'
    else:
        L+='11'
    ans=L[::-1]
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
l=[0] if N==0 else []
j=0

while sum(l[i]*(-2)**i for i in range(len(l)))!=N:
  if sum(l[i]*(-2)**i for i in range(len(l)))%((-2)**(j+1))==N%((-2)**(j+1)):
    l.append(0)
  else:
    l.append(1)
  j+=1
print(''.join(map(str,reversed(l))))

Submission status: Accepted

Solution code:
N=int(input())
s=[]
if N==0:
    print(0)
else:
    while N!=1:
        if N%2==0:
            s.append(0)
            N=-N//2
        else:
            s.append(1)
            N=(1-N)//2
    s.append(1)
    print(*reversed(s),sep='')

Submission status: Accepted

Solution code:
N = int(input())
i = 1
ans = [0 for i in range(1) if N == 0]
while N != 0:
    if N % (-2 ** i) == 0:
        ans.append(0)
    else:
        ans.append(1)
        N -= ((-2)**(i-1))
    i += 1
print("".join(map(str, ans))[::-1])

"""
N = bin(int(input()))
N_str = str(N)[:1:-1]+"0"  # 逆順
N_list = list(N_str)
print(N_list)
for i in range(len(N_list)+1):
    if i % 2 == 1:


        # 繰り上がり
        for j in range(i+1, len(N_list)):
            # N[j] += 1
            # print(type(N[j]))
            N_list[j] = str(int(N_list[j])+1)
            # N_str[j] = str(int(N[j])+1)
            if N_list[j] == "2":
                N_list[j] = "0"
                continue
            else:
                break

ans = "".join(N_list[::-1])
print(ans)
        """

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

if N == 0:
    print(0)
else:
    curr = N
    ans = ""
    idx = 0
    while curr != 0:
        c = curr // pow(2, idx)
        if c % 2 == 1:
            ans = "1" + ans
            curr -= pow(-2, idx)
        else:
            ans = "0" + ans
        idx += 1
    print(ans)

Submission status: Accepted

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

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

if res == "":
    res = "0"
    
print(res)

Submission status: Accepted

Solution code:
n = int(input())
base = 2
ans =""

while n != 0:
  ans = str(n%base)+ans
  n = -(n//base)
if ans:
  print(ans)
else:
  print(0)

Submission status: Accepted

Solution code:
#むずい
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
 
n = ni()
 
if n == 0:
    print(0)
else:
    s = ""
    while n != 0:
        #  print('n', n)
        if n % 2 != 0:
            n -= 1
            s = "1" + s
        else:
            s = "0" + s
        n //= -2
    print(s)

Submission status: Accepted

Solution code:
n = int(input())
s = ""

if n == 0:
    print("0")

while abs(n) > 0:
    if(abs(n) % 2 == 0):
        s = "0" + s
    else:
        s = "1" + s
        n -= 1
    n = n // (-2)
print(s)

Submission status: Accepted

Solution code:
N = int(input())

ans = ""
if N == 0:
    ans = "0"
else:
    while N != 0:
        b = N % 2
        ans += str(b)
        N = (N - b) // -2

print(ans[::-1])

Submission status: Accepted

Solution code:
n = int(input())

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

else:
    ans = []
    r = 1
    while n != 0:
        if n % (r*-2) == 0:
            ans.append('0')
        else:
            ans.append('1')
            n -= r
        r *= -2
print(''.join(reversed(ans)))

Submission status: Accepted

Solution code:
N = int(input())
s = []
if N == 0:
    print(N)
    exit()
while N:
    s.append(abs(N)%2)
    N -= 1
    N //= -2
for i in range(1,len(s)+1):
    print(s[-i], end='')

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = ""

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

    else:
        while N:
            if N % 2:
                N -= 1
                S = "1" + S

            else:
                S = "0" + S

            N //= -2

        print(S)

    return


main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = ''

    if N == 0:
        print(0)

    else:
        while N:
            if N % 2 != 0:
                S = '1' + S
                N -= 1

            else:
                S = '0' + S

            N //= -2

        print(S)

    return


main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = ""

    if N == 0:
        print(0)

    else:
        while N:
            if N % 2 != 0:
                S = '1' + S
                N -= 1

            else:
                S = '0' + S

            N //= -2

        print(S)

    return


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque

S = deque()


def main():
    N = int(input())

    while N:
        if (abs(N % -2) == 1):
            S.appendleft('1')
            N -= 1
        else:
            S.appendleft('0')
        N //= -2

    if not S:
        S.append('0')

    print(''.join(list(S)))
    return


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = []
i=2
j=0
k = 0
while True:
    if k==n:
        break
    if (n-k)%i==0:
        ans.append(0)
    else:
        k += i>>1 if j%2==0 else -i>>1
        ans.append(1)
    i = i<<1
    j+=1

if n==0:
    print(0)
else:
    for i in ans[::-1]:
        print(i,end='')
    print()

Submission status: Accepted

Solution code:
def div_minus2(n: int)->tuple:
    """n を -2 で割ったときの商とあまりを計算する。
    """
    d = n // (-2)
    r = n % (-2)
    if r == -1:
        return d+1, 1
    return d, r


def base_2number(N: int) -> int:
    if N == 0:
        return '0'
    # N > 0
    s = ''
    while N != 0:
        d, r = div_minus2(N)
        N = d
        s = str(r) + s

    return s


if __name__ == "__main__":
    N = int(input())
    ans = base_2number(N)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import bisect
N = int(input())
right = 0
left = 0
length = 0
for i in range(34):
    if N in [0,1]:
        break
    if (-2) ** i + left <= N and N <= (-2) ** i + right:
        length = i + 1
        break
    if i % 2 == 0:
        right += (-2) ** i
    else:
        left += (-2) ** i
ans = []
def bi(arr):
    if len(ans) >= length:
        return
    if (length-len(ans)) % 2 == 0:
        if bisect.bisect_right(arr,N) > len(arr)//2:
            ans.append(0)
            bi(arr[len(arr)//2:])
        else:
            ans.append(1)
            bi(arr[:len(arr)//2])
    else:
        if bisect.bisect_right(arr,N) > len(arr)//2:
            ans.append(1)
            bi(arr[len(arr)//2:])
        else:
            ans.append(0)
            bi(arr[:len(arr)//2])

if N == 0:
    print(0)
elif N == 1:
    print(1)
else:
    ans.append(1)
    bi(range((-2) ** (length-1) + left , (-2) ** (length-1) + right +1))
    ans = map(str, ans)
    print("".join(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ans = []
if N == 0:
    print(0)
    exit()
while not(N==0):
    a = -(N%(-2))
    b = (N-a)//(-2)
    N = b
    ans.append(str(a))
ans = [ans[-i-1] for i in range(len(ans))]
print("".join(ans))

Submission status: Accepted

Solution code:
n = int(input())
ans=[]
if n==0:
    print(0)
    exit()
while not(n==0):
    amari=-(n%(-2))
    shou=(n-amari)//(-2)
    n=shou
    ans.append(str(amari))
ans=[ans[-i-1] for i in range(len(ans))]
print(''.join(ans))

Submission status: Accepted

Solution code:
N=int(input())

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

    print("1"+ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    if N == 0:
        return 0
    ans = ''
    plusvalue = True
    plusbit = True
    if N < 0:
        N = -N
        plusvalue = False
    c = 0
    while N != 0 or c == 1:
        b = (N & 1) + c
        if b < 2:
            c = 0
        else:
            b -= 2
            c = 1
        N >>= 1
        if b == 0:
            ans = '0' + ans
        else:
            if plusvalue:
                ans = '1' + ans
                if not plusbit:
                    c += 1
            else:
                ans = '1' + ans
                if plusbit:
                    c += 1
        plusbit = not plusbit
    return ans

print(solve())

Submission status: Accepted

Solution code:
n=int(input())

def hoge(x):
    if x%2==0:
        return x//(-2),0
    else:
        return x//(-2)+1,1


def base10_to_minus2(x):
    shou,amari=hoge(x)
    if shou:
        return base10_to_minus2(shou)+str(amari)
    return str(amari)

print(base10_to_minus2(n))

Submission status: Accepted

Solution code:
N=int(input())
S=''

if N==0 or N==1:
  S=str(N)
else:
  while N!=1:
    if N%(-2)==-1:
      N=N//(-2)+1
      remainder=1
    else:
      N=N//(-2)
      remainder=0
    S=str(remainder)+S
    if N==1:
      S='1'+S

print(S)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(S)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    ans = ""
    while N != 0:
        tmp = (-2) ** len(ans)
        if N % (tmp*-2) == 0:
            ans = "0" + ans
        else:
            ans = "1" + ans
            N -= tmp
    if ans == "":
        ans = "0"
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

s = ""

while n != 0:
	s = str(n%2) + s
	n = -(n//2)

print(s if s != "" else 0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
import sys


def solve(N):
  N_str = ''
  if N == 0:
    return('0')

  while(N != 0):
    r = N % 2
    if r < 0:
      r += 2
    N = (N-r)//(-2)
    N_str += str(r)
  return(N_str[::-1])


if __name__ == "__main__":
  N = int(sys.stdin.readline().rstrip())
  print(solve(N))

Submission status: Accepted

Solution code:
n = int(input())
amari = ""

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

while n :
    if n%2 == 1:
        amari += "1"
        n -= 1
    else:
        amari += "0"
    n = n//-2
    
print(amari[::-1])

Submission status: Accepted

Solution code:
n=int(input())
#print(n)
s=''
k=1
if n==0:
    s='0'
else:
    while n!=0:
        if abs(n)%abs((-2)**k)!=0:
            n-=(-2)**(k-1)
            s='1'+s
        else:
            s='0'+s
        k+=1
    
print(s)

Submission status: Accepted

Solution code:
n=int(input())
s=''
while n != 0:
    s = str( n % 2 ) + s
    n = - ( n // 2 )
print(s*(s != '') or 0)

Submission status: Accepted

Solution code:
N = int(input())
dig = []
def dmod(a, b):
  if a % b < 0:
    return [1, a//b+1]
  else:
    return [a%b, a//b]
while abs(N) > 1 :
  d, N = dmod(N, -2)
  dig.append(d)
if N == -1:
  dig += [1, 1]
else:
  dig.append(N)
dig.reverse()

n = ''.join(map(str, dig))
print(int(n))

Submission status: Accepted

Solution code:
N = int(input())
A = [[0,1] for _ in range(31)]
a = 1
for i in range(1,31):
    a *= -2
    A[i][0] = A[i-1][0] + min(0,a)
    A[i][1] = A[i-1][1] + max(0,a)
a = 1
for i in range(0,31):
    a *= -2
    A[i][0] += a
    A[i][1] += a
A = [[1,1]] + A
A = A[:32]

def main():
    if N==0:
        return '0'
    s = ''
    n = N
    flg = False
    for i in range(31, -1, -1):
        if A[i][0]<=n and n<=A[i][1]:
            s += '1'
            n -= (-2)**i
            flg = True
        else:
            if flg:
                s += '0'
    return s

print(main())

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  ans = ''
  if N == 0:
    ans = '0'
  else:
    while N != 0:
      if N % 2 == 0:
        ans = '0' + ans
        N //= -2
      else:
        ans = '1' + ans
        N = (N - 1) // -2
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

s = ''
flag = True
while flag:
    if n % 2 != 0:
        s = '1' + s
        n -= 1
    else:
        s = '0' + s
    n /= -2
    if n == 0:
        flag = False
print(s)

Submission status: Accepted

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

if S=="":
    S="0"

print(S)

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce

n = int(input())

X = 35
i = np.arange(X, dtype=np.int64)[::-1]
# 別法：i = np.flip(np.arange(X))

i = (-2)**i

ans = np.zeros(X, dtype=np.int64)

for digit in range(X):

	i[digit]
	sum_of_opposite = i[digit+1::2].sum() # 反対符号の和

	if i[digit] > 0 and i[digit] + sum_of_opposite > n:
		ans[digit] = 0
	elif i[digit] < 0 and i[digit] + sum_of_opposite < n:
		ans[digit] = 0
	else:
		ans[digit] = 1
		n -= i[digit]

# ansの先頭の0を削除して、桁をつなげる
print(int(reduce(lambda x, y: str(x) + str(y), ans)))

Submission status: Accepted

Solution code:
n=int(input())
s=abs(n)
c=""
if n==0:
    print("0")
else:
    while n:
        c+=str(n%2)
        n-=1
        n//=(-2)
print(c[::-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import permutations


class Solver(object):
    def __init__(self):
        self.n = int(input())

    def solve(self):
        number_string = ""
        n = -self.n
        while True:
            remainder = abs(n % (-2))
            number_string = str(remainder) + number_string
            quotient = n // (-2)
            if quotient == 0:
                break
            n = quotient
        if (number_string == "") or (number_string == "0"):
            print("0")
        else:
            print(number_string.lstrip("0"))


if __name__ == "__main__":
    s = Solver()
    s.solve()

Submission status: Accepted

Solution code:
#n=(-2)*?+0or1をして、?を新たなnとする。出てきたあまりを逆にたどれば答え
n=int(input())
L=[]
if n==0:
    print('0')
else:
# if が多数あるときelifでないと計算がおかしくなる
    while n!=0:
        if n>0 and n%2==0:
            n=-n//2
            L.append('0')
        elif n>0 and n%2==1:
            n=(-n+1)//2
            L.append('1')
        elif n<0 and -n%2==0:
            n=-n//2
            L.append('0')
        elif n<0 and -n%2==1:
            n=(-n+1)//2
            L.append('1')
    print(int(''.join(L[::-1])))

Submission status: Accepted

Solution code:
n=int(input())
L=[]
if n==0:
    print('0')
else:    
    while n!=0:
        if n>0 and n%2==0:
            n=-n//2
            L.append('0')
        elif n>0 and n%2==1:
            n=(-n+1)//2
            L.append('1')
        elif n<0 and -n%2==0:
            n=-n//2
            L.append('0')
        elif n<0 and -n%2==1:
            n=(-n+1)//2
            L.append('1')
    print(int(''.join(L[::-1])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

po_lst = [0]
a = 0
for i in range(0, 33, 2):
    a += 2**i
    po_lst.append(a)

ne_lst = [0]
a = 0
for i in range(1, 33, 2):
    a += (-2)**i
    ne_lst.append(a)

if n == 0:
    max_index = 0
elif n > 0:
    for k, i in enumerate(po_lst):
        if n < i:
            max_index = 2*(k-1)
            break
else:
    for k, i in enumerate(ne_lst):
        if n > i:
            max_index = 2*k-1
            break

def calcu(a, index, ans, po_lst, ne_lst):
    if index == -1:
        return ans
    elif a == 0:
        ans += '0'
        return calcu(a, index-1, ans, po_lst, ne_lst)
    else:
        b = (-2)**index
        if b > 0:
            k = (index // 2) + 1
            if a > po_lst[k-1]:
                a -= b
                ans += '1'
            else:
                ans += '0'
        else:
            k = (index+1) // 2
            if a < ne_lst[k-1]:
                a -= b
                ans += '1'
            else:
                ans += '0'
        return calcu(a, index-1, ans, po_lst, ne_lst)

print(calcu(n, max_index, '', po_lst, ne_lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
if n == 0:
    print(0)
    exit()
    
ans = ''
while abs(n) > 0:
    if n % 2 == 0:
        n //= (-2)
        ans += '0'
    else:
        n -= 1
        n //= (-2)
        ans += '1'

print(ans[::-1])

Submission status: Accepted

Solution code:
a=int(input());s=''
while a!=0:s=str(a%2)+s;a=-(a//2)
print(s if s != '' else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = ''
if (n == 0):
  s = '0'
while(n != 0):
  bit = abs(n) % 2
  s = str(bit) + s
  n -= bit
  n //= -2
print(s)

Submission status: Accepted

Solution code:
def r(k):
    if k == -1:
        return 0, 0
    if k == 0:
        return 0, 1
    else:
        low, high = r(k - 1)
        d = pow(-2, k)
        if d < 0:
            return low + d, high
        else:
            return low, high + d


def solve(N):
    if N == 0:
        return "0"
    ar = []
    for k in range(50, -1, -1):
        low1, high1 = r(k - 1)
        low2, high2 = r(k)
        if not (low1 <= N <= high1) and low2 <= N <= high2:
            ar.append("1")
            N -= pow(-2, k)
        else:
            ar.append("0")
    ans = "".join(ar)
    ans = ans[ans.find("1"):]
    return ans


if __name__ == "__main__":
    N = int(input())
    print(solve(N))

Submission status: Accepted

Solution code:
N = int(input())
s = ""
while N != 0:
    s = str(N%2)+s
    N = - (N//2)

print(s * (s != "") or 0)

Submission status: Accepted

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)

    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:
            #     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

    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)


    for e,s in enumerate(lst):
        if s >= 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

    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: Accepted

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))
    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: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
def inpl(): return list(map(int, input().split()))

#### START
N = int(input())

ans = ""
cnt = 0

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

if ans=="":
  ans = "0"
print(ans)