CF699A.Launch of Collider
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
一个全新、强大且独特的对撞机即将启动,其结构为一条直线。对撞机内部将发射 n 个粒子。所有粒子均位于同一条直线上,且任意两个或更多粒子不可能处于同一位置。粒子的坐标即为其距离对撞机中心的米数;xi 表示第 i 个粒子的坐标,同时也是其在对撞机中的初始位置。所有粒子坐标的值均为偶数。
已知每个粒子的运动方向——对撞机启动后,它将向右或向左运动。所有粒子均在对撞机启动时刻同时开始运动,且均以恒定速度 1 米/微秒沿直线向左或向右运动。对撞机尺寸足够大,因此在可预见的时间内粒子不会离开对撞机。
请编写一个程序,找出对撞机中任意两个粒子发生首次碰撞的时刻(即:求出首次出现任意两个粒子处于同一位置时,距离对撞机启动时刻的微秒数)。
输入格式
The first line contains the positive integer n (1 ≤ n ≤ 200 000) — 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 ≤ 109) — 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.
第一行包含一个正整数 n(1≤n≤200000)—— 粒子的数量。
第二行包含 n 个字符,每个字符为 "L" 或 "R"。若第 i 个字符为 "L",则第 i 个粒子向左移动;否则该字符为 "R",第 i 个粒子向右移动。
第三行包含一个由两两互异的偶整数组成的序列 x1,x2,…,xn(0≤xi≤109)—— 粒子的坐标,按从左到右的顺序给出。保证粒子坐标的输入是严格递增的。
输出格式
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.
在第一行输出唯一的一个整数——两个粒子首次处于同一点并发生爆炸的时刻(单位:微秒)。
若粒子不会发生碰撞,则输出唯一的一个整数 -1。
输入输出样例
输入#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.
在第一个样例中,第一次爆炸将在 1 微秒时发生,因为编号为 1 和 2 的粒子将同时到达坐标为 3 的同一点。
在第二个样例中,不会发生爆炸,因为不存在会同时到达同一点的粒子。
输入解题思路,AI测评打分。不知道怎么写?