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 1100. Final Standings

Python - Accepted solution suggestions ENG + RUS
Posted by nIIIpls 15 Sep 2020 14:23
Hope it will help someone <3

You need to create a dictionary (dict) with keys from '100' to '0' (keys in str format) and values ​​in the form of empty lists (list) - {'100': [], '99': [], ..., '0 ': []}.

After that, you need to read the commands IDs and their results in a loop, and then add the commands IDs to the dictionary with the key as the commands results - if you get the values ​​"11 2", then add the command ID 11 to the dictionary under the key 2 (command result) - [..., '2': [11], ...].

When we finish adding commands, we will have a sorted dictionary and all that remains is to print the values. In the loop we go through the dictionary and if the value (list) is not empty, then we display all the values ​​in the format "command_id dictionary_key".


Нужно создать словарь с ключами от '100' до '0' (ключи в формате str) и значениями в виде пустых списков (list) - {'100': [], '99': [], ..., '0': []}.

После этого нужно в цикле считывать ID команд и их результат, после чего добавлять ID команд в словарь с ключом в виде результата команды - если получили значения "11 2", значит добавляем ID команды 11 в словарь под ключом 2 (результат команды) - [..., '2': [11], ...].

Когда закончим добавление команд то у нас будет уже отсортированный словарь и останется только вывести значения. В цикле проходим по словарю и если значение (список) не пустой, то выводим все значения в формате "ID_команды ключ_словаря".
Re: Python - Accepted solution suggestions ENG + RUS
Posted by BENDER 24 Oct 2021 21:43
There is no bubble sort, but I finally did it as you suggested to fit in memory limit. Thnx)
import sys

dict ={}
for x in range(100,-1,-1):
    dict.update({str(x):[]})

def process(line):
    k = [x for x in line.split()]
    if len(k)!=1:
        dict[k[1]].append(k[0])

for line in sys.stdin:
    process(line)

for x, y in dict.items():
    if y:
        for t in y:
            print(t, x)