The Captain's Room

  • + 3 comments

    Sorry, I didn't know how to embed code in the message. Now I have realised that triple backticks (like in github) seem to do the job, so here is the code:

    1. Implementation of your idea:
    nom = int(input())
    members = list(map(int, input().split()))
    rooms = set()   # Contains all the rooms.
    room_more_mem = set()   # Contains only the rooms with families.
    
    for m in members:
        if m not in rooms:
            rooms.add(m)
        else:
            room_more_mem.add(m)
    print(rooms.difference(room_more_mem).pop())
    
    1. The "alternative" and faster implementation.
    k = int(input())
    numbers = list(map(int, input().split()))
    numset = set(numbers)
    print(((sum(numset)*k)-(sum(numbers)))//(k-1))
    

    If you run both versions on the large input01.txt (with 823 in the first line and total filesize 10390383 bytes --- it is one of their test cases) you will see that this particular implementation of your idea is slower.