CF2169B.Drifting Away

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There's a river flowing in front of Monocarp's house, which can be represented as a strip of cells. In some cells, there is a strong current, while in others, there is no current. It can be represented as a string ss, consisting of the following characters:

  • the "less-than" sign ('<') — leftward current;
  • the "greater-than" sign ('>') — rightward current;
  • an asterisk ('*') — no current.

At first, Monocarp chooses the cell to start his journey along the river at.

If there is a current in the cell, where Monocarp is at the moment, he is carried to the neighboring cell in the direction of the current. If there is no neighboring cell (i. e., a leftward current in cell 11 or a rightward current in cell nn), Monocarp ends up on the shore. Each move takes one minute.

If there is no current in the cell, where Monocarp is at the moment, he rows to the neighboring cell on the left or to the neighboring cell on the right. If there is no neighboring cell in the direction where Monocarp decides to row to, he ends up on the shore. Each move also takes one minute.

Monocarp wants to sail along the river for as long as possible. If Monocarp can sail infinitely, print −1-1. Otherwise, print the maximum time Monocarp can sail along the river before ending up on the shore.

Monocarp 的家门前有一条河流,该河流可被建模为一条由若干单元格组成的带状区域。其中某些单元格中存在强水流,而其余单元格中则无水流。该河流可用一个字符串 ss 表示,字符串中包含以下字符:

  • 小于号('<')——表示向左的水流;
  • 大于号('>')——表示向右的水流;
  • 星号('*')——表示无水流。

初始时,Monocarp 选择河流中的某个单元格作为其航行的起点。

  • 若 Monocarp 当前所处单元格中存在水流,则他将被水流带动至相邻单元格,方向与水流方向一致。若该方向上不存在相邻单元格(即:在第 11 个单元格中遇到向左的水流,或在第 nn 个单元格中遇到向右的水流),则 Monocarp 到达岸边。每次移动耗时一分钟。
  • 若 Monocarp 当前所处单元格中无水流,则他可自行划桨,选择移至左侧相邻单元格或右侧相邻单元格。若所选方向上不存在相邻单元格,则 Monocarp 到达岸边。每次移动同样耗时一分钟。

Monocarp 希望尽可能延长其在河上的航行时间。若 Monocarp 可以无限期航行,请输出 −1-1;否则,请输出 Monocarp 在到达岸边前所能航行的最长时间(单位:分钟)。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The only line of each test case contains a string ss (1≤∣s∣≤3⋅1051 \le |s| \le 3 \cdot 10^5), consisting only of characters '<' (leftward current), '>' (rightward current), '*' (no current). The ASCII codes are 6060, 6262, and 4242, respectively.

An additional constraint on the input: the total length of strings ss over all test cases does not exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例仅有一行,包含一个字符串 ss(1≤∣s∣≤3⋅1051 \le |s| \le 3 \cdot 10^5),该字符串仅由字符 '<'(向左的水流)、'>'(向右的水流)和 '*'(无水流)组成。它们对应的 ASCII 码分别为 6060、6262 和 4242。

输入的额外约束:所有测试用例中字符串 ss 的总长度不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, output a single integer:

  • −1-1, if Monocarp can sail along the river infinitely;
  • the maximum time Monocarp can sail along the river before ending up on the shore, otherwise.

对于每个测试用例,输出一个整数:

  • 若 Monocarp 可以沿河流无限航行,则输出 −1-1;
  • 否则,输出 Monocarp 在抵达岸边之前能够沿河流航行的最长时间。

输入输出样例

  • 输入#1

    4
    *****
    &lt;&lt;&lt;&gt;
    &gt;*&lt;
    *

    输出#1

    -1
    3
    -1
    1

输入解题思路,AI测评打分。不知道怎么写?

首页