37012023-03-02 11:34:14DoraAutókódoláspython3Time limit exceeded 34/50300ms12676 KiB
def count_one_bits(n: int) -> int:
    kettes = bin(n)[2:]
    count = 0
    for i in range(len(kettes)):
        tmp = int(kettes[i])
        if tmp == 1:
            count += 1
    return count

n = int(input())
one_bits = count_one_bits(n)

prev_code = n - 1
while prev_code >= 1 and count_one_bits(prev_code) != one_bits:
    prev_code -= 1

next_code = n + 1
while count_one_bits(next_code) != one_bits:
    next_code += 1

if prev_code > 0:
    print(prev_code)
else:
    print("-1")

if next_code > 0:
    print(next_code)
else:
    print("-1")
SubtaskSumTestVerdictTimeMemory
base34/50
1Accepted0/017ms11284 KiB
2Time limit exceeded0/0300ms4068 KiB
3Accepted2/217ms11648 KiB
4Accepted2/218ms12060 KiB
5Accepted2/217ms12444 KiB
6Accepted2/217ms12368 KiB
7Accepted2/217ms12220 KiB
8Accepted4/423ms12404 KiB
9Accepted4/417ms12564 KiB
10Accepted4/417ms12676 KiB
11Accepted4/417ms12404 KiB
12Accepted4/417ms12648 KiB
13Time limit exceeded0/4254ms5220 KiB
14Accepted4/492ms12552 KiB
15Time limit exceeded0/4266ms5172 KiB
16Time limit exceeded0/4268ms5436 KiB
17Time limit exceeded0/4240ms5448 KiB