Hi all,

I'm practicing with the 2019 GCJ problems and I'm getting a TLE error on 
the first set when submitting, 
however the time limit is stated to be 20 seconds per set and running the 
code locally it takes less than a second on the first set

I suspect the code could be stuck when running in the judge's envirenment

any helps is appreciated

my code:

def next_prime(a, n):
    number = a
    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
                break
            i += 6
        return number
    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()

Enter code here...


-- 
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/fa39e0e7-508c-4fec-8689-537950edb5f5%40googlegroups.com.

Reply via email to