Created
May 5, 2018 11:39
-
-
Save jakab922/beea9dfc3b286808ba2ea86a50e87ddf to your computer and use it in GitHub Desktop.
Google Code Jam 18 / 1C / Lollipop shop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import choice | |
import sys | |
t = int(raw_input().strip()) | |
LOW, HIGH = 0.005, 0.1 | |
def calc(p, count, curr, left): | |
return pow(p, count) * pow(1.0 - p, curr - count) * pow(1.0 - p, left) | |
for case in xrange(1, t + 1): | |
# sys.stderr.write("%s\n" % case) | |
# sys.stderr.flush() | |
n = int(raw_input().strip()) | |
counts = [0] * n | |
has = [True] * n | |
for i in xrange(1, n + 1): | |
curr = map(int, raw_input().strip().split())[1:] | |
if curr == []: | |
print -1 | |
sys.stdout.flush() | |
continue | |
for el in curr: | |
counts[el] += 1 | |
probs = [min(max(counts[j] / float(i), LOW), HIGH) for j in xrange(n)] | |
# sys.stderr.write("probs: %s\n" % probs) | |
# sys.stderr.flush() | |
left = n + 1 - (i + 1) | |
stuff = [] | |
for el in curr: | |
stuff.append((calc(probs[el], counts[el], i, left), el)) | |
stuff = sorted(stuff, reverse=True) | |
# sys.stderr.write("stuff: %s\n" % stuff) | |
# sys.stderr.flush() | |
found = None | |
for _, el in stuff: | |
if has[el]: | |
found = el | |
has[el] = False | |
break | |
if found is not None: | |
print found | |
else: | |
print -1 | |
sys.stdout.flush() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment