QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 256 MB 总分: 100

#12728. 轻松阅读

统计

Eugene 正在读一本无聊的书。为了让这个过程变得有趣,他同时在画一幅画。他有一张被分成若干方格的方格纸。起初,所有的格子都是空的。

Eugene 先涂满一个格子。然后他随机翻开书的一页开始阅读。每当他在文中看到字母 ‘u’ 时,他会将笔向上移动一格,然后涂满笔下的格子。每当他看到字母 ‘d’ 时,他做同样的动作,但将笔向下移动一格而不是向上。对于字母 ‘l’ 和 ‘r’,他分别向左和向右移动一格。如果他想要涂的格子已经被涂过,他会再次涂一遍。

你找到了一张纸和这本书的文本。现在你想知道纸上的这幅画是否可能是 Eugene 在阅读过程中某个时刻画出来的。请记住,Eugene 可能只阅读了文本的某个子串。

输入格式

第一行包含一个整数 $l$ — 文本的长度 ($1 \le l \le 100\,000$)。第二行包含一个长度为 $l$ 的字符串 — 文本。它仅包含小写英文字母、空格、逗号和句号。文本既不以空格开头,也不以空格结尾。

第三行包含两个正整数 $n$ 和 $m$ — 图片的尺寸 ($2 \le n \times m \le 100\,000$)。接下来的 $n$ 行,每行包含一个长度为 $m$ 的字符串。涂色的格子用 ‘X’ 表示,空格子用 ‘.’ 表示。保证图片中至少有两个涂色的格子。

这 $n$ 行中的第一行对应图片的顶部,最后一行对应图片的底部。

输出格式

如果这幅画可能是 Eugene 画出来的,在第一行输出 “YES”。在第二行输出两个整数 $b$ 和 $e$,使得如果 Eugene 阅读了从第 $b$ 个到第 $e$ 个(包含 $b$ 和 $e$)的所有字母,他会画出与输入中完全相同的图片 ($1 \le b \le e \le l$)。如果有多种解,输出其中任意一个。

如果这幅画不可能是 Eugene 画出来的,输出 “NO”。

样例

样例输入 1

43
you should read statement really carefully.
3 6
...XX.
..XXX.
...XXX

样例输出 1

YES
3 42

样例输入 2

43
you should read statement really carefully.
3 2
XX
XX
XX

样例输出 2

NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.