QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 2048 MB 총점: 100

#16064. Wormly

통계

Jonly 正在编写他的第一款电脑游戏。在片头场景中,他希望主角 Wormly 穿过一座名为 Bridgely 的桥。Wormly 是一只由 $b$ 个相同的圆形气泡和 $l$ 条腿组成的蠕虫。在任何时刻,每条腿都必须位于其中一个气泡的下方,且每个气泡下方最多只能有一条腿。Bridgely 本应由 $n$ 块木板组成,每块木板的宽度等于 Wormly 每个气泡的直径。然而,其中一些木板缺失了。

在任意时刻,Wormly 可以精确执行以下操作之一:

  • 将其一条腿向前移动任意数量的(可能缺失的)木板。移动后,该腿必须位于一块现存的木板上,且处于 Wormly 的某个气泡下方。腿不允许越过其他腿。
  • 将其所有气泡向前移动一块木板,而其腿保持在原木板上。移动后,每条腿仍必须处于 Wormly 的某个气泡下方。

在这个例子中,最后一条腿唯一可能的移动是到位置 $b$。(位置 $a$ 处的木板缺失了,因此腿不能移动到那里。要到达位置 $c$,最后一条腿必须越过第一条腿。)此外,在这个例子中,不允许将所有气泡向前移动,因为这样会导致 Wormly 的最后一条腿上方没有气泡。

现在 Jonly 想知道 Wormly 到达 Bridgely 尽头需要播放多长时间的动画。最初,Wormly 的气泡正处于桥最左侧的 $b$ 块木板上方,其腿位于最左侧的 $l$ 块木板上。在动画结束时,Wormly 的气泡必须正处于最右侧的 $b$ 块木板上方,其腿必须位于最右侧的 $l$ 块木板上。

Bridgely 最左侧和最右侧的 $l$ 块木板均未缺失。

输入格式

第一行包含一个正整数:测试用例的数量,最多为 100。接下来对于每个测试用例:

  • 一行包含三个整数 $l$、$b$ 和 $n$($1 \le l \le b \le n \le 1\,000\,000$):分别表示腿的数量、气泡的数量和桥的长度。
  • 一行包含一个由 $n$ 个字符组成的字符串,字符为 '0' 或 '1',描述 Bridgely。'1' 表示有木板,'0' 表示缺失木板。

输出格式

对于每个测试用例:

  • 输出一行,包含一个整数:Wormly 穿过 Bridgely 所需的最少步数。如果无法在满足约束条件的情况下穿过,则该行应输出 "IMPOSSIBLE"。

样例

输入样例 1

3
1 2 2
11
2 3 5
11011
1 3 5
11011

输出样例 1

1
IMPOSSIBLE
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.