A10536 | Launch of Collider
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. $n$ particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, $x_{i}$ is the coordinate of the $i$ -th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of $1$ meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of $1$ meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
输入格式
The first line contains the positive integer $n$ ( $1<=n<=200000$ ) — the number of particles.
The second line contains $n$ symbols "L" and "R". If the $i$ -th symbol equals "L", then the $i$ -th particle will move to the left, otherwise the $i$ -th symbol equals "R" and the $i$ -th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers $x_{1},x_{2},...,x_{n}$ ( $0<=x_{i}<=10^{9}$ ) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
The second line contains $n$ symbols "L" and "R". If the $i$ -th symbol equals "L", then the $i$ -th particle will move to the left, otherwise the $i$ -th symbol equals "R" and the $i$ -th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers $x_{1},x_{2},...,x_{n}$ ( $0<=x_{i}<=10^{9}$ ) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
输出格式
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Print the only integer -1, if the collision of particles doesn't happen.
输入输出样例
输入 #1
4 RLRL 2 4 6 10
输出 #1
1
输入 #2
3 LLR 40 50 60
输出 #2
-1
In the first sample case the first explosion will happen in $1$ microsecond because the particles number $1$ and $2$ will simultaneously be at the same point with the coordinate $3$ .
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted