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:
N = int(input())
i = 0
answ = []

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

if ( N == abs(N)):
  sign = 1
  base = 0
  i = 0
  while(1):
    if N <= (-2) ** i + base:
      break
    else:
      base = base + (-2) ** i
      i = i + 2
else:
  sign = -1
  base = 0
  i = 1
  while(1):
    if N >= (-2) ** i + base:
      break
    else:
      base = base + (-2) ** i
      i = i + 2
      #print(i, base)
# keta
#print("keta", i)

if(sign == 1):
  N = N - (-2) ** i
  answ.append('1')
  i = i - 1

while(i >= 0):
  a = N
  b = N - (-2) ** i
  c = N - (-2) ** i - (-2) ** (i-1)
  d = N - (-2) ** (i-1)
  x = min(abs(a), abs(b), abs(c), abs(d))
  if abs(a) == x:
    answ.append('00')
  elif abs(b) == x:
    answ.append('10')
    N = b
  elif abs(c) == x:
    answ.append('11')
    N = c
  else:
    answ.append('01')
    N = d
  #print(i,N)
  i = i - 2

als = ''.join(answ)
print(als[::-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
if N == 0:
    print("0")
else:
    K = int(abs(N) ** (1/2)) + 3
    for i in range(2 ** K):
        counter = 0
        bits = bin(i)[3:]
        bits = "0" * (K - len(bits)) + bits
        for j in range(1, K+1):
            if bits[j-1] == "1":
                counter += (-2) ** (K - j)
        if counter == N:
            bits = bits[bits.find("1"):]
            print(bits)
            break

Submission status: Wrong Answer

Solution code:
li = list(map(int,input().split()))
n=li[0]
ans = 0

def asd(x):
    global ans
    if x>0:
        for i in range(0,31):
            max = 0
            l=0
            for j in range (0,i,2):
                max += pow(-2,j)
            if max >= x:
                ans += pow(10,i-1)
                #print(pow(-2,i-1))
                return asd(x-(pow(-2,i-1)))
                #asd(x-pow(-2,i-1))
    elif x<0:
        for i in range(0,31):
            min =0
            for j in range (1,i,2):
                min += pow(-2,j)
            if min <= x:
                ans += pow(10,i-1)
                #print(pow(-2,i-1))
                return asd(x-(pow(-2,i-1)))
                
                


    elif x==0:
        return 0
asd(n)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from math import log
n=int(input())
neg_bin =[]

def f(n,neg,m):
    if(n>1):
        #print(n,neg,m)
        x = 2*math.ceil(0.5*math.log(3*n+1,2))-1
        n -= (-2)**(x-1)
        neg.append('1')
        for i in range(m-x-1):
            neg.append('0')
        return(f(n,neg,x))
    elif(n<0):
        #print(n,neg,m)
        x = 2*math.ceil(0.5*log((3/2)*(-1*n)+1,2))
        n -= (-2)**(x-1)
        for i in range(m-x-1):
            neg.append('0')
        neg.append('1')
        return(f(n,neg,x))
    elif(n==1):
        #print(n,neg,m)
        for i in range(m-2):
            neg.append('0')
        neg.append('1')
        return(1)
    else:
        #print(n,neg,m)
        for i in range(m-2):
            neg.append('0')
        neg.append('0')
        return(1)

m= 2*math.ceil(0.5*math.log(3*n+1,2))-1 if n>1 else (2*math.ceil(0.5*log((3/2)*(-1*n)+1,2)) if n<0 else 1)
a=f(n,neg_bin,m)
#if len(neg_bin)>1:neg_bin.pop(-2)
print(''.join(neg_bin))

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

n = int(input())

v = []

tmp_n = n
plus = 0

if tmp_n < 0:
    plus = 1
    tmp_n *= -1

while tmp_n > 0:
    v.append(tmp_n & 1)
    tmp_n = tmp_n >> 1

r = [0 for _ in range(len(v) + 10)]
for i in range(len(v)):
    if i % 2 == plus:
        r[i] += v[i]
    else:
        r[i] += v[i]
        r[i + 1] += v[i]

for i in range(len(r)):
    while (r[i] >= 2 and r[i + 1] >= 1):
        r[i] -= 2
        r[i + 1] -= 1
    while r[i] >= 2:
        r[i + 1] += 1
        r[i + 2] += 1
        r[i] -= 2

started = False
res = ""
for i in range(len(r)):
    idx = len(r) - 1 - i
    if r[idx] == 1:
        res = res + "1"
        started = True
    elif started == True:
        res = res + "0"

print(res)

Submission status: Wrong Answer

Solution code:
import math
inp = int(input())
if inp > -1:
  print('{0:b}'.format(inp))
else:
  s = ""
  x = math.floor(math.log(abs(inp), 2))
  while x >= 0:
    if x == 1:
      if inp == -1:
        s += '11'
      elif inp == 0:
        s += '00'
      elif inp == -2:
        s += '10'
      break
    if inp + int(math.pow(2,x)) < 0:
      s += '1'
      inp += int(math.pow(2,x))
    else:
      s += '0'
    x -= 1
  print(s)

Submission status: Wrong Answer

Solution code:
N = input()
N = abs(int(N))
S = format(N, 'b')
print(S)

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 0:
    print(0)
else:
    d = 0
    pows = [(0, 1)]
    for i in range(1, 50):
        a, b = pows[i-1]
        if i%2 == 1:
            min_ = b-2**(i+1)+1
            pows.append((min_, min_+2**i-1))
        else:
            max_ = a+2**(i+1)-1
            pows.append((max_-2**i+1, max_))
    # print(pows, len(str(pows[-1][0])))

    ans = ''
    d = len(pows)-1
    for p in pows[::-1]:
        pmin, pmax = p
        if n >= pmin and n <= pmax:
            ans += '1'
            n -= (-2)**d
            # print((-2)**d)
        else:
            ans += '0'

        d -= 1
    print(ans.lstrip('0'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
num = int(input())
b = bin(num)
if num < 0 and int(b[-1])==1:
    print(bin(abs(num)+2)[2:])
else:
    print(bin(num)[2:])

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 0:
    print(0)
else:
    d = 0
    pows = [(0, 1)]
    for i in range(1, 40):
        a, b = pows[i-1]
        if i%2 == 1:
            min_ = b-2**(i+1)+1
            pows.append((min_, min_+2**i-1))
        else:
            max_ = a+2**(i+1)-1
            pows.append((max_-2**i+1, max_))
    # print(pows, len(str(pows[-1][0])))

    ans = ''
    d = len(pows)-1
    for p in pows[::-1]:
        pmin, pmax = p
        if n >= pmin and n <= pmax:
            ans += '1'
            n -= (-2)**d
            # print((-2)**d)
        else:
            ans += '0'

        d -= 1
    print(ans.lstrip('0'))

Submission status: Wrong Answer

Solution code:
import math
inp = int(input())
if inp > -1:
  print('{0:b}'.format(inp))
else:
  s = ""
  x = math.floor(math.log(abs(inp), 2))
  while x >= 0:
    print(inp)
    if x == 1:
      if inp == -1:
        s += '11'
      elif inp == 0:
        s += '00'
      elif inp == -2:
        s += '10'
      break
    if inp + int(math.pow(2,x)) < 0:
      s += '1'
      inp += int(math.pow(2,x))
    else:
      s += '0'
    x -= 1
  print(s)

Submission status: Wrong Answer

Solution code:
import math

n=int(input())
a=1
p=0
b=[]
s=""
#最高桁が奇数の時は正、偶数の時は負
if n==0:
    print(0)
else:
    while n!=0:
        if n>0:
            t=math.floor(math.log(n,2))
            if t%2==1:
                n=n-2**(t+1)
                b.append(t+2)
            else:
                n=n-2**(t)
                b.append(t+1)
            #print(n)
        else:
            t=math.floor(math.log(-n,2))
            if t%2==1:
                n=n+2**(t)
                b.append(t+1)
            else:
                n=n+2**(t+1)
                b.append(t+2)
            #print(n)
    b.sort()
    for i in range(1,b[len(b)-1]+1):
        if i==b[p]:
            s=s+"1"
            p=p+1
        else:
            s=s+"0"
    print(s[::-1])

Submission status: Wrong Answer

Solution code:
import math
from math import log
n=int(input())
neg_bin =[]

def f(n,neg,m):
    if(n>1):
        x = 2*math.ceil(0.5*math.log(3*n+1,2))-1
        n -= (-2)**(x-1)
        neg.append('1')
        for i in range(m-x-1):
            neg.append('0')
        return(f(n,neg,x))
    elif(n<0):
        x = 2*math.ceil(0.5*log((3/2)*(-1*n)+1,2))
        n -= (-2)**(x-1)
        for i in range(m-x-1):
            neg.append('0')
        neg.append('1')
        return(f(n,neg,x))
    elif(n==1):
        for i in range(m-1):
            neg.append('0')
        neg.append('1')
        return(1)
    else:
        for i in range(m-1):
            neg.append('0')
        neg.append('0')
        return(1)

m= 2*math.ceil(0.5*math.log(3*n+1,2))-1 if n>1 else (2*math.ceil(0.5*log((3/2)*(-1*n)+1,2)) if n<0 else 1)
a=f(n,neg_bin,m)
if len(neg_bin)>1:neg_bin.pop(-2)
print(''.join(neg_bin))

Submission status: Wrong Answer

Solution code:
N = int(input())
base = 1
pos = 0
ans = ''
while N != 0:
    if abs(N) & (1 << pos):
        N -= base
        ans += '1'
    else:
        ans += '0'
    pos += 1
    base *= -2
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
if N >= 0:
  if N == 0:
    print(0)
  elif N == 1:
    print(1)
  else:
    s = 2
    j = 2
    i = 1
    while s + j**2 <= N:
      i += 1
      s += j**2
      j*= 2
  
    k = 2 * i + 1
    print('1' + bin(int('10'*i, 2)^(N-s))[2:])
else:
  s = -1
  j = -2
  i = 1
  while N <= s + j:
    s += j
    j *= 4
    i += 1
  k = 2 * i
  print(bin(int('10'*i, 2)^(N-(s+j)-1))[2:])

Submission status: Wrong Answer

Solution code:
import math
from math import log
n=int(input())
neg_bin =[]

def f(n,neg,m):
    if(n>1):
        x = 2*math.ceil(0.5*math.log(3*n+1,2))-1
        n -= (-2)**(x-1)
        neg.append('1')
        for i in range(m-x-1):
            neg.append('0')
        return(f(n,neg,x))
    elif(n<0):
        x = 2*math.ceil(0.5*log((3/2)*(-1*n)+1,2))
        n -= (-2)**(x-1)
        neg.append('1')
        for i in range(m-x-1):
            neg.append('0')
        return(f(n,neg,x))
    elif(n==1):
        for i in range(m-1):
            neg.append('0')
        neg.append('1')
        return(1)
    else:
        for i in range(m-1):
            neg.append('0')
        neg.append('0')
        return(1)

m= 2*math.ceil(0.5*math.log(3*n+1,2))-1 if n>1 else (2*math.ceil(0.5*log((3/2)*(-1*n)+1,2)) if n<0 else 1)
a=f(n,neg_bin,m)
if len(neg_bin)>1:neg_bin.pop(-2)
print(''.join(neg_bin))

Submission status: Wrong Answer

Solution code:
n = int(input())
if n == 0:
    print(0)
else:
    d = 0
    pows = [(0, 1)]
    for i in range(1, 40):
        a, b = pows[i-1]
        if i%2 == 1:
            min_ = b-2**(i+1)+1
            pows.append((min_, min_+2**i-1))
        else:
            max_ = a+2**(i+1)-1
            pows.append((max_-2**i+1, max_))
    # print(pows, len(str(pows[-1][0])))

    ans = ''
    d = len(pows)-1
    for p in pows[::-1]:
        pmin, pmax = p
        if n >= pmin and n <= pmax:
            ans = '1'+ans
            n -= (-2)**d
            # print((-2)**d)
        else:
            ans = '0'+ans

        d -= 1
    print(ans.rstrip('0')[::-1])

Submission status: Wrong Answer

Solution code:
num = int(input())
if num < 0:
    print(bin(abs(num)+2)[2:])
else:
    print(bin(num)[2:])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
m = 1

min = 0
max = 1

i = 0
while True:
    m *= 2

    if i % 2 == 0:
        min -= m
    else:
        max += m

    if min <= N <= max:
        break

    i += 1

# print(min,max)
# print("i =",i)
# print("m =",m)
ans = []

while True:
    if (min + max)/2 < N:
        if i % 2 == 0:
            ans.append("0")
        else:
            ans.append("1")
        min += m

    elif N < (min + max)/2 :
        if i % 2 == 0:
            ans.append("1")
        else:
            ans.append("0")
        max -= m

    else:
        break

    m /= 2
    i -= 1

print("".join(ans))

Submission status: Wrong Answer

Solution code:
a=int(input())
sum=0
s=''
if a<0:
    b = abs(a)
    if b%2==1:
        b=b+1
        print(str(bin(b))[2:-1]+'1')
    else:
        print(str(bin(b))[2:-1])
elif a>0:
    while(a!=1):
        if a%(-2)==-1:
            s=s+'1'
            a=a-1
            a=a/-2
        else:
            s = s + '0'
            a=a/-2
    s=s+'1'
    for i in range(len(s)):
        print(s[len(s)-1-i],end='')
    print()
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def fa(): #final answer
    global ans
    print(ans)
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
N = getN()

deci = []
carry = False
a  = bin(N)[2:]

while(len(a) > 1):
    d = a[-2]+a[-1]
    if carry:
        if d == "00":
            d = "01"
        elif d == "01":
            d = "10"
        elif d == "10":
            d = "11"
        elif d == "11":
            deci.append("00")
            carry = True
            a = a[:-2]
            continue
    if d == "01":
        deci.append("01")
        carry = False
    elif d == "00":
        deci.append("00")
        carry = False
    elif d == "10":
        deci.append("10")
        carry = True
    elif d == "11":
        deci.append("11")
        carry = True
    a = a[:-2]

if len(a) == 1:
    if a[0] == "0":
        deci.append("0")
    else:
        if carry:
            deci.append("110")
        else:
            deci.append("1")
if len(a) == 0 and carry:
    if len(deci) != 0:
        deci.append("1")
    else:
        deci.append("0")
deci.reverse()

print("".join(deci))
"""
   1 11 01 01 10 11 11 00 11 01 00 01 01 01
1 10 00 10 10 11 00 11 01 11 01 00 01 01 01
1 10 00 10 10 11 00 11 01 11 01 00 01 01 01
"""

Submission status: Wrong Answer

Solution code:
import random
import bisect
import math

option = 0     # 0:PSO 1:CFA 2:CFArank
max_or_min = 0 # 0:minimize 1:maxmize

iter=1

N = 70 #粒子の数
T = 2000 #世代数(ループの回数)
maximum=1
minimum=0

dimension, limit = 32, float("inf")

pi = [0 for i in range(dimension)]
ci = [0 for i in range(dimension)]
       
value = int(input())

#print(pi)
#print(ci)
#print(tot)


#--------粒　子　群　最　適　化------------------------------

#評価関数
def criterion(x):
    
    z = abs (sum([(-2)** i * x[i] for i in range(dimension)]) - value)
    return z

#粒子の位置の更新を行う関数
def update_position(x, v, x_min, x_max):
#    new_x = [x_min[i] if x[i]+ v[i] < x_min[i] else x_max[i] if x[i]+ v[i] > x_max[i] else x[i]+ v[i] for i in range(dimension)]
    new_x = [1 if random.uniform(0, 1)< 1/(1+math.e**(-v[i])) else 0 for i in range(dimension)]
    return new_x

#粒子の速度の更新を行う関数
def update_velocity(x, v, p, g, w, ro_max=1.0, c1=2.00, c2=0.75):
    #パラメーターroはランダムに与える
    phi=c1+c2
    K=2/abs(2-phi-(phi*phi-4*phi)**0.5)
    
    #粒子速度の更新を行う
    if option!=0:
        new_v = [K * ( w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) ) for i in range(dimension)]
    else:
        new_v = [w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) for i in range(dimension)]

    return new_v

def main():
    w = 1.0
    w_best, w_worst = 1.25, 0.25
    x_min = [minimum for i in range(dimension)]
    x_max = [maximum for i in range(dimension)]
    
    #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
    ps = [[random.randint(x_min[j], x_max[j]) for j in range(dimension)] for i in range(N)]
    vs = [[0.0 for j in range(dimension)] for i in range(N)]

    personal_best_positions = ps[:] 
    personal_best_scores = [criterion(p) for p in ps]

    if max_or_min == 1:
        best_particle = personal_best_scores.index(max(personal_best_scores))
    elif max_or_min == 0:
        best_particle = personal_best_scores.index(min(personal_best_scores))
    global_best_position = personal_best_positions[best_particle][:]

    for t in range(T):
        for n in range(N):
            x = ps[n][:]
            v = vs[n][:]
            p = personal_best_positions[n][:]

            if option>=2:
                best_list = sorted(personal_best_positions)
                mu = bisect.bisect_left( best_list, p ) + 1
                w = w_best - mu * (w_best - w_worst) / (N - 1)


            #粒子の位置の更新を行う
            new_x = update_position(x, v, x_min, x_max)
            ps[n] = new_x[:]

            #粒子の速度の更新を行う
            new_v = update_velocity(new_x, v, p, global_best_position, w)
            vs[n] = new_v[:]

            #評価値を求め, パーソナルベストの更新を行う
            score = criterion(new_x)

            if max_or_min == 1:
                if score > personal_best_scores[n]:
                    personal_best_scores[n] = score
                    personal_best_positions[n] = new_x[:]
            elif max_or_min == 0:
                if score < personal_best_scores[n]:
                    personal_best_scores[n] = score
                    personal_best_positions[n] = new_x[:]

        #グローバルベストの更新を行う
        if max_or_min == 1:
            best_particle = personal_best_scores.index(max(personal_best_scores))
            global_best_position = personal_best_positions[best_particle][:]

        elif max_or_min == 0:
            best_particle = personal_best_scores.index(min(personal_best_scores))
            global_best_position = personal_best_positions[best_particle][:]
                     
    #最適解
    if max_or_min == 1:
        return max(personal_best_scores)
    elif max_or_min == 0:
        return min(personal_best_scores), global_best_position

#--------------------------------------------------------------
    
if max_or_min == 1:
    best=-float("inf")
    for i in range(iter):
        best=max(best, main())

elif max_or_min == 0:
    best=float("inf")
    for i in range(iter):
        best, answer =  main()

#print(best, answer)
flag = 0
s = ""
for i in range(len(answer)):
  if answer[len(answer)-1-i] ==1:
    flag = 1
  if flag ==1:
    s+=str(answer[len(answer)-1-i])
    
if value ==0:
  print(0)
else:
  print(s)

Submission status: Wrong Answer

Solution code:
import random
import bisect
import math

option = 0     # 0:PSO 1:CFA 2:CFArank
max_or_min = 0 # 0:minimize 1:maxmize

iter=1

N = 100 #粒子の数
T = 1550 #世代数(ループの回数)
maximum=1
minimum=0

dimension, limit = 32, float("inf")

pi = [0 for i in range(dimension)]
ci = [0 for i in range(dimension)]
       
value = int(input())

#print(pi)
#print(ci)
#print(tot)


#--------粒　子　群　最　適　化------------------------------

#評価関数
def criterion(x):
    
    z = abs (sum([(-2)** i * x[i] for i in range(dimension)]) - value)
    return z

#粒子の位置の更新を行う関数
def update_position(x, v, x_min, x_max):
#    new_x = [x_min[i] if x[i]+ v[i] < x_min[i] else x_max[i] if x[i]+ v[i] > x_max[i] else x[i]+ v[i] for i in range(dimension)]
    new_x = [1 if random.uniform(0, 1)< 1/(1+math.e**(-v[i])) else 0 for i in range(dimension)]
    return new_x

#粒子の速度の更新を行う関数
def update_velocity(x, v, p, g, w, ro_max=1.0, c1=2.00, c2=0.75):
    #パラメーターroはランダムに与える
    phi=c1+c2
    K=2/abs(2-phi-(phi*phi-4*phi)**0.5)
    
    #粒子速度の更新を行う
    if option!=0:
        new_v = [K * ( w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) ) for i in range(dimension)]
    else:
        new_v = [w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) for i in range(dimension)]

    return new_v

