結果

問題 No.3032 ホモトピー入門
ユーザー tassei903
提出日時 2025-02-21 23:10:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,189 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 82,656 KB
実行使用メモリ 80,712 KB
最終ジャッジ日時 2025-02-21 23:10:54
合計ジャッジ時間 7,657 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 1 RE * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

def rot(s):
    x, y = 0, 0
    ans = 0
    for c in s:
        if c == "R":
            if x == 0:
                if y <= 0:
                    ans += 1
                else:
                    ans -= 1
            x += 1
        elif c == "L":
            if x == 1:
                if y <= 0:
                    ans -= 1
                else:
                    ans += 1
            x -= 1
        elif c == "U":
            if y == 0:
                if x <= 0:
                    ans -= 1
                else:
                    ans += 1
            y += 1
        else:
            if y == 1:
                if x <= 0:
                    ans += 1
                else:
                    ans -= 1
            y -= 1
    assert x == 0 and y == 0 and ans % 4 == 0
    # print(ans)
    return ans
def rot2(s):
    x, y = 0, 0
    ans = 0
    for c in s:
        if c == "R":
            if x == -1:
                if y <= 0:
                    ans += 1
                else:
                    ans -= 1
            x += 1
        elif c == "L":
            if x == 0:
                if y <= 0:
                    ans -= 1
                else:
                    ans += 1
            x -= 1
        elif c == "U":
            if y == 0:
                if x < 0:
                    ans -= 1
                else:
                    ans += 1
            y += 1
        else:
            if y == 1:
                if x < 0:
                    ans += 1
                else:
                    ans -= 1
            y -= 1
    assert x == 0 and y == 0 and ans % 4 == 0
    # print(ans)
    return ans


n, m = na()
ans = 0
for i in range(n):
    s = input()
    #print(rot(s) ,rot(convert(s)))
    X = rot(s)
    Y = rot2(s)
    if X == 0 and Y == 0:
        ans += 1
    else:
        assert X + Y != 0
print(ans)
0