結果

問題 No.8069 Torn Documents
ユーザー maspy
提出日時 2020-04-01 23:09:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 890 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2024-07-21 21:39:58
合計ジャッジ時間 3,395 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = map(int, readline().split())
S = readline().rstrip().decode()
wall = set()
path = set()
path.add((A, B))

H = A
W = B

for s in S:
    if s == 'R':
        if (A, B + 1) not in path:
            wall.add((A, B + 1))
        else:
            B += 1
    elif s == 'L':
        if (A, B - 1) in wall or B == 0:
            continue
        B -= 1
        path.add((A, B))
    elif s == 'U':
        if (A - 1, B) in wall or A == 0:
            continue
        A -= 1
        path.add((A, B))
    elif s == 'D':
        if (A + 1, B) not in path:
            wall.add((A + 1, B))


if (0, 0) not in path:
    print(-1)
    exit()

wall = [(x, y) for x, y in wall if 0 <= x <= H and 0 <= y <= W]
print(len(wall))
for x, y in wall:
    print(x, y)
0