I did my code in Python3, and seems that I had followed the analysis given for
Test Set 2.
Would it be possible for someone to go through the code and let me know what is
wrong?
--------------------------
#function to delete multiple items off of a list given another list containing
the indices to be deleted
def delete_multi(c,idx):
popped_count = 0
for i in range(0,len(idx)):
pop_index = idx[i] - popped_count
c.pop(pop_index)
popped_count +=1
return c
T = int(input())
A_Array= []
for i in range(0,T):
n = int(input())
s = []
# We read the maximum length of a program by an opponent. This is the
maximum length of our program.
max_len = 0
for j in range(0,n):
C = input()
if(len(C)>max_len):
max_len = len(C)
s.append(C)
# Store opponents' program as an array s, along with the maximum length
of program contained in s.
A_Array.append([s,max_len])
for i in range(0,T):
s = A_Array[i]
m = s[1] # maximum length of the program
c = s[0] # array containing all the programs
output = ''
# start iterating through to the maximum length of the programs
available
for j in range(0,m):
# there may be no players left by now because we defeated all
players by this round
if(len(c)==0):
break
this_column= []
counter = ''
r_index, s_index, p_index = [],[],[]
# for each opponent program,
# check the element using modulo counting
# add the index of the opponent's row, based on whether they
played R, P or S on this round
for k in range(0,len(c)):
series = c[k]
ele = j%len(series)
play = series[ele]
if(play=='R'):
r_index.append(k)
elif(play=='P'):
p_index.append(k)
elif(play=='S'):
s_index.append(k)
this_column.append(play)
x = list(set(this_column))
# for this round
# if opponents have played R, P and S, there is no possible
solution at all
# if all the opponents played exact same move, then we can
defeat all the opponents
# if the opponents played two moves (some played R, some played
P etc.) then we tie some and defeat the others
# ***
# after each round, remove the defeated opponents to check the
next round
if(len(x)>2):
output = "IMPOSSIBLE"
break
elif(len(x)==1):
if('R' in x):
counter = 'P'
c = delete_multi(c,r_index)
if('S' in x):
counter = 'R'
c = delete_multi(c,s_index)
if('P' in x):
counter = 'S'
c = delete_multi(c,p_index)
else:
if(('R' in x) and ('S' in x)):
counter = 'R'
c = delete_multi(c,s_index)
elif(('P' in x) and ('S' in x)):
counter = 'S'
c = delete_multi(c,p_index)
elif(('R' in x) and ('P' in x)):
counter = 'P'
c = delete_multi(c,r_index)
output += counter
print("Case #%i: %s"%((i+1),output))
--
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/0878f5cf-542b-491e-a625-c668e0057cb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.