b2.py (319B)
1 import fileinput 2 3 with fileinput.input() as lines: 4 rows = [line[:-1] for line in lines] 5 6 t = [1 if x == 'S' else 0 for x in rows[0]] 7 for row in rows[1:]: 8 next = [0] * len(row) 9 for i in range(len(row)): 10 if row[i] == '^': 11 next[i-1] += t[i] 12 next[i+1] += t[i] 13 else: 14 next[i] += t[i] 15 t = next 16 17 print(sum(t))