QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100

#13114. 石头剪刀布

Statistics

有一台石头剪刀布(RPS)机器,它会随机生成石头、剪刀或布。你也有一个类似的简易石头剪刀布机器。在游戏开始前,RPS 机器会生成一个长度为 $n$ 的选择列表,你的机器也会生成一个长度为 $m$ 的选择列表。也就是说,你预先知道 RPS 机器的所有选择以及你机器的所有选择。当然,每种选择都是三种选项(石头、剪刀、布)之一。

现在,你开始玩石头剪刀布游戏。在每一场比赛中,你将 RPS 机器的选择列表与你的机器的选择列表进行比较,并决定谁获胜。但是,你可以在开始比赛前跳过 RPS 机器的一些选择,以找到能让你的机器获得最多胜场的起始位置。一旦你决定开始比赛,你就不能再跳过选择,直到比赛结束。'R' 代表石头,'P' 代表布,'S' 代表剪刀。

例如,假设 RPS 的列表是 "RSPPSSSRRPPR",你的机器的列表是 "RRRR"。为了获得最多的胜场,你应该在跳过三个 RPS 的选择后开始比赛,这样你的机器就能赢得四场比赛中的三场。(参见图 H.1)。平局的情况不予考虑。

图 H.1:当 $n = 12$ 且 $m = 4$ 时,针对 RPS 机器的最佳位置。

给定 RPS 的选择列表和你的选择列表,求出能获得最大胜场数的起始位置。

输入格式

你的程序需要从标准输入读取数据。第一行包含两个正整数 $n$ 和 $m$($1 \le m < n \le 100,000$),其中 $n$ 是 RPS 机器字符串的长度,$m$ 是你的机器字符串的长度。接下来的第一行包含 RPS 机器的选择列表,第二行包含你的机器的选择列表。

输出格式

你的程序需要向标准输出写入数据。第一行应包含一个整数,表示最大胜场数。

样例

输入 1

12 4
RSPPSSSRRPPR
RRRR

输出 1

3

输入 2

12 3
RRRRRRRRRRRR
SSS

输出 2

0

输入 3

12 4
PPPRRRRRRRRR
RSSS

输出 3

2

输入 4

12 4
RRRRRRRRRSSS
RRRS

输出 4

3

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.