def main():
    w = 1.0
    w_best, w_worst = 1.25, 0.25
    x_min = [minimum for i in range(dimension)]
    x_max = [maximum for i in range(dimension)]
    
    #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
    ps = [[random.randint(x_min[j], x_max[j]) for j in range(dimension)] for i in range(N)]
    vs = [[0.0 for j in range(dimension)] for i in range(N)]

    personal_best_positions = ps[:] 
    personal_best_scores = [criterion(p) for p in ps]

    if max_or_min == 1:
        best_particle = personal_best_scores.index(max(personal_best_scores))
    elif max_or_min == 0:
        best_particle = personal_best_scores.index(min(personal_best_scores))
    global_best_position = personal_best_positions[best_particle][:]

    for t in range(T):
        for n in range(N):
            x = ps[n][:]
            v = vs[n][:]
            p = personal_best_positions[n][:]

            if option>=2:
                best_list = sorted(personal_best_positions)
                mu = bisect.bisect_left( best_list, p ) + 1
                w = w_best - mu * (w_best - w_worst) / (N - 1)


            #粒子の位置の更新を行う
            new_x = update_position(x, v, x_min, x_max)
            ps[n] = new_x[:]

            #粒子の速度の更新を行う
            new_v = update_velocity(new_x, v, p, global_best_position, w)
            vs[n] = new_v[:]

            #評価値を求め, パーソナルベストの更新を行う
            score = criterion(new_x)

            if max_or_min == 1:
                if score > personal_best_scores[n]:
                    personal_best_scores[n] = score
                    personal_best_positions[n] = new_x[:]
            elif max_or_min == 0:
                if score < personal_best_scores[n]:
                    personal_best_scores[n] = score
                    personal_best_positions[n] = new_x[:]

        #グローバルベストの更新を行う
        if max_or_min == 1:
            best_particle = personal_best_scores.index(max(personal_best_scores))
            global_best_position = personal_best_positions[best_particle][:]

        elif max_or_min == 0:
            best_particle = personal_best_scores.index(min(personal_best_scores))
            global_best_position = personal_best_positions[best_particle][:]
                     
    #最適解
    if max_or_min == 1:
        return max(personal_best_scores)
    elif max_or_min == 0:
        return min(personal_best_scores), global_best_position

