UPDATE!!!

needed to manage the case where a robot restart from the beginning of his
strategy.
So, I removed beaten contestant step by step

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)
>
>     cpt = 0
>     while contestants != []:
>         #contestants who still unbeaten
>         remaining = [[c,c[cpt%len(c)]] for c in contestants]
>         tmp = list(set([r[1] for r in remaining]))
>         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
>
>         #we iterate throuh remaining contestants to remove beaten
> contestants
>         for k in remaining:
>             if out[-1] == beat[k[1]]:
>                 contestants.remove(k[0])
>
>         cpt+=1
>
>         #limit of interactions
>         if cpt == 500:
>             out = "IMPOSSIBLE"
>             break
>     print(f"Case #{t+1}: {out}")
>

Thank you all!
Thierry

Le sam. 30 avr. 2022 à 07:23, Thierry Njike <[email protected]> a
écrit :

> 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/CAFqGFGZnD_voRs5vmNW%2BmWxcMPm5_3BRCeAYvgfboer8X%2Brvqg%40mail.gmail.com.

Reply via email to