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:
def mainusbin(num):
    base = -2
    dst = ""
    i = 0
    if abs(base) > num:
        return num
    while abs(base**i) <= num:
        i += 1
        amari = num % base**i
        if amari:
            dst = "1" + dst
            num -= base**(i-1)
        else:
            dst = "0" + dst
    return dst
src = int(input())
dst = mainusbin(src)
print(dst)

Submission status: Wrong Answer

Solution code:
#絶対値小さくできるか？
#振動しそうなので
from itertools import dropwhile
from collections import deque
n=int(input())
ans=deque([["",n]])
def bfs(d):
    global ans
    l=len(ans)
    for i in range(l):
        x=ans.popleft()
        new1=[x[0]+"0",x[1]]
        if abs(new1[1])<abs((-2)**d):
            ans.append(new1)
        new2=[x[0]+"1",x[1]-(-2)**d]
        if abs(new2[1])<abs((-2)**d):
            ans.append(new2)
    if d!=0:
        bfs(d-1)
bfs(30)
#全探索

for i in ans:
    if i[1]==0:
        ans=list(dropwhile(lambda x:x=="0",i[0]))
        if len(ans)==0:
            print(0)
        else:
            print("".join(ans))
        break

Submission status: Wrong Answer

Solution code:
#絶対値小さくできるか？
#振動しそうなので
from itertools import dropwhile
from collections import deque
n=int(input())
ans=deque([["",n]])
def bfs(d):
    global ans
    l=len(ans)
    for i in range(l):
        x=ans.popleft()
        new1=[x[0]+"0",x[1]]
        if abs(new1[1])<abs((-2)**d):
            ans.append(new1)
        new2=[x[0]+"1",x[1]-(-2)**d]
        if abs(new2[1])<abs((-2)**d):
            ans.append(new2)
    if d!=0:
        bfs(d-1)
bfs(29)
#全探索

for i in ans:
    if i[1]==0:
        ans=list(dropwhile(lambda x:x=="0",i[0]))
        if len(ans)==0:
            print(0)
        else:
            print("".join(ans))
        break

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    L = 100000

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

    s = 1 if N > 0 else -1
    n = abs(N)

    bit = [0] * L

    i = 0
    while n > 0:
        if n % 2:
            bit[i] += 1
            if s > 0 and i % 2 == 1 or s < 0 and i % 2 == 0:
                bit[i+1] += 1
        n //= 2
        i += 1

    for i in range(L-2):
        if bit[i] > 1:
            bit[i+2] += bit[i] // 2
            bit[i+1] += bit[i] // 2
            bit[i] = bit[i] % 2

    bit.reverse()
    i = bit.index(1)
    print(*bit[i:],sep='')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
S = ''

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

print(S[::-1])

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    L = 10000

    N = NI()

    s = 1 if N > 0 else -1
    n = abs(N)

    bit = [0] * L

    i = 0
    while n > 0:
        if n % 2:
            bit[i] += 1
            if s > 0 and i % 2 == 1 or s < 0 and i % 2 == 0:
                bit[i+1] += 1
        n //= 2
        i += 1

    for i in range(L-2):
        if bit[i] > 1:
            bit[i+2] += bit[i] // 2
            bit[i+1] += bit[i] // 2
            bit[i] = bit[i] % 2

    f = False
    ans = ''
    for i in range(L-1,-1,-1):
        if bit[i] == 1:
            ans = ''.join((ans,'1'))
            f = True
        elif f:
            ans = ''.join((ans,'0'))
    if ans == '': ans = '0'

    print(ans)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()

    s = 1 if N > 0 else -1
    n = abs(N)

    bit = [0] * 1000

    i = 0
    while n > 0:
        if n % 2:
            bit[i] += 1
            if s > 0 and i % 2 == 1 or s < 0 and i % 2 == 0:
                bit[i+1] += 1
        n //= 2
        i += 1

    for i in range(1000-2):
        if bit[i] > 1:
            bit[i+2] += bit[i] // 2
            bit[i+1] += bit[i] // 2
            bit[i] = bit[i] % 2

    f = False
    ans = ''
    for i in range(999,-1,-1):
        if bit[i] == 1:
            ans = ''.join((ans,'1'))
            f = True
        elif f:
            ans = ''.join((ans,'0'))
    if ans == '': ans = '0'

    print(ans)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from itertools import product
def main():
    N = int(input())
    if N == 0:
        return 0
    l = set()
    while N != 0:
        if N > 0:
            r = plus(N)
            l.add(r)
            N -= pow(2, r)
        else:
            r = minus(N)
            l.add(r)
            N += pow(2, r)
    s = [0] * (max(l)+1)
    for i in range(max(l)+1):
        if i in l:
            print(i)
            s[i] = 1
    s.reverse()
    return ''.join(str(i) for i in s)

def plus(N):
    p = 0
    n = 0
    while True:
        p += pow(2, n)
        if p >= N:
            break
        n += 2
    return n
