Yes, Bartholomew, that is what I did in my solution. I tested this locally with m=1000000 and it took 4 seconds to build the mapping, so I figured it was good enough and also that searching for the answer in each test case would time out. https://codingcompetitions.withgoogle.com/codejam/submissions/0000000000051635/ZGV2am9l Saeon, it's Python 2, but take a look.
On Sat, Apr 13, 2019 at 9:45 PM Bartholomew Furrow <[email protected]> wrote: > I don't know how quickly Python can compute a million numbers modulo 18, > but if it's too slow, you could consider doing a precomputation, where you > figure out what each possible number is modulo each of your primes, then > make a dict mapping from (tuple of moduli) to number. That way you can do a > quick lookup in each test case. > > On Sat, Apr 13, 2019 at 4:10 PM Xiongqi ZHANG <[email protected]> > wrote: > >> possible = [i for i in possible if i%primes[night] == sum(a)] >> >> it should be sum(a) % primes[night] >> >> >> On Sat, Apr 13, 2019 at 2:51 PM Saeon Piremakumar <[email protected]> >> wrote: >> >>> Kept getting a TLE for this problem, is my code slow or is it just wrong >>> somewhere >>> . >>> ##### CODE ######### >>> import sys >>> t, n, m = map(int, input().split()) >>> >>> def solve(n,m): >>> >>> primes = [16,9,5,7,11,13,17] >>> possible = list(range(1,m+1)) >>> for night in range(n): >>> for dummy in range(18): >>> print (primes[night],end = " ") >>> sys.stdout.flush() >>> >>> a = list(input().split()) >>> a = [int(i) for i in a] >>> possible = [i for i in possible if i%primes[night] == sum(a)] >>> if len(possible) == 1: >>> print(possible[0]) >>> sys.stdout.flush() >>> break >>> >>> for _ in range(t): >>> solve(n,m) >>> >>> ################### >>> Thanks >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Google Code Jam" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> To post to this group, send email to [email protected]. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/google-code/23e6dabb-6c75-4188-8b4a-18a3e52b029b%40googlegroups.com >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google Code Jam" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/google-code/CAGDEU-KJuWSoq4Wk7zR4XC7bV%2B2S4wgXfhDXZwmPdSjx0j0vTg%40mail.gmail.com >> <https://groups.google.com/d/msgid/google-code/CAGDEU-KJuWSoq4Wk7zR4XC7bV%2B2S4wgXfhDXZwmPdSjx0j0vTg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-code/CAHaiWHMgqPAvENvhC%3D4TvJsfLfxGmtUH4Zg%2BWmgfBeGiPvVWrg%40mail.gmail.com > <https://groups.google.com/d/msgid/google-code/CAHaiWHMgqPAvENvhC%3D4TvJsfLfxGmtUH4Zg%2BWmgfBeGiPvVWrg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/CAMAzhzhUcmuJ3%2BFkvg6ykfYy77TQSabzyAZR%2B4ZmzsH5%2Bg%3Dd4g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