#--------------------------------------------------------------
    
if max_or_min == 1:
    best=-float("inf")
    for i in range(iter):
        best=max(best, main())

elif max_or_min == 0:
    best=float("inf")
    for i in range(iter):
        best, answer =  main()

#print(best, answer)
flag = 0
s = ""
for i in range(len(answer)):
  if answer[len(answer)-1-i] ==1:
    flag = 1
  if flag ==1:
    s+=str(answer[len(answer)-1-i])
    
if value ==0:
  print(0)
else:
  print(s)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[]
M=""
while N!=0:
  M=int((-1)*(N%(-2)))
  if N<0:
    N=int((N-1)/(-2))
  else:
    N=int(N/(-2))
  L.insert(0,str(M))
if N==0:
  print(0)
else:
  print("".join(L))

Submission status: Wrong Answer

Solution code:
N = int(input())

if N == 0:
  print(0)
elif N == 1:
  print(1)
else:
  s = 2
  j = 2
  i = 1
  while s + j**2 <= N:
    i += 1
    s += j**2
    j*= 2
  
  k = 2 * i + 1
  print('1' + bin(int('10'*i, 2)^(N-s))[2:])

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[]
M=""
while N!=0:
  M=int((-1)*(N%(-2)))
  if N<0:
    N=int((N-1)/(-2))
  else:
    N=int(N/(-2))
  L.insert(0,str(M))