def minus(N):
    p = 0
    n = 1
    while True:
        p -= pow(2, n)
        if p <= N:
            break
        n += 2
    return n

print(main())

Submission status: Wrong Answer

Solution code:
n = int(input())

s = ""

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

print(s[::-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
i = 0
#for i in range(10):
ans = []
while abs(n) > 0:
    #print(n, n // (2 * (-1)**i), n % (2 * (-1)**i))
    #print(n, n % (2 * (-1)**i), n % 2)
    ans.append(n%2)
    #n = n // (2 * (-1)**i)
    n = (n - n % (2 * (-1)**i)) // 2
    i += 1
#print(n, n % (2 * (-1)**i))
#print(ans[::-1])
print(''.join(map(str, ans[::-1])))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
def solve(N):
    ans = ''
    while N != 0:
        ans += str(N & 1)
        N >>= 1
        N *= -1
    return ans[::-1]
print(solve(N))

Submission status: Wrong Answer

Solution code:
# returns : Nのd進数表記
def base_n_num(N, d):
    p = 1
    ans = []
    while N != 0:
        if N % (d**p) == 0:
            ans.append(0)
        else:
            ans.append(1)
            N -= (d**(p-1))
        p += 1
        if N == 0:
            break
    return reversed(ans)

def solve():
    n = int(input())

    # 下の桁から求める
    ans = base_n_num(n, -2)
    print(''.join(list(map(str, ans))))

solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=""
i=0
while n!=0 :
    if n%2==0:
        ans+="0"

    else:
        ans+="1"
        if i%2==0:
            n-=1
        else:
            n+=1
    n=n//2
    i+=1
    #print(n,ans)

print(ans[::-1])

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)


def input(): return sys.stdin.readline().rstrip()


N = int(input())
l = deque()
while N != 0:
    x = (-2) ** len(l)
    y = (-2) * x
    if abs(N) % abs(y) != 0:
        N -= x
        l.appendleft('1')
    else:
        l.appendleft('0')
print(0 if N == 0 else ''.join(l))

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
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())
lst = []

while (n!=0):
    r = int(n%2)
    if(r<0):
        r += 2
    lst.append(r)
    n = (n-r)/(-2)

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

Submission status: Wrong Answer

Solution code:
N = int(input())
div = 2
ans = []
while N // 2 > 0:
    ans.append(N % 2)
    N //= 2

ans.reverse()
print("".join(map(lambda x: str(x), ans)))

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()

    if ans in [True, False]:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    N = iip(False)
    if N == 0:
        return 0

    n = N # 残りの数で表現すべき数
    result = []
    cur = -2
    for i in range(100):
        if n % cur != 0:
            result.append(1)
            n -= cur/(-2)
        else:
            result.append(0)
        cur *= -2

        if abs(cur) > abs(N) * 10:
            break


    result.reverse()
    r = []
    f = False
    for i in result:
        if f:
            r.append(i)
        elif i == 1:
            r.append(i)
            f = True

    print("".join([str(i) for i in r]))



#####################################################ライブラリ集ここから

def iip(listed=True, num_only=True):  # 数字のinputをlistで受け取る
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()

    if ans in [True, False]:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    N = iip(False)

    n = N # 残りの数で表現すべき数
    result = []
    cur = -2
    for i in range(100):
        if n % cur != 0:
            result.append(1)
            n -= cur/(-2)
        else:
            result.append(0)
        cur *= -2

        if abs(cur) > abs(N) * 10:
            break


    result.reverse()
    r = []
    f = False
    for i in result:
        if f:
            r.append(i)
        elif i == 1:
            r.append(i)
            f = True

    print("".join([str(i) for i in r]))



#####################################################ライブラリ集ここから

def iip(listed=True, num_only=True):  # 数字のinputをlistで受け取る
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()

    if ans in [True, False]:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    N = iip(False)

    n = N # 残りの数で表現すべき数
    result = []
    cur = 2
    for i in range(10**6):
        print(n, cur, i)
        if abs(n) == cur:
            if i % 2 == 0:
                if n < 0:
                    result.append(0)
                    result.append(1)
                else:
                    result.append(0)
                    result.append(1)
                    result.append(1)
            else:
                result.append(1)
            break

        if n % cur != 0:
            result.append(1)
            if i % 2 == 0:
                n -= cur // 2
            else:
                n += cur // 2
        else:
            result.append(0)

        cur *= 2

    result.reverse()
    print("".join([str(i) for i in result]))



#####################################################ライブラリ集ここから

def iip(listed=True, num_only=True):  # 数字のinputをlistで受け取る
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

def resolve():
    N = int(input())
    mods = []
    target = N
    if N == 0:
        print("0")
        return
    while True:
        print(target)
        if target == 1:
            mods.append("1")
            break
        v = target // (-2)
        c = target % (-2)
        if c == -1:
            v += 1
            c = 1
        mods.append(str(c))
        target = v
    mods.reverse()
    print("".join(mods))

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())

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

