A few suggestions: 1. Try to come up with a "worst case" input. One that's allowed by the constraints, but that makes your code run as slowly as possible. Assume the real test input contains cases like that. In this problem, a good place to start is with N=10000. 2. When you're testing your code, you probably don't need to type the inputs in. If I were running that, I'd do something like python3 a.py < a.samplein, where a.samplein is a file I made that contains the sample input. That's called *input redirection*, and it tells your OS to pass a.samplein's contents to your program as stdin. 3. This problem is the third problem in the set, rather than the first or second, because it isn't straightforward to solve! Only 19% of competitors solved the first input set, and 9% solved the second input set. A response of TLE is what a lot of people's code would get. The challenge here is coming up with an efficient way to solve the problem.
If you aren't sure about how to solve this problem efficiently, you can check out the analysis: it's on the same page as the problem, but look for the word "analysis." It's hard to spot. That wouldn't be available to you during the contest, but might teach you some useful stuff. Don't be discouraged if this problem is kind of tough! There are tons of other problems you can check out to build your skill. Good luck! Bartholomew On Sat, Mar 14, 2020 at 8:04 AM أحمد خطيب <[email protected]> wrote: > H all, > > I started practicing some previous GCJ problems in preperation for GCJ > 2020, I'm getting a TLE error on the first set on my submitted code, > however the time limit is specified as 20 seconds per set,running my code > locally it takes less that one second removing the time it takes me to type > down the inputs. > > Any help is appreciated, > > code: > ======================================= > > def next_prime(a, n): > for number in range(a+1, n): > if (number % 2 == 0) or (number % 3 == 0): > continue > i = 5 > while i*i <= number: > if number % i == 0 or number % (i + 2) == 0: > i += 6 > continue > i += 6 > return number > > > def main(): > t = input() > for x in range(int(t)): > n, l = input().split(' ') > n = int(n) > l = int(l) > ans = '' > pangram = dict() > prime_list = [] > > p = input().split(' ') > a = 3 > while int(p[0]) % a != 0: > a = next_prime(a, n) > > if int(p[1]) % a != 0: > prime_list.append(a) > prime_list.append(int(p[0])/a) > else: > prime_list.append(int(p[0])/a) > prime_list.append(a) > > for i in range(1, len(p)): > num = int(p[i]) > prime_list.append(num/prime_list[-1]) > > sorted_list = prime_list.copy() > sorted_list = list(dict.fromkeys(sorted_list)) > sorted_list.sort() > alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' > for num in range(len(alphabets)): > pangram[sorted_list[num]] = alphabets[num] > > for prime in prime_list: > ans += str(pangram.get(prime)) > print('Case #' + str(x + 1) + ': ' + ans) > > main() > > > =============================== > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/google-code/e210f8cf-2ac9-46fa-9bd7-f4d454dedabb%40googlegroups.com > <https://groups.google.com/d/msgid/google-code/e210f8cf-2ac9-46fa-9bd7-f4d454dedabb%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/google-code/CAHaiWHML10RmL17Rgm47ThWKOZwubM9isVBmFEaAR5yJnY-yWg%40mail.gmail.com.