print("".join(L))

Submission status: Wrong Answer

Solution code:
import random
import bisect
import math

option = 0     # 0:PSO 1:CFA 2:CFArank
max_or_min = 0 # 0:minimize 1:maxmize

iter=1

N = 100 #粒子の数
T = 1550 #世代数(ループの回数)
maximum=1
minimum=0

dimension, limit = 32, float("inf")

pi = [0 for i in range(dimension)]
ci = [0 for i in range(dimension)]
       
value = int(input())

#print(pi)
#print(ci)
#print(tot)


#--------粒　子　群　最　適　化------------------------------

#評価関数
def criterion(x):
    
    z = abs (sum([(-2)** i * x[i] for i in range(dimension)]) - value)
    return z

#粒子の位置の更新を行う関数
def update_position(x, v, x_min, x_max):
#    new_x = [x_min[i] if x[i]+ v[i] < x_min[i] else x_max[i] if x[i]+ v[i] > x_max[i] else x[i]+ v[i] for i in range(dimension)]
    new_x = [1 if random.uniform(0, 1)< 1/(1+math.e**(-v[i])) else 0 for i in range(dimension)]
    return new_x

#粒子の速度の更新を行う関数
def update_velocity(x, v, p, g, w, ro_max=1.0, c1=2.00, c2=0.75):
    #パラメーターroはランダムに与える
    phi=c1+c2
    K=2/abs(2-phi-(phi*phi-4*phi)**0.5)
    
    #粒子速度の更新を行う
    if option!=0:
        new_v = [K * ( w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) ) for i in range(dimension)]
    else:
        new_v = [w * v[i] + c1 * random.uniform(0, ro_max) * (p[i] - x[i]) + c2 * random.uniform(0, ro_max) * (g[i] - x[i]) for i in range(dimension)]

    return new_v

def main():
    w = 1.0
    w_best, w_worst = 1.25, 0.25
    x_min = [minimum for i in range(dimension)]
    x_max = [maximum for i in range(dimension)]
    
    #粒子位置, 速度, パーソナルベスト, グローバルベストの初期化を行う
    ps = [[random.randint(x_min[j], x_max[j]) for j in range(dimension)] for i in range(N)]
    vs = [[0.0 for j in range(dimension)] for i in range(N)]

    personal_best_positions = ps[:] 
    personal_best_scores = [criterion(p) for p in ps]

    if max_or_min == 1:
        best_particle = personal_best_scores.index(max(personal_best_scores))
    elif max_or_min == 0:
        best_particle = personal_best_scores.index(min(personal_best_scores))
    global_best_position = personal_best_positions[best_particle][:]

    for t in range(T):
        for n in range(N):
            x = ps[n][:]
            v = vs[n][:]
            p = personal_best_positions[n][:]

            if option>=2:
                best_list = sorted(personal_best_positions)
                mu = bisect.bisect_left( best_list, p ) + 1
                w = w_best - mu * (w_best - w_worst) / (N - 1)


            #粒子の位置の更新を行う
            new_x = update_position(x, v, x_min, x_max)
            ps[n] = new_x[:]

            #粒子の速度の更新を行う
            new_v = update_velocity(new_x, v, p, global_best_position, w)
            vs[n] = new_v[:]

            #評価値を求め, パーソナルベストの更新を行う
            score = criterion(new_x)

            if max_or_min == 1:
                if score > personal_best_scores[n]:
                    personal_best_scores[n] = score
                    personal_best_positions[n] = new_x[:]
            elif max_or_min == 0:
                if score < personal_best_scores[n]:
                    personal_best_scores[n] = score
                    personal_best_positions[n] = new_x[:]

        #グローバルベストの更新を行う
        if max_or_min == 1:
            best_particle = personal_best_scores.index(max(personal_best_scores))
            global_best_position = personal_best_positions[best_particle][:]

        elif max_or_min == 0:
            best_particle = personal_best_scores.index(min(personal_best_scores))
            global_best_position = personal_best_positions[best_particle][:]
                     
    #最適解
    if max_or_min == 1:
        return max(personal_best_scores)
    elif max_or_min == 0:
        return min(personal_best_scores), global_best_position

