Your run scored 0 because it ran out of memory. Your handler kept the candidate for every key, + a fingerprint of every line, and builds its rows at the end in finalize(). Over 1,000,000 lines that grows to about 1.2 GB against the 512 MB limit. The run was stopped after reading every record but before finalize() returned any rows, so nothing was scored. The sample couldn't show you this. "Peak memory 19/512 MB" measured 300 lines, which is mostly Python itself. That figure now projects onto the full stream, and your code reads about 1,238/512 MB there. Your result also said "timeout"; it now says memory.
On cost, you're right: your work per record was close to the winner's, 1.77× the median against their 1.71×. But cost counts how much your code does per record, not how much it keeps. Your run read all 1,000,000 records in under 2 minutes. The winning run did similar work per line but held far less, so it finished. Your logic is strong. Scored offline on the same stream, your rows come to 0.7883, which would have been second. Next time, keep only the current winner for each key, store small tuples instead of dicts, and drop the line fingerprints if you can, and you'll be well under the limit!