ans = ''
while N:
    d = N % 2
    ans = str(d) + ans
    N -= d
    N //= -2
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = ''
while N:
    d = N % 2
    ans += str(d)
    N -= d
    N //= -2
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
#!python3

# input
N = int(input())


def solve(x):
    ans = []
    while x != 1 and x != -1:
        if x % 2 == 1:
            ans.append(1)
            x = (x - 1) // -2
        else:
            ans.append(0)
            x //= -2
    
    ans.append(1)
    if x == 1:
        ans = ans[::-1]
    else:
        ans.append(1)
    print("".join(map(str, ans)))


def main():
    if N == 0:
        print(0)
    else:
        solve(N)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

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

    n = (n - rest) // -2

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

print(reversed(ans))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

    n = (n - rest) // -2

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

print(ans)

Submission status: Wrong Answer

Solution code:

n = int(input())

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
N = 2**30 + N
buf = [0]*35
for i,s in enumerate(bin(N)[2:][::-1]):
    if s == "1":
        buf[i] = 1
#print(buf)

ans = [0]*35

for i in range(33):
    if buf[i]==1:
        if i%2==0:
            ans[i]+=1
        else:
            ans[i]+=1
            ans[i+1]+=1
    while ans[i]>=2:
        ans[i]-=2
        ans[i+1]+=1
        ans[i+2]+=1
    #print(ans)
first = True
ans[30]-=1
a = ""
for i in ans[:32][::-1]:
    if first:
        if i==1:
            first=False
    if not first:
        a += str(i)
if a!="":
    print(a)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
N = 2**30 + N
buf = [0]*35
for i,s in enumerate(bin(N)[2:][::-1]):
    if s == "1":
        buf[i] = 1
#print(buf)

ans = [0]*35

for i in range(33):
    if buf[i]==1:
        if i%2==0:
            ans[i]+=1
        else:
            ans[i]+=1
            ans[i+1]+=1
    while ans[i]>=2:
        ans[i]-=2
        ans[i+1]+=1
        ans[i+2]+=1
    #print(ans)
first = True
ans[30]-=1
a = ""
for i in ans[:31][::-1]:
    if first:
        if i==1:
            first=False
    if not first:
        a += str(i)
if a!="":
    print(a)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
N = 2**30 + N
buf = [0]*35
for i,s in enumerate(bin(N)[2:][::-1]):
    if s == "1":
        buf[i] = 1
#print(buf)

ans = [0]*35

for i in range(33):
    if buf[i]==1:
        if i%2==0:
            ans[i]+=1
        else:
            ans[i]+=1
            ans[i+1]+=1
    while ans[i]>=2:
        ans[i]-=2
        ans[i+1]+=1
        ans[i+2]+=1
    #print(ans)
first = True
a = ""
for i in ans[:30][::-1]:
    if first:
        if i==1:
            first=False
    if not first:
        a += str(i)
if a!="":
    print(a)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#print(1//-2)

n = int(input())
result = ''
while n!=0:
  #print(n)
  if n%-2==0:
    result+='0'
    n = n//-2
    #n+=1
  else:
    result+='1'
    if n<0:
      n = n//-2
      n+=1
    else:
      n = n//-2
      n+=1
result = result[::-1]
print(result)

Submission status: Wrong Answer

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

for _ in range(400):
    if n > 0:
        if n % 2 == 1:
            n = - (n // 2)
            a.append(1)
        else:
            n = -(n // 2)
            a.append(0)
    elif n < 0:
        if (-n) % 2 == 1:
            n = n // (-2) + 1
            a.append(1)
        else:
            n = n // (-2)
            a.append(0)
    
a.reverse()
ans = ''.join([str(n) for n in a])

if n != 0:
    print(ans)
if n == 0:
    print(0)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc026/tasks/arc026_2
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=''

  while True:
    if abs(n)==0:
      return ans

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

# main()
print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

def nega_binary(num):
	res = []
	while num != 0:
		remainder = abs(num) % 2
		res.append(str(remainder))
		if num < 0 and remainder:
			num -= 1
		num = int(num / -2)

	return ''.join(reversed(res))

print(nega_binary(N))

Submission status: Wrong Answer

Solution code:
N = int(input())
k = 0
i = 0
ans = []
while k != N:
    j = pow(-2, i)
    p = '1' if (N - k - j) % pow(2, i + 1) == 0 else '0'
    ans.append(p)
    k += int(p) * j
    i += 1

print(''.join(reversed(ans)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[]
cnt=0
while(n!=0):
    cnt+=1
    a=n%(2**cnt)
    b=(1 if a>0 else 0)
    L.append(b)
    n=n-(((-2)**(cnt-1))*b)
L=list(map(str,L))[::-1]
print("".join(L))