CSES - Datatähti 2017 alku - Results
Submission details
Task:Bittijono
Sender:inkeri
Submission time:2016-10-05 22:34:31 +0300
Language:Python2
Status:READY
Result:29
Feedback
groupverdictscore
#1ACCEPTED10
#2ACCEPTED19
#30
Test results
testverdicttimegroup
#1ACCEPTED0.06 s1details
#2ACCEPTED1.58 s2details
#3--3details

Code

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

class Bittijono():
    def __init__(self):
        self.bitit = [[0, 1],[1, 0]]

    def getBitti(self, luku, length, bitti):
        if length > 2:
            # print ("Luku: " + str(luku))
            # print ("Koko pituus: " + str(length))
            length /= 4
            # print ("Pätkän pituus: " + str(length))
            if luku > 3 * length:
                a = 0
                luku -= 3 * length
            else:
                a = 1
                luku -= length * 2
            while luku <= length / 2:
                length /= 2
            # print ("Kohta pätkässä: " + str(luku))
            # print ("Bitti: " + str(self.bitit[bitti][a]))
            return self.getBitti(luku, length, self.bitit[bitti][a])

        return self.bitit[bitti][luku - 1]

def main():
    jono = Bittijono()
    amount = int(input(""))

    for i in xrange(amount):
        luku = int(input(""))
        length = int(math.pow(2, math.ceil(math.log(luku, 2))))
        print jono.getBitti(luku, length, 0)

def luoJono(luku):
    jono = [0, 1]
    while len(jono) < luku:
        uusijono = []
        for bitti in jono:
            if bitti == 0:
                uusijono += [0, 1]
            else:
                uusijono += [1, 0]
        jono = uusijono
    return jono

def test(maara):
    jono = Bittijono()
    lista = [i + 1 for i in range(maara)]
    jono2 = luoJono(lista[maara - 1])
    vaarat = []

    # for luku in lista:
    #     a = ""
    #     a += str(luku) + ": "
    #     length = math.pow(2, math.ceil(math.log(luku, 2)))
    #     print a + str(jono.getBitti(luku, length, 0))

    for luku in lista:
        length = int(math.pow(2, math.ceil(math.log(luku, 2))))
        bitti = jono.getBitti(luku, length, 0)
        if bitti != jono2[luku - 1]:
            vaarat.append(luku)

    print vaarat

main()
#test(1000000)

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
100
62
9
12
73
...

correct output
1
1
1
0
1
...

user output
1
1
1
0
1
...

Test 2

Group: 2

Verdict: ACCEPTED

input
100000
565433
141881
120108
825392
...

correct output
1
1
0
0
1
...

user output
1
1
0
0
1
...

Test 3

Group: 3

Verdict:

input
100000
374768524402011755
937067109466254318
389256426086302899
932585725667010169
...

correct output
0
1
1
1
1
...

user output
(empty)