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 1263. Elections

Python 3, wrong on test 2
Posted by Krasheninnikova 16 Aug 2019 21:39
n, m = map(int,input().split(' '))
voices = []
p = ['p']
h = 0
for i in range(m):
    voices.append(int(input()))

for i in range(n):
    p.append(0)

for i in voices:
    for c in range(n+1):
        if i == c:
            p[c] += 1

for i in range(1, len(p)):
    h = p[i] / m * 100
    p[i] = str(round(h, 2))
    if len(p[i]) == 4:
        p[i] += '0'
    print(p[i] + '%')
Help. what's wrong
Re: Python 3, wrong on test 2
Posted by Gilles Deleuze 16 Aug 2019 21:55
n, m = map(int,input().split(' '))
voices = []
p = ['p']
h = 0
for i in range(m):
    voices.append(int(input()))

for i in range(n):
    p.append(0)

for i in voices:
    for c in range(n+1):
        if i == c:
            p[c] += 1

for i in range(1, len(p)):
    h = p[i] / m * 100
    print(f'{h:.2f}%')



This is your code that prints the right answer. Python 3 uses BANKER'S rounding while the problem asks you to the MATHEMATICAL rounding. I used 'f-string' to perform MATHEMATICAL rounding. Anyways, the solution is not fast enough - try to come up with some speed-ups.