#abc360d. D - Ghost Ants
D - Ghost Ants
Score : points
问题陈述
在数轴上有 只蚂蚁,编号为 到 。蚂蚁 从坐标 开始,面向正方向或负方向。最初,所有蚂蚁都在不同的坐标上。每只蚂蚁面向的方向由一个长度为 的二进制字符串 表示,如果 是 0
,则蚂蚁 面向负方向;如果 是 1
,则面向正方向。
设当前时间为 ,蚂蚁们以每单位时间 单位的速度沿着各自的方向移动,持续 单位时间,直到时间 。如果有多只蚂蚁到达同一坐标,它们会相互穿过,而不会改变方向或速度。在 单位时间后,所有蚂蚁停止。
找出在时间 之前,有多少对 满足 并且蚂蚁 和 相互穿过。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There are ants on a number line, labeled to . Ant starts at coordinate and faces either a positive or negative direction. Initially, all ants are at distinct coordinates. The direction each ant is facing is represented by a binary string of length , where ant is facing the negative direction if is 0
and the positive direction if is 1
.
Let the current time be , and the ants move in their respective directions at a speed of unit per unit time for units of time until time . If multiple ants reach the same coordinate, they pass through each other without changing direction or speed. After units of time, all ants stop.
Find the number of pairs such that and ants and pass each other from now before time .
Constraints
- is a string of length consisting of
0
and1
. - , , and are integers.
Input
The input is given from Standard Input in the following format:
...
Output
Print the answer.
Sample Input 1
6 3
101010
-5 -1 0 1 2 4
Sample Output 1
5
The following five pairs of ants pass each other:
- Ant and ant pass each other at time .
- Ant and ant pass each other at time .
- Ant and ant pass each other at time .
- Ant and ant pass each other at time .
- Ant and ant pass each other at time .
No other pairs of ants pass each other, so print .
Sample Input 2
13 656320850
0100110011101
-900549713 -713494784 -713078652 -687818593 -517374932 -498415009 -472742091 -390030458 -379340552 -237481538 -44636942 352721061 695864366
Sample Output 2
14