Hello,
I am practicing by solving older code jam problems, and I don't know why my
solution is not accepted (WA). Anyone to check my code and tell me what's
wrong please?
My logic:
I define a maxlen which will be the max length of all contestants
strategies.
I iterate through the list of contestants and compare characters from left
to right and get out with a set of entries that will have a max length of 3
because there is only 3 possible letters.
if the length of the set is 3 it's impossible because whatever you play
someone will beat you
if the length is 2, I append the stronger one between them
if it's one, I append the one that beats it.
When I check the analysis of the problem I can see that I had the same
strategy with the optimal one.
please need to know what is the problem.
Thank you in advance!
Thierry
--
-- You received this message because you are subscribed to the Google Groups
Code Jam group. To post to this group, send email to
[email protected]. To unsubscribe from this group, send email to
[email protected]. For more options, visit this group at
https://groups.google.com/d/forum/google-code?hl=en
---
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/CAFqGFGbybheZX5%3D%3DRnnEoWjv0o7Vk21OLXXqo2TfqKj5v1z30Q%40mail.gmail.com.
T = int(input())
beat = {"P":"S", "R":"P", "S":"R"}
for t in range(T):
N = int(input())
contestants = []
out = ""
maxlen = 0
for i in range(N):
tm = input()
if len(tm) > maxlen:
maxlen = len(tm)
contestants.append(tm)
# contestants.sort(key = lambda x: len(x))
for j in range(maxlen):
tmp = list(set([c[j] for c in contestants if len(c)>j]))
tlen = len(tmp)
if tlen > 2:
out = "IMPOSSIBLE"
break
elif tlen == 2:
if tmp[0] == beat[tmp[1]]:
out+=tmp[0]
else:
out+=tmp[1]
elif tlen ==1:
out+=beat[tmp[0]]
break
print(f"Case #{t+1}: {out}")