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:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    if N == 0:
        print(0)
        exit()
    if N < 0:
        N = -N
        D = defaultdict(int)
        index = 0
        while N >= 1:
            #bitフラグがたっていたら
            if N & 1 == 1:
                #2の倍数の場合D[index]とD[index+1]に1を足す
                if index % 2 == 0:
                    D[index] += 1
                    D[index+1] += 1
                else:
                    D[index] += 1
            else:
                D[index] = D[index]
            N = N>>1
            index += 1
    else:
        D = defaultdict(int)
        if N & 1 == 1:
            D[0] = 1
        else:
            D[0] = 0
        index = 1
        N = N >> 1

        while N >= 1:
            #bitフラグがたっていたら
            if N & 1 == 1:
                #2の倍数の場合D[index]とD[index+1]に1を足す
                if index % 2 == 1:
                    D[index] += 1
                    D[index+1] += 1
                else:
                    D[index] += 1
            else:
                D[index] = D[index]
            N = N>>1
            index += 1
            
            
    index = 0
    while True:
        if not index in D.keys():
            break
        if D[index] <= 1:
            pass
        else:
            temp = D[index]
            D[index] = temp % 2
            D[index+1] = temp // 2
            D[index+2] = temp // 2
        index += 1

    for i in reversed(D.values()):
        print(i, end="")
    print()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    if N == 0:
        print(0)
        exit()
    if N < 0:
        N = -N
        D = defaultdict(int)
        index = 0
        while N >= 1:
            #bitフラグがたっていたら
            if N & 1 == 1:
                #2の倍数の場合D[index]とD[index+1]に1を足す
                if index % 2 == 0:
                    D[index] += 1
                    D[index+1] += 1
                else:
                    D[index] += 1
            else:
                D[index] = D[index]
            N = N>>1
            index += 1
    else:
        D = defaultdict(int)
        if N & 1 == 1:
            D[0] = 1
        else:
            D[0] = 0
        index = 1
        N = N >> 1

        while N >= 1:
            #bitフラグがたっていたら
            if N & 1 == 1:
                #2の倍数の場合D[index]とD[index+1]に1を足す
                if D[index] == 1:
                    D[index] += 1
                    D[index+1] += 1
                else:
                    D[index] += 1
                    D[index+1] += 1
            else:
                D[index] = D[index]
            N = N>>1
            index += 1
    index = 0
    while True:
        if not index in D.keys():
            break
        if D[index] <= 1:
            pass
        else:
            temp = D[index]
            D[index] = temp % 2
            D[index+1] = temp // 2
            D[index+2] = temp // 2
        index += 1

    for i in reversed(D.values()):
        print(i, end="")
    print()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N = I()
    if N == 0:
        print(0)
        exit()
    if N < 0:
        N = -N
        D = defaultdict(int)
        index = 0
        while N >= 1:
            #bitフラグがたっていたら
            if N & 1 == 1:
                #2の倍数の場合D[index]とD[index+1]に1を足す
                if index % 2 == 0:
                    if D[index] == 1:
                        D[index] = 0
                        D[index+1] = D[index+1]
                        D[index+2] = 1
                    else:
                        D[index] = 1
                        D[index+1] = 1
                else:
                    if D[index] == 1:
                        D[index] = 0
                        if D[index+1] == 1:
                            D[index+1] = 0
                            D[index+2] = 1
                        else:
                            D[index+1] = 1
                    else:
                        D[index] = 1
            else:
                D[index] = D[index]
            N = N>>1
            index += 1
    else:
        D = defaultdict(int)
        if N & 1 == 1:
            D[0] = 1
        else:
            D[0] = 0
        index = 1
        N = N >> 1

        while N >= 1:
            #bitフラグがたっていたら
            if N & 1 == 1:
                #2の倍数の場合D[index]とD[index+1]に1を足す
                if index % 2 == 1:
                    if D[index] == 1:
                        D[index] = 0
                        D[index+1] = D[index+1]
                        D[index+2] = 1
                    else:
                        D[index] = 1
                        D[index+1] = 1
                else:
                    if D[index] == 1:
                        D[index] = 0
                        if D[index+1] == 1:
                            D[index+1] = 0
                            D[index+2] = 1
                        else:
                            D[index+1] = 1
                    else:
                        D[index] = 1
            else:
                D[index] = D[index]
            N = N>>1
            index += 1

    for i in reversed(D.values()):
        print(i, end="")
    print()

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
 
