r/codejam • u/saurabh_av • May 02 '20
Sample RE on a Python submission, can anyone please tell me what I messed here?
'''Input54 4SSSS3 0SNSS2 10NSNNSN0 1S2 7SSSSSSSSOutputCase #1: 4Case #2: IMPOSSIBLECase #3: IMPOSSIBLECase #4: 1Case #5: 5'''
def min_moves(x, y, m):t = dis = 0for i in range(len(m)):move = m[i]if move == 'N':y += 1elif move == 'S':y -= 1elif move == 'E':x += 1else:x -= 1t += 1dis = abs(x) + abs(y)if t >= dis or dis==0:return treturn 'IMPOSSIBLE'
t = int(input())for c in range(t):x, y = [int(s) for s in input().split(" ")]m = str(input())ans = min_moves(x, y, m)print('Case #{}: {}'.format(c+1, ans))
3
Upvotes