#--------------------------------------------------------------
    
if max_or_min == 1:
    best=-float("inf")
    for i in range(iter):
        best=max(best, main())

elif max_or_min == 0:
    best=float("inf")
    for i in range(iter):
        best, answer =  main()

#print(best, answer)
flag = 0
s = ""
for i in range(len(answer)):
  if answer[len(answer)-1-i] ==1:
    flag = 1
  if flag ==1:
    s+=str(answer[len(answer)-1-i])
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = ''

def divide(n):
	if n % (-2) != 0:
		p = (n//(-2))+1
		q = n - p * (-2)
	else:
		p = n//(-2)
		q = n - p * (-2)
	return p,q

while True:
	p,q = divide(N)
	if p == 1 or p == 0:
		ans = str(p) + ans
		break
	N = p
	ans = str(q) + ans
print(ans)

Submission status: Wrong Answer

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

oddsum = [2, 10, 42, 170, 682, 2730, 10922, 43690, 174762, 699050, 2796202, 11184810, 44739242, 178956970, 715827882, 2863311530]
evensum = [1, 5, 21, 85, 341, 1365, 5461, 21845, 87381, 349525, 1398101, 5592405, 22369621, 89478485, 357913941, 1431655765]
two = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184]
ans = 0
while n != 0:
    if n < 0:
        x = 1
        for i in oddsum:
            if n >= -1 * i:
                break
            x += 2
        n += two[x]
    else:
        x = 0
        for i in evensum:
            if n <= i:
                break
            x += 2
        n -= two[x]
    v = 1 << x
    ans += v