N = int(sys.stdin.readline())
if N == 0:
    print(0)
    sys.exit()
binN = ""
pN = abs(N)
while N != 0:
    if abs(N % -2) == 1:
        binN += "1"
    else:
        binN += "0"
    N //= -2
print(binN[::-1])

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline())
binN = ""
pN = abs(N)
while N != 0:
    if abs(N % -2) == 1:
        binN += "1"
    else:
        binN += "0"
    N += N%(-2)
    N //= -2
print(binN[::-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
while N!=0:
    if N%2==1:
        A.append("1")
        N -= 1
    else:
        A.append("0")
    N = N//(-2)
A = A[::-1]
print("".join(A))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    ans = ''
    base = 1
    while N != 0:
        if N % (base * -2) == 0:
            ans += '0'
        else:
            ans += "1"
            N -= base
        base *= -2
    ans = list(ans)
    ans.reverse()
    print(''.join(ans))

if __name__ == "__main__":
    main()

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 = n//(-2)
  
print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

import sys
import bisect

SUM_P = [2**x for x in range(0, 29, 2)]
SUM_M = [2**x for x in range(1, 29, 2)]
for i in range(len(SUM_P)-1):
    SUM_P[i+1] += SUM_P[i]
for i in range(len(SUM_M)-1):
    SUM_M[i+1] += SUM_M[i]


N = int(input())

ret = 0
while N != 0:
    if N > 0:
        idx = bisect.bisect_left(SUM_P, N)
        idx = idx * 2
        N -= 2 ** idx
        ret += 2**idx
    else:
        idx = bisect.bisect_left(SUM_M, abs(N))
        idx = (idx * 2) + 1
        N += 2 ** idx
        ret += 2**idx

print(format(ret, "b"))

Submission status: Wrong Answer

Solution code:
from decimal import Decimal
n = Decimal(input())
if n == 0:
  print(0)
  exit(0)
s = ""
while True:
  m = n % -2
  s = str(abs(m)) + s
  n = n // -2
  if n == 1 or n == 0:
    break
  elif m < 0:
    n += 1
print('1'+s)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 0:
  print(0)
  exit(0)
s = ""
while True:
  m = n % -2
  s = str(-m) + s
  n = n // -2
  if n == 1 or n == 0:
    break
  elif m != 0:
    n += 1
print('1'+s)

Submission status: Wrong Answer

Solution code:
N = int(input())

def base(x, n):
  ret = []
  while x != 0:
    ret.append( x % abs(n))
    if n < 0:
      x = - ( (-x)//n )
    else:
      x //= n
  return ret

print("".join(map(str, reversed(base(N, -2)))))

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=''
while n:
  ans+=str(n%2)
  n-=n%2
  n//=-2
print([''.join(ans[::-1]),0][n==0])

Submission status: Wrong Answer

Solution code:
n = int(input())

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

Submission status: Wrong Answer

Solution code:
n = int(input())

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

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==0:
    print(0)
    exit()
ans=''
for i in range(30):
    if n%(2**(i+1))!=0:
        n-=(-2)**i
        ans='1'+ans
    else:
        ans='0'+ans
    if n==0:
        break
if ans[0]!='0':
    print(ans)
else:
    print(ans[1:])

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = []
for i in range(10**5):
    if n == 0:
        break
    if n%pow(2,i+1) != 0:
        ans.append('1')
        n -= pow(-2,i)
    else:
        ans.append('0')
    

ans = ans[::-1]
ans_s = ''.join(ans)
print(ans_s)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
s = []

while N:
    r = N%(-2)
    if r<0:
        r+=2
    N = (N-r)//(-2)
    s.append(str(r))
print(''.join(s)[::-1])

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = abs(n)
for i in range(n > 0, 30, 2):
    if ans & (1 << i) == (1 << i):
        ans += (1 << (i + 1))
print(f'{ans:b}')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = ''
for i in range(30):
    r = n%2
    n = (n-r) // (-2)
    ans += str(r)
    if n==0:
        break
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
N=int(input())

if N >= 0:
  n = N
  b = bin(N)[2:]
  for i in range(len(b)):
    if i%2==1 and b[-i-1]=='1':
      n += 2**(i+1)
  print(bin(n)[2:])
  
else:
  n = -N
  b = bin(-N)[2:]
  for i in range(len(b)):
    if i%2==0 and b[-i-1]=='1':
      n += 2**(i+1)
  print(bin(n)[2:])

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
ans = deque()
i = 0
while n != 0:
    tmp = ( n % 2**(i+1) ) // 2**i
    ans.appendleft(tmp)
    n -= tmp * (-2)**i
    i += 1
print(*list(ans),sep="")

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
if n==0:
    print(0)
    exit()
elif n==1:
    print(1)
    exit()
def check(_n):        
    if _n>0:
        j=0
        while True:
            if pow(2,j)-2*(pow(2,j)-1)//3<=_n<=pow(2,j)+(pow(2,j)-1)//3:
                k=j
                break
            else:
                j+=2
    elif _n<0:
        j=1
        while True:
            if -1*pow(2,j)-2*(pow(2,j-1)-1)//3<=_n<=-1*pow(2,j)+(pow(2,j+1)-1)//3:
                k=j
                break
            else:
                j+=2
    else:
        return 0,0
    return _n-pow(-2,k),k
c=n
ans=0
while True:
    res=check(c)
    if res[0]==0:
        ans+=c
        break
    else:
        ans+=pow(10,res[1])
        c=res[0]
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    # n, m = [int(x) for x in input().split()]
    n = -int(input())
    ans = []
    while n != 0:
        n, m = divmod(n, -2)
        ans.append(-m)

    ans.reverse()
    print(''.join([str(x) for x in ans]))

        


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

"""

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list()
if N==0:
  print(0)
  exit()
elif N>0:
  while N>0:
    S.append(N%2)
    N//=2
  S.append(0)
  S.append(0)
  for i in range(len(S)-1):
    if i%2==1 and S[i]==1:
      S[i+1] += 1
    if S[i]==2:
      S[i]=0
      S[i+1]+=1
else:
  N *= -1
  while N>0:
    S.append(N%2)
    N//=2
  S.append(0)
  S.append(0)
  for i in range(len(S)-1):
    if i%2==0 and S[i]==1:
      S[i+1] += 1
    if S[i]==2:
      S[i]=0
      S[i+1]+=1
  
S.reverse()
if S[0]==0:
  S = S[1:]
ans = ""
for s in S:
  ans += str(s)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list()
if N==0:
  print(0)
  exit()
elif N>0:
  while N>0:
    S.append(N%2)
    N//=2
  S.append(0)
  for i in range(len(S)-1):
    if i%2==1 and S[i]==1:
      S[i+1] += 1
    if S[i]==2:
      S[i]=0
      S[i+1]+=1
else:
  N *= -1
  while N>0:
    S.append(N%2)
    N//=2
  S.append(0)
  for i in range(len(S)-1):
    if i%2==0 and S[i]==1:
      S[i+1] += 1
    if S[i]==2:
      S[i]=0
      S[i+1]+=1
  
S.reverse()
if S[0]==0:
  S = S[1:]
ans = ""
for s in S:
  ans += str(s)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans.reverse()
print(*ans, sep="")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def f(n):
	return (f(n/-2) if n/-2 != 0 else []) +[1 if n % 2 else 0] 

print ''.join(map(str,f(int(raw_input()))))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
def I():
    return int(sys.stdin.readline().rstrip())

N = I()

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

ANS = []
r = 0
while N != 0:
    for i in range(10**6):
        if -((2*(4**((i+1)//2)-1))//3) <= N <= (4*(4**(i//2)-1))//3+1:
            for j in range(r-i-1):
                ANS.append('0')
            ANS.append('1')
            r = i
            break
    N -= (-2)**r

print(''.join(ANS))

Submission status: Wrong Answer

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

if N == 0:
    print(0)
    exit()
ans = []
while N !=0:
    ans.append(N%2)
    N = -(N-N%2)//2
print("".join(list(map(str,ans))))

Submission status: Wrong Answer

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

ans = []
while N !=0:
    ans.append(N%2)
    N = -(N-N%2)//2
print("".join(list(map(str,ans))))

Submission status: Wrong Answer

Solution code:
N = int(input())
max_v = 1
min_v = 0
L = 1
mask = 1
while not (min_v <= N <= max_v):
    L += 1
    mask *= -2
    if mask < 0:
        min_v += mask
    else:
        max_v += mask

ans = []
for _ in range(L - 1):
    prev_max_v = max_v
    prev_min_v = min_v
    if mask < 0:
        min_v -= mask
    else:
        max_v -= mask
    if prev_max_v >= N > max_v or prev_min_v < N <= min_v:
        ans.append(1)
        N -= mask
    else:
        ans.append(0)
    mask //= -2
print("".join(map(str, ans)) + str(N))

Submission status: Wrong Answer

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

while N:
    ans = str(N % 2)+ans
    N = -(N//2)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

op_cnt = len(bin(abs(N)))-2

import numpy as np

two = [(-2)**i for i in reversed(range(op_cnt))]

for i in range(2 ** op_cnt):
    op = [0] * op_cnt  
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = 1 
    if sum(np.array(op)*two) == N:
        op = [str(i) for i in op]
        print("".join(op))
        break

Submission status: Wrong Answer

Solution code:

def solve():
    k = 0
    N = n
    ans = ""
    while N:
        k+=1
        if N % 2 == 1:
#            print("------\t" + str(N))
            N -= 1
            ans += "1"
        else:
            ans += "0"
        N //= (-2)  # n=-2 進数
#        print(N)
#    print(k)    #   桁数
    print(ans[::-1])
#    print(a[::-1])



if __name__=="__main__":
    n = int(input())
    solve()

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = 2
ans = ''

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = ""

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

print(ans[::-1] if n != 0 else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = []
a = n
while a != 0:
    b = a % (-2)
    a //= (-2)
    if b == -1:
        a += 1
        b = 1
    ans.append(b)

ans.reverse()    
print(*ans, sep='')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

if N == 0:
    print(0)
    exit()
elif N == 1:
    print(1)
    exit()
DP = [(0,1)]
num = 0
start = 0
end = 1
while True:
    num += 1
    a = end - start + 1
    if num % 2 == 0:
        start_ = end + 1
        end_ = start_ + a - 1
        end = end_
    else:
        end_ = start - 1
        start_ = end_ - a + 1
        start = start_
    DP.append((start_, end_))
    if start <= N <= end:
        break

Ans = ''
for i, (start, end) in enumerate(DP[::-1]):
    if start <= N <= end:
        Ans += '1'
        N -= (-2) ** (num-i)
    else:
        Ans += '0'

print(Ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

s = ""

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

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 0:
    print(0)
    exit()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ansl = []
while n != 0:
	if n % 2 == 1:
		ansl.append("1")
		n -= 1
	else:
		ansl.append("0")
	n //= -2
print("".join(ansl)[::-1])

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())


ans = []
of = 0


if N < 0:
    N = -N
    s = "00" + bin(N)[2:]
    l = len(s)
    for i in range(l):
        # 1010 = N + 0101
        of, b = of, int(s[l - i - 1])
        if i % 2 == 0:
            if (of, b) == (0, 0):
                ans.append(0)
                of = 0
            elif (of, b) == (0, 1):
                ans.append(1)
                of = 1
            elif (of, b) == (1, 0):
                ans.append(1)
                of = 1
            else:
                ans.append(0)
                of = 1
        else:
            if (of, b) == (0, 0):
                ans.append(0)
                of = 0
            elif (of, b) == (0, 1):
                ans.append(1)
                of = 0
            elif (of, b) == (1, 0):
                ans.append(1)
                of = 0
            else:
                ans.append(0)
                of = 1
    ans.reverse()
    pre_ans = "".join(list(map(str, ans)))
    print(pre_ans[pre_ans.find("1"):])

elif N > 0:
    s = "0" + bin(N)[2:]
    l = len(s)

    for i in range(l):
        # 10101 = N + 01010
        of, b = of, int(s[l - i - 1])
        if i % 2 == 0:
            if (of, b) == (0, 0):
                ans.append(0)
                of = 0
            elif (of, b) == (0, 1):
                ans.append(1)
                of = 0
            elif (of, b) == (1, 0):
                ans.append(1)
                of = 0
            else:
                ans.append(0)
                of = 1
        else:
            if (of, b) == (0, 0):
                ans.append(0)
                of = 0
            elif (of, b) == (0, 1):
                ans.append(1)
                of = 1
            elif (of, b) == (1, 0):
                ans.append(1)
                of = 1
            else:
                ans.append(0)
                of = 1
    ans.reverse()
    pre_ans = "".join(list(map(str, ans)))
    print(pre_ans[pre_ans.find("1"):])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())

cnt, now = 1, 0
ans = ''
for i in range(100):
    if n == now:
        break
    if (n - now) % (2**(i + 1)) != 0:
        ans = ans + '1'
        now += pow(-2, i)
    else:
        ans = ans + '0'
print(ans[::-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

s = ""
while abs(N) > 0:
    m = N % (-2)
    if m != 0:
        s = "1" + s
    else:
        s = "0" + s
    N = (N+m) // (-2)
    print(m, N)
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
K = [((-2)**k) for k in range(33)]


def reachable(diff, k):
    """
    現在のゴールとの差を考えて残りの係数で到達可能か判定
    :param diff: 目標への差(これだけ加算できれば辿り着ける)
    :param k: 現在の次数
    :return: True: 到達可能
    """
    if diff == 0:
        return True
    elif diff > 0:
        # kが偶数(正数)の項
        if k % 2 == 1:
            k -= 1
        rest = sum([K[i] for i in range(k, -1, -2)])
        return rest >= diff
    else:
        # kが奇数(負数)の項
        if k % 2 == 0:
            k -= 1
        rest = sum([K[i] for i in range(k, -1, -2)])
        return rest <= diff


def calc(goal, total, k, s):
    if k < 0:
        return s
    if not reachable(goal-total, k):
        return None

    r1 = calc(goal, total+K[k], k-1, s+"1")
    r2 = calc(goal, total, k-1, s+"0")
    if r1 is None and r2 is None:
        return None
    elif r1 is not None:
        return r1
    else:
        return r2


if N == 0:
    print("0")
else:
    s = calc(N, 0, 32, "")
    print(s[s.index("1"):])

Submission status: Wrong Answer

Solution code:
n=int(input())
if n==0:
  print(0)
  exit()
if n==1:
  print(1)
  exit()
ans=[]
while n!=1:
  r=n%(-2)
  ans.append(str(r))
  n=(n-r)//(-2)
ans.append(str(1))
ans.reverse()
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
n=int(input())

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

ans.reverse()

for i in ans:
    print(i,end='')

Submission status: Wrong Answer

Solution code:
n=int(input())

print(n%2)
ans=[]
while n!=0:
    r=n%2
    ans.append(r)
    n=int((n-r)/(-2))

ans.reverse()

for i in ans:
    print(i,end='')

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# ここから書き始める
n = int(input())
ans = ""
cnt = 0
if n == 0:
    print(0)
else:
    while True:
        # print("n =", n)
        if n == 0:
            break
        if n == -2 ** cnt:
            ans += "1"
            break
        if n % (-2) ** (cnt + 1) == 0:
            ans += "0"
        else:
            ans += "1"
            n -= (-2) ** cnt
        cnt += 1
        # if cnt == 4:
        #     break
    print(ans[::-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = ''

while N != 0 and N != 1:
    if N > 0:
        if N%2:
            ans += '1'
            N = -(N//2)
        else:
            ans += '0'
            N = -N//2
    else:
        if -N%2:
            ans += '1'
            N = -(N-1)//2
        else:
            ans += '0'
            N = N//(-2)
if N:
    ans += '1'
print(ans[::-1])

Submission status: Wrong Answer

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

def F(N):
  if(N == 0):
    return ''
  
  if(N % 2 == 0):
    return F(N//-2) + '0'
  else:
    return F((N-1)//-2) + '1'

print(F(N))

Submission status: Wrong Answer

Solution code:
n=int(input())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement, dropwhile
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

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

ans = []
for _ in range(10):
    r = n % 2
    if r < 0:
        r += 2
    n = (n-r) // (-2)
    ans.append(str(r))
print(int("".join(reversed(ans))))