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:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  s = 0
  ans = []
  for i in range(30):
    if (n - s) % (2**(i+1)) == 0:
      ans.append('0')
    else:
      ans.append('1')
      s += ((-2) ** i)
    if s == n:
      break
  print(''.join(ans[::-1]))
    
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def get_ans():
    n = int(input().rstrip())
    dv = 1
    bit_list = []
    while n != 0:
        tmp = n % (dv*2)
        if tmp == 0:
            bit_list.append("0")
        else:
            bit_list.append("1")
        n -= tmp
        dv *= -2
    return "".join(reversed(bit_list))


print(get_ans())

Submission status: Wrong Answer

Solution code:
n = int(input())

a = []
while n != 0:
    if n%2 == 0:
        a.append(0)
    else:
        a.append(1)
        n -= 1
    n//=(-2)
    
if n == 0:
    print(0)
else:
    print(''.join(map(str, a[::-1])))

Submission status: Wrong Answer

Solution code:
a = int(input(""))
list = []
while(a):
    if(a%(-2)==0):
        list.append(0)
        a//=-2
    elif(a%(-2)==-1):
        list.append(1)
        a -= 1
        a//=-2

list.reverse()
for i in list:print(i,end='')
print()

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=''
while N:
  ans=str(N%2)+ans
  N//=(-2)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())

kp=-10
km=10
k=0
while not(km<=n and n<=kp):
    k=k+1
    km=-int(2*(4**k-1)/(4-1))
    kp=int((4**k-1)/(4-1))
    print("n=",n,"k=",k,"km=",km,"kp=",kp)        
#print("n=",n,"n-km=",n-km)

n=n-km

v=""
for kk in range(k):
    np=n//4**(k-kk-1)
    n=n-np*4**(k-kk-1)
    if np==0:
        v=v+"10"
    elif np==1:
        v=v+"11"
    elif np==2:
        v=v+"00"
    elif np==3:
        v=v+"01"
#print("v=",v)

if len(v)>0 and v[0]=="0":
    v=v[1:]
if len(v)>0:
    print(v)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())

#n=-9
#ans=1011

#n=123456789
#ans=11000101011001101110100010101
#ans="01 10 00 10 10 11 00 11 01 11 01 00 01 01 01"

#n=4

#n=0
#ans=0

kp=0
km=0
k=0
while not(km<=n and n<=kp):
    k=k+1
    km=-int(2*(4**k-1)/(4-1))
    kp=int((4**k-1)/(4-1))
#    print("n=",n,"k=",k,"km=",km,"kp=",kp)        
#print("n=",n,"n-km=",n-km)

n=n-km
#s=[]
#t=[]
u=""
while n>0:
    n0=n
    n=n//4
    n2=n0%4
#    n1=n0-n*4
#    print(n0,n,n2)
#    s.append(n2)
    if n2==0:
#        t.append("10")
        u="10"+u
    elif n2==1:
#        t.append("11")
        u="11"+u
    elif n2==2:
#        t.append("00")
        u="00"+u
    elif n2==3:
#        t.append("01")
        u="01"+u
        
if len(u)>0:
    while u[0]=="0":
        u=u[1:]

#s.reverse()    
#print(s)
#t.reverse()    
#print(t)
print(u)
#print(ans)

Submission status: Wrong Answer

Solution code:
LOWER, UPPER = range(2)
n = 0
bounds = [0] * 32
for digit in range(32):
    n = (n << 1) | (digit & 1)
    bounds[digit] = [-(n >> (digit & 1)), n >> (not (digit & 1))]

N = int(input())

answer = 0
n = -(1 << digit)

while digit:
    answer <<= 1
    n = (-1) * n >> 1
    if bounds[digit][LOWER] <= N < bounds[digit - 1][LOWER] or \
        bounds[digit - 1][UPPER] < N <= bounds[digit][UPPER]:
        answer |= 1
        N -= n
    digit -= 1

print(format(answer, "b"))

Submission status: Wrong Answer

Solution code:

if __name__ == '__main__':
    N=int(input())
    ans=[]
    while N:
        ans.append(str(N%2))
        N=-(N//2)
    ans.reverse()
    print("".join(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

def base_minus_two_num(digit, ans, total):
    if total == N:
        print(ans)
        exit()
    if digit == 0:
        return
    tmp = total + math.pow(-2, digit - 1)
    if abs(N - tmp) < abs(math.pow(-2, digit - 1)):
        base_minus_two_num(digit - 1, ans + '1', total + math.pow(-2, digit - 1))
    base_minus_two_num(digit - 1, ans + '0', total)

N = int(input())

if N == 0:
    print(0)
    exit()
elif N < 0:
    p = 1
    num = math.pow(-2, p)
    while num > N:
        p += 2
        num += math.pow(-2, p)
else:
    p = 0
    num = math.pow(-2, p)
    while num < N:
        p += 2
        num += math.pow(-2, p)

base_minus_two_num(p, '1', math.pow(-2, p))

Submission status: Wrong Answer

Solution code:
s=int(input())
s=0
x=s
list=[]
for i in range(1000000000000000000):
    y=x%(-2)
    if y == -1:
        x = (x-1)//(-2)
        y = 1
    else:
        x=x//(-2)
    list.insert(0, y)
    if x == 0:
        print(*list, sep="")
        break

Submission status: Wrong Answer

Solution code:
S=str(bin(abs(int(input()))))
print(S[2:])

Submission status: Wrong Answer

Solution code:
S=str(bin(int(input())))
if S[0]=="-":
    print(S[3:])
else:
    print(S[2:])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
s=""
while n:
    print(n)
    s=str(n&1)+s
    n=-(n>>1)
    print(s)
print(s if s else 0)

Submission status: Wrong Answer

Solution code:
a=int(input())
print(bin(-(a-2))[2:])

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = ''

while n != 0:
    r = n % 2 

    if r < 0:
        r = r + 2
    
    n = (n-r) / (-2)

    ans = ans + str(int(r))

ans = list(ans)    
ans.reverse()
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = ''

while n != 0:
    r = n % 2 
    print(r)

    if r < 0:
        r = r + 2
    
    n = (n-r) / (-2)

    ans = ans + str(int(r))

ans = list(ans)    
print(ans)
ans.reverse()
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
d=-2
ans=[]
while N!=0:
    r=N%(d)
    if r<0:
        r+=2
    N=(N-r)//(d)
    ans.append(str(r))
    
print("".join(ans[::-1]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
i = 0
ans = []
while N != 0:
    i += 1
    if N % 2 == 0:
        N //= 2
        ans.append("0")
    else:
        if i % 2 == 1:
            N -= 1
            N //= 2
            ans.append("1")
        else:
            N += 1
            N //= 2
            ans.append("1")
print("".join(ans[::-1]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
N_abs = abs(N)
N_abs_bin = list(bin(N_abs))[2:]
n = len(N_abs_bin)
if N == 0:
    print(0)
    sys.exit()
ans = ["0"] * (n + 1)
if N > 0:
    flag = 0
else:
    flag = 1
for i in range(n):
    if N_abs_bin[::-1][i] == "1":
        if i % 2 == flag:
            ans[i] = "1"
        else:
            ans[i], ans[i+1] = "1", "1"
ans = ans[::-1]
while ans[0] == "0":
    ans.pop(0)
print("".join(ans))

Submission status: Wrong Answer

Solution code:
from math import log2

def main():
    N = int(input())
    if N == 0:
        print(0)
        return
    Ans = []
    while N !=  1:
        r = N%2
        Ans.append(r)
        N = -1*( N // 2)
    print(*Ans[::-1],sep="")
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import log2

def main():
    N = int(input())
    if N == 0:
        print(0)
        return
    K = int(log2(abs(N))) + 1
    Ans = []
    for _ in range(K):
        r = N%2
        Ans.append(r)
        N = -1*( N // 2)
    print(*Ans[::-1],sep="")
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import log2

def main():
    N = int(input())
    if N <= 0:
        print(0)
        return
    K = int(log2(abs(N))) + 1
    Ans = []
    for _ in range(K):
        r = N%2
        Ans.append(r)
        N = -1*( N // 2)
    print(*Ans[::-1],sep="")
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

	n += n % -2
	n /= -2
	n = int(n)

print(''.join([str(i) for i in reversed(ans)]))

Submission status: Wrong Answer

Solution code:
N = int(input())
tmp = []
if(N == 0):
  print('0')
else:
  N = N // 2
  while(abs(N)>1):
    tmp.append(N%2)
    N = N // 2
  tmp.append(1)
tmp.reverse()
print(''.join([str(n) for n in tmp]))

Submission status: Wrong Answer

Solution code:
N = input()
ans = 'Yes'
if N.isdecimal():
    ans = 'No'
    N = int(N)

    A = N % 4
    B = N % 7
    C = N % 11

    if A == 0:
        ans = 'Yes'
    elif B == 0:
        ans = 'Yes'
    elif C == 0:
        ans = 'Yes'
    elif C == 4:
        ans = 'Yes'
    elif C == 7:
        ans = 'Yes'
    elif C == 8:
        ans = 'Yes'
print(ans)

Submission status: Wrong Answer

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

print(ans[::-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

mbits = []

while abs(n) > 0:
    mbits.append(n % 2)
    n = n // 2 * (-1)

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

Submission status: Wrong Answer

Solution code:
import sys

n = int(sys.stdin.readline().rstrip())

def base_convert(n, b):
    res = ''
    while n:
        r = abs(n % b)
        res = str(r) + res
        n = (n - r) // b

    return int(res) if res else 0

def main():
    return base_convert(n, 3)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc105/tasks/abc105_c
# -2進数
# 前に考えたときはわからなかったけど、数式イジイジしたら解けた


N = int(input())
ans = ''

while N != 0:
    if N & 1:  # 奇数ならbitが立つのは共通する性質
        ans += '1'
        N /= -2
        if N > 0:
            N += 1
        N = int(N)
    else:
        ans += '0'
        N //= -2


print(ans[::-1])

Submission status: Wrong Answer

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

if x=="":
    print(0)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
import math

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

bits = []
for keta in range(int(math.log2(abs(N))) + 1)[::-1]:
    if keta % 2 == 0:
        if N > 0:
            N -= 2**keta
            bits.append("1")
        else:
            bits.append("0")
    else:
        if N < 0:
            N += 2 ** keta
            bits.append("1")
        else:
            bits.append("0")


print("".join(bits))

Submission status: Wrong Answer

Solution code:
import math

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

bits = []
for keta in range(int(math.log2(abs(N))) + 1)[::-1]:
    if abs(N - (-2)**keta) <= abs(N):
        bits.append("1")
        N -= (-2)**keta
    else:
        bits.append("0")


print("".join(bits))

Submission status: Wrong Answer

Solution code:
import math

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

bits = []
for keta in range(int(math.log2(abs(N))) + 1)[::-1]:
    print(N, keta)
    if abs(N - (-2)**keta) <= abs(N):
        bits.append("1")
        N -= (-2)**keta
    else:
        bits.append("0")


print("".join(bits))

Submission status: Wrong Answer

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

chinpo = 1

while True:
    if n==0:
        break
    if n%2 != 0:
        n -=1
        list1.append(1)
    else:
        list1.append(0)
    n /= -2

list1.reverse()
print("".join(map(str,list1)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = ""
while N != 0:
    # 下の桁から求めていく
    r = N % 2
    if r < 0:
        r += 2
    N = (N-r) // (-2)
    ans += str(r)
print(ans[::-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
ls=[]
while N!=0:
  ls.append(N%2)
  N=-(N//2)
ls.reverse()
print(*ls,sep="")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(n):
    v = 0
    for i in range(30):
        if 1 << i & n:
            v += (-2)**i
    return v

@mt
def slv(N):
    v = N
    for i in range(30):
        b = 1 if 1 << i & v > 0 else 0
        if b and i % 2 != 0:
            v += 1 << (i+1)

    return v


def main():
    N = read_int()
    print(bin(slv(N))[2:])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    L = [(0, 1), (-2, 1)]
    for leng in range(2, 17):
        min_v = (-2*(4**(leng+(2-1)//2) - 1))//3
        max_v = (4**(leng+(2-1)//2) - 1)//3
        L.append((L[-1][0], max_v))
        L.append((min_v, max_v))
    # print(*L, sep='\n')
    S = [(0, 1)]
    for leng in range(1, 32):
        if leng & 1:
            S.append((L[leng][0], L[leng-1][0]-1))
        else:
            S.append((L[leng-1][1]+1, L[leng][1]))
    # print(*S, sep='\n')
    ans = ["0"] * 32
    cnt = 31
    for le, ri in S[::-1]:
        if ri < le:
            le, ri = ri, le
        if le <= N <= ri:
            ans[cnt] = "1"
            N -= (-2)**cnt
        cnt -= 1
    print(int("".join(ans[::-1])))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
bit = []
while N != 0:
    bit.append(str(abs(N % 2)))
    N = (N - N % 2) // (-2)
bit.reverse()
print("".join(bit))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
number = int(input())

def to_bin(n):
    if n == 0:
        return 0
    
    digits = []
    i = 0
    base = 1
    while n != 0:
        print(i, n, base, digits)
        if n % (base * 2) == 0:
            digits.append('0')
        else:
            digits.append('1')
            n -= base
        i+= 1
        base *= -2
    return digits[::-1]

print(to_bin(number))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = ''
for i in range(30):
    if n % 2 == 0:
        ans = '0' + ans
    else:
        ans = '1' + ans
        n -= 1
    n //= -2

print(int(ans))

Submission status: Wrong Answer

Solution code:
def main():
    n=int(input())
    ans=[]
    while n != 0:
        MOD=n%(-2)
        if MOD <0:
            MOD+=2
        ans.append(str(MOD))
        n=(n-MOD)//(-2)
    ans.reverse()
    print(''.join(ans))

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
s=""

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

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
s=""

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

Submission status: Wrong Answer

Solution code:
N = int(input())
Nb = str(bin(N))
if Nb[0] == "-":
    print(Nb[3:])
else:
    print(Nb[2:])

Submission status: Wrong Answer

Solution code:
def judge(m,i):
    if m==1:
        return 1
    elif m>0:
        if m%(2**i)==0:
            return 0
        else:
            return 1
    else:
        m = -m
        if m%(2**i)==0:
            return 0
        else:
            return 1

def examC():
    n = I()
    N = copy.deepcopy(n)
    i = 0
    ans = []
    while(N!=0):
        cur = judge(N,i+1)
#        print(cur,N)
#        input()
        N -=((-2)**i)*cur
        ans.append(cur)
        i +=1
    print("".join(map(str,ans[::-1])))

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Wrong Answer

Solution code:
n = int(input())
pow_m2 = [1]
for i in range(100):
  pow_m2.append(pow_m2[-1]*-2)
div = 2
k = 0
bit_m2 = []
while div < 2 * n:
  if (n % div - k) // (div / 2) == 1:
    bit_m2.append('1')
  else:
    bit_m2.append('0')
  k = n % div
  div *= 2
print(''.join(reversed(bit_m2)))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
input = sys.stdin.readline

N = int(input().strip())
ans = deque([])
while N != 0:
    if N % -2 != 0:
        N -= 1
        ans.appendleft('1')
    else:
        ans.appendleft('0')
    N /= -2

print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())

ansl = []

while n:
    if n % -2 == 0:
        ansl.append("0")
    else:
        n -= 1
        ansl.append("1")
    n = n // -2

ansl.reverse()
print("".join(ansl))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    if n == 0:
        print(0)
    else:
        ans = []
        while n:
            if n % -2 == 0:
                ans.append("0")
                n //= -2
            else:
                ans.append("1")
                n //= -2
        ans.reverse()
        print("".join(ans))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
S = int(input())

num = ''
def division(N):
  if N%2==0:
    return N//-2,'0'
  else:
    return (N//-2)+1,'1'
  
while S!=0:
  a,b = division(S)
  num += b
  S = a

print(num[::-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
if (N>0):
    print(bin(N)[2:])
    exit()
N *= -1
digit = 0
for i in range(1, 40):
    if N < (1<<i) -1:
        # 2^n -1 だったら
        digit = i
        break
ans = ['0' for i in range(digit)]
if (N%2):
    ans[0] = '1'
    N += 1
for i in range(1, digit):
    ans[i] = str((N >> i) % 2)
ans.reverse()
print(''.join(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
Z = int(input())
n = (-2)

ans = ""

while abs(Z) >= 1:
  r = Z % n
  if r < 0:
    r = r + 2
  Z = int((Z - r) / n)
  ans += str(r)

ans = "".join(list(reversed(ans)))

if Z == 0:
  print(0)
else:
  print(int(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

ttl = n
ans = []

memo = -2
memo2 = 1

while(abs(ttl)>0):
    if ttl%memo != 0:
        ttl -= memo2
        ans.append(1)
    else:
        ans.append(0)

    memo *= (-2)
    memo2 *= (-2)

for i in range(1,len(ans)+1):
    print(ans[-i],end = "")
print()

Submission status: Wrong Answer

Solution code:
# print('input >>')
N = int(input())

rest = N
i = 0
ans_l = []

while not rest == 0:
    if rest % (-2)**(i+1) == 0:
        ans_l.append('0')
    else:
        ans_l.append('1')
        rest -= (-2)**i
    i += 1

# print('----------output----------')
ans = ''.join(ans_l[::-1])

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=""
while n: 
    rem=n%(-2)
    n=n//(-2)
    if(rem<0):
        rem+=2 
        n+=1 
    s=str(rem)+s 
print(s)

Submission status: Wrong Answer

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

N = int(input())
print(F(N))

Submission status: Wrong Answer

Solution code:
n = int(input())

def basen(n):
    a = []
    while n!= 0:
        r = n % 2
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
        if(a == " "):
            a.append(0)
    a.reverse()
    return "".join(map(str,a))
print(basen(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
def basen(n):
    a = []
    while n!= 0:
        r = n % 2
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
        if(a == " "):
            a.append(0)
        reversed(a)
    return "".join(map(str,a))
print(basen(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
def basen(n):
    a = []
    while n!= 0:
        r = n % 2
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
        if(a == " "):
            a.append(0)
        reversed(a)
    return a
print(basen(n))

Submission status: Wrong Answer

Solution code:
n = int(input())
res = ""
cnt = 0
div = 0
while n != 0:
    div = n % 2**(cnt+1)
    div = 1 if div > 0 else 0
    res = str(div) + res
    if div > 0:
        n -= (-2) ** cnt
    cnt += 1
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())

ans = []

while abs(N) > 0:
    ans.append(abs(N) % 2)
    if N > 0:
        N //= 2
    else:
        N = (N // 2) * -1

if not len(ans):
    ans = [0]

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

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())
x = ''

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

print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
dp = [2**i if i % 2 == 0 else -2**i for i in range(32) ]

if n < 0 :
    plus_minus = 1
elif n > 0:
    plus_minus = 0
else:
    print(0)
    exit()

a = 0
for i in range(plus_minus,32,2):
    if abs(dp[i]) + abs(a) > abs(n):break
    a += dp[i]
s = "1"

if plus_minus == 1:
    b = dp[i]
    for j in range(i-1,-1,-1):
        if j % 2 == 0:
            if (b + dp[j]) + a <= n:
                s += "1"
                b += dp[j]
            else: s += "0"
        else:
            if b > n:
                s += "1"
                b += dp[j]
                a += dp[j]
            else:
                s += "0"
                a += dp[j]
else:
    b = dp[i]
    for j in range(i-1,-1,-1):
        if j % 2 == 1:
            if (b + dp[j]) + a >= n:
                s += "1"
                b += dp[j]
            else: s += "0"
        else:
            a -= dp[j]
            if b + a < n:
                s += "1"
                b += dp[j]
            else:
                s += "0"
print(s)

Submission status: Wrong Answer

Solution code:
import math
import sys


n = int(input())
if n == 0:
  print(0)
  sys.exit()
  
nn = math.floor(math.log2(abs(n)))
keta = 0
under = 0
s = ""

if n > 0:
    if n <= sum([2**i for i in range(0,nn+1,2)]):
        keta = nn+1
        under = sum([2**i for i in range(0,nn,2)])
    else:
        keta = nn+3
        under = sum([2**i for i in range(0,nn+1,2)])

    for i in range(1,keta):
        remainder = (n-under)%(2**i)
        if remainder in range(1,2**(i-1)+1):
            s += "0" if i%2==1 else "1"
        else:
            s += "1" if i%2==1 else "0"
    else:
        s+="1"
    print(s[::-1])

else:
    if n >= sum([(-2)**i for i in range(1,nn+1,2)]):
        keta = nn+1
        under = sum([(-2)**i for i in range(1,nn-1,2)])
    else:
        keta = nn+3
        under = sum([(-2)**i for i in range(1,nn+1,2)])
    for i in range(1,keta):
        remainder = abs(n-under)%(2**i)
        if remainder in range(1,2**(i-1)+1):
            s += "1" if i%2==1 else "0"
        else:
            s += "0" if i%2==1 else "1"
    else:
        s+="1"
    print(s[::-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
res = []
while N != 0:
    if N % -2 != 0:
        res.append("1")
    else:
        res.append("0")
    
    if N == 1:
        break

    if N % -2 != 0:
        N -= 1
    N //= -2

print("".join(reversed(res)))

Submission status: Wrong Answer

Solution code:
import math
import copy
import sys
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

# n, k = map(int, input().split())
n = getInputInt()

ansketa = []

def searchN(plus, n):
    point = 0
    if plus == 1:
        flg = True
        i = 0
        while(flg):
            if n < pow(-2, i):
                point = i
                flg = False
            i+=1

    else:
        flg = True
        i = 0
        while(flg):
            if abs(n) < abs(pow(-2, i)):
                point = i-1
                flg = False
            i+=1

    return point

plumi = 0
if n >= 0:
    plumi = 1

point = searchN(plumi, n)

sumnum = pow(-2, point)
ansketa.append(point)

for i in range(point-1, -1, -1):
    tmpsumnum = sumnum+pow(-2, i)
    if abs(n - tmpsumnum) <= abs(n - sumnum):
         ansketa.append(i)
         sumnum += pow(-2, i)

ans = 0
if len(ansketa) == 0:
    ans = 0
else:
    for i in range(len(ansketa)):
        ans+=pow(10, ansketa[i])

print(ans)

Submission status: Wrong Answer

Solution code:
def neg_bin(N):
  num = N
  val = float('inf')
  
  while 1:
    bin_num = bin(num)[2:]
    len_bin_num = len(bin_num)

    bin_num1 = ''
    for i in range(0,len_bin_num,2):
      bin_num1 = bin_num1 + bin_num[i] + '0'

    bin_num2 = ''
    for i in range(1,len_bin_num,2):
      bin_num2 = bin_num2 + '0' + bin_num[i]
    
    if - int(bin_num1,2) + int(bin_num2,2) == -N:
      #print(num, bin_num, bin_num1, bin_num2)
      return bin_num
    else:
      num += 1

N = int(input())
print(bin(N)[2:] if N >= 0 else neg_bin(-N))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = ''
while(N != 0):
  r = N % 2
  ans += str(r)
  N = (N-r) // (-2)
  #print(N,r)
print(''.join(reversed(ans)))

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[]
while abs(n)>0:
	if n>0:
		r=n%2
		n=-(n//2)
	else:
		r=(-n)%2
		n=(-n)//2
		if r==1:
			n+=1
	L.append(r)
print(''.join(map(str,L[::-1])))

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = ""
while n != 0:
    ans = str(n % 2) + ans
    n = - (n // 2)
if 0 == n:
    ans = "0"
print("".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = ""
while n != 0:
    ans = str(n % 2) + ans
    n = - (n // 2)
print("".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = []
while abs(n) > 0:
    ans.append(n % 2)
    n = - (n // 2)
ans.reverse()
print("".join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=[]
while N!=0:
    x=N%2
    N=(N-x)//-2
    ans.append(x)
ans.reverse()
print(*ans,sep='')

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
for i in range(10**10):
    if N == 0:
        break
    if N%2 == 1:
        ans.append("1")
        N -= (-1)**(i)
    else:
        ans.append('0')
    N = N // 2

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