print(bin(ans))

Submission status: Wrong Answer

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

def solve(N):
    bin_str = bin(N)
    if bin_str[0] == "-":
        bin_str = bin_str[3:]
    else:
        bin_str = bin_str[2:]

    print(bin_str)
    exit()
    j = 0
    for k in range(len(bin_str)-1, -1, -1):
        ans = bin_str[i] * j

def solve2(N):
    """
    1011
    1001111001000111011100111111
    """
    if N <= 0:
        N *= -1
        print(bin(N)[2:])
        exit()

    ans = ""
    while True:
        if N%(-2) == 0:
            ans = "0" + ans
        else:
            ans = "1" + ans
        N = math.floor(N/(-2))
        if N == 0:
            #ans = "1" + ans
            break
    print(ans)

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

    solve(N)

Submission status: Wrong Answer

Solution code:
n = int(input()) * -1 # なぜか-1した数になる
s = ""
while n != 0:
    s = str(n % 2) + s
    n = n // -2
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
ans = "0"
while(abs(N) > 1):
  S.append(str(abs(-N % (-2))))
  N += N % (-2)
  N = N // (-2)
  
S.append(str(abs(N)))
S.append("1")
S.reverse()

if S == []:
  print(ans)
else:
  ans = ""
  for i in S:
    ans += i
    
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

b = list(bin(abs(n))[2:].zfill(100))
if n == 0:
	print '0'
	quit()


i = 99
while i > 0 :
	if n < 0 and i%2 == 1 and b[i] == '1':
		b[i-1] = 1
		i -= 2
		next

	elif n > 0 and i%2 == 0 and b[i] == '1':
		b[i-1] = 1
		i -= 2
		next

	i -= 1

i = 0
while b[i] == '0' :
	i += 1
b = map(str,b[i:])
print ''.join(b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def div(x):
    a = x //(-2)
    if a*(-2) > x:
        a+=1
    return a
n = int(input())
bi = ""
while n != 0:
    x = div(n)
    if n % (-2) != 0:
        bi = "1"+bi
    elif x != 0:
        bi = "0"+bi 
    n = x
print(bi)