You are viewing a single comment's thread. Return to all comments →
Ok, let's do an honest test here to see who is mistaken here:
$ cat captain-bruce.py 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()) $ cat captain-bruce-ver2.py 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 room_more_mem: target = room_more_mem if m in rooms else rooms target.add(m) print(rooms.difference(room_more_mem).pop()) $ cat captain-tigran.py k = int(input()) numbers = list(map(int, input().split())) numset = set(numbers) print(((sum(numset)*k)-(sum(numbers)))//(k-1)) $ time python3 captain-tigran.py < input01.txt 2710 real 0m0.628s user 0m0.552s sys 0m0.076s $ time python3 captain-bruce.py < input01.txt 2710 real 0m1.006s user 0m0.957s sys 0m0.048s $ time python3 captain-bruce-ver2.py < input01.txt 2710 real 0m0.750s user 0m0.686s sys 0m0.064s
So, the difference is: 0.750 - 0.628 = 0.122s i.e. about 19%, namely my version is 19% faster on this particular (rather large) sample.
Seems like cookies are disabled on this browser, please enable them to open this website
The Captain's Room
You are viewing a single comment's thread. Return to all comments →
Ok, let's do an honest test here to see who is mistaken here:
So, the difference is: 0.750 - 0.628 = 0.122s i.e. about 19%, namely my version is 19% faster on this particular (rather large) sample.