結果
問題 |
No.3032 ホモトピー入門
|
ユーザー |
![]() |
提出日時 | 2025-02-21 23:43:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 572 ms / 2,000 ms |
コード長 | 1,987 bytes |
コンパイル時間 | 510 ms |
コンパイル使用メモリ | 82,460 KB |
実行使用メモリ | 116,364 KB |
最終ジャッジ日時 | 2025-02-21 23:44:02 |
合計ジャッジ時間 | 9,134 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
n, m = map(int, input().split()) S = [input() for _ in range(n)] t = "ULDR" dy = [1, 0, -1, 0] dx = [0, -1, 0 , 1] ans = 0 for i in range(n): s = S[i] x, y = 0, 0 rot0 = 0 rot1 = 0 stuck = [-1] pr0 = pr1 = 0 for j in range(m): ind = t.index(s[j]) nx, ny = x+dx[ind], y+dy[ind] if (x, nx) == (0, 1): if 1 <= y: rot0 += 1 else: rot0 -= 1 if (x, nx) == (1, 0): if 1 <= y: rot0 -= 1 else: rot0 += 1 if (x, nx) == (-1, 0): if 1 <= y: rot1 += 1 else: rot1 -= 1 if (x, nx) == (0, -1): if 1 <= y: rot1 -= 1 else: rot1 += 1 if (y, ny) == (0, 1): if x <= -1: rot0 += 1 rot1 += 1 elif x <= 0: rot0 += 1 rot1 -= 1 else: rot0 -= 1 rot1 -= 1 if (y, ny) == (1, 0): if x <= -1: rot0 -= 1 rot1 -= 1 elif x <= 0: rot0 -= 1 rot1 += 1 else: rot0 += 1 rot1 += 1 x, y = nx, ny if rot0 % 4 == 0 and pr0 != rot0: if pr0 < rot0: if stuck[-1] == 0: stuck.pop() else: stuck.append(1) else: if stuck[-1] == 1: stuck.pop() else: stuck.append(0) pr0 = rot0 if rot1 % 4 == 0 and pr1 != rot1: if pr1 < rot1: if stuck[-1] == 2: stuck.pop() else: stuck.append(3) else: if stuck[-1] == 3: stuck.pop() else: stuck.append(2) pr1 = rot1 if len(stuck) == 1: ans += 1 print(ans)