Your code fails for the following case: Plaintext: A B A B A B C ........ Ciphertext: 2 2 2 2 2 6 .. The solution is to backtrace from where the sequence ends. This is what your code produces 1 5 6 2 2 2 2 2 3 Case #1: BABABAC
1 5 6 2 2 2 2 2 3 Case #1: BABABAC Same Result in Both the cases. On Tuesday, April 9, 2019 at 8:38:14 PM UTC+5:30, [email protected] wrote: > import math > > def solve(): > _, l = map(int, input().split()) > p = [int(i) for i in input().split()] > > fs, sc = p[0:2] > pr = math.gcd(fs, sc) if fs != sc else int(math.sqrt(fs)) > > vals = [] > vals.append(fs / pr) > vals.append(pr) > vals.append(sc / pr) > > for i in range(2, l): > vals.append(p[i] / vals[i]) > > prs = list(sorted(set(vals))) > > return ''.join([chr(65 + prs.index(i)) for i in vals]) > > for t in range(1, 1 + int(input())): > print('Case #{}: {}'.format(t, solve())) -- 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/98fd9879-4dda-49d1-a672-50db8b61af76%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
