結果
| 問題 | 
                            No.3032 ホモトピー入門
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Kude
                         | 
                    
| 提出日時 | 2025-02-21 22:16:01 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 564 ms / 2,000 ms | 
| コード長 | 912 bytes | 
| コンパイル時間 | 183 ms | 
| コンパイル使用メモリ | 82,908 KB | 
| 実行使用メモリ | 114,640 KB | 
| 最終ジャッジ日時 | 2025-02-21 22:16:09 | 
| 合計ジャッジ時間 | 8,201 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
ソースコード
n, m = map(int, input().split())
ans = 0
for _ in range(n):
    s = input()
    d = []
    x = y = 0
    for c in s:
        if c == 'L':
            if x == 0 and y <= 0:
                d.append(0)
            elif x == 0 and y >= 1:
                d.append(1)
            elif x == 1 and y <= 0:
                d.append(2)
            elif x == 1 and y >= 1:
                d.append(3)
            x -= 1
        elif c == 'R':
            x += 1
            if x == 0 and y <= 0:
                d.append(0)
            elif x == 0 and y >= 1:
                d.append(1)
            elif x == 1 and y <= 0:
                d.append(2)
            elif x == 1 and y >= 1:
                d.append(3)
        elif c == 'U':
            y += 1
        else:
            y -= 1
        if len(d) >= 2 and d[-1] == d[-2]:
            d.pop()
            d.pop()
    if len(d) == 0:
        ans += 1
print(ans)
            
            
            
        
            
Kude