ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

3-rd test time limit exceded, but why? Python 3.8
Posted by Dmitry 13 Aug 2022 10:11
I have two solutions!
Time: 1.15 solution:
numbers = []

for i in range(int(input())):
    numbers.append(int(input()))

print_s = ''

for n in numbers:
    if len(print_s) > 0:
        print_s += ' '
    number = int((n * 2) ** 0.5)
    y = (number * (number - 1)) // 2
    y2 = y + number
    y += 1
    if n <= y2:
        print_s += '1' if n == y  else '0'
    else:
        print_s += '1' if n == y + number else '0'
print(print_s)

Time: 1.15 solution:
numbers = []

for i in range(int(input())):
    numbers.append(int(input()))

print_s = ''

for n in numbers:
    if len(print_s) > 0:
        print_s += ' '
    length = 1
    while n > length:
        n -= length
        length += 1
    print_s += '1' if n == 1 else '0'
print(print_s)
Help me pls!!

Edited by author 13.08.2022 10:14
Re: 3-rd test time limit exceded, but why? Python 3.8
Posted by Daniil Seryodkin 2 Dec 2022 09:50
n=int(input())
numbers=[]
for i in range(0,n):
    numbers.append(int(input()))

print_s = ''

for n in numbers:
    if len(print_s) > 0:
        print_s += ' '
    length = 1
    while n > length:
        n -= length
        length += 1
    print_s += '1' if n == 1 else '0'
print(print_s)