QOJ.ac

QOJ

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

#165. 线性戏法

Statistics

你正面对着一个线性游戏装置。它由 $N$ 个排成一行的面板组成,每个面板上都显示着一个向右或向左的箭头。

你可以从任意一个面板进入该装置。一旦你踏上一个面板,你将被迫沿着该面板上箭头所指的方向移动,并且该面板会立即被移除。你将保持相同的方向移动,直到你到达另一个面板;如果你到达了一个面板,你将转向(或保持)该面板上箭头所指的方向。你经过的面板也会被移除。你重复此过程,当你的当前方向上没有面板时,你就会离开该装置。

例如,当装置如下图所示时:

如果你首先踏上从左往右数的第 2 个面板,你的移动过程如下:

  • 向右移动并移除第 2 个面板。
  • 向左移动并移除第 3 个面板。
  • 向右移动并移除第 1 个面板。
  • 向右移动并移除第 4 个面板。
  • 向左移动并移除第 5 个面板。
  • 离开装置。

给定一个包含 $N$ 个面板的装置,计算你离开装置后移除面板的最大数量。

输入格式

输入包含两行。第一行包含一个整数 $N$ ($1 \le N \le 10^5$),表示装置中面板的数量。第二行包含一个长度为 $N$ 的字符串 $S$,由字符 ‘>’ 或 ‘<’ 组成。$S$ 的第 $i$ 个字符对应从左往右数第 $i$ 个面板上箭头的方向。‘<’ 和 ‘>’ 分别表示向左和向右的方向。

输出格式

输出你离开装置后移除面板的最大数量。

样例

样例输入 1

7
>><><<<

样例输出 1

7

样例输入 2

5
>><<<

样例输出 2

5

样例输入 3

6
><<><<

样例输出 3

6

样例输入 4

7
<<><<>>

样例输出 4

5

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.