Launch of Collider
来源:互联网 发布:最好的erp软件 编辑:程序博客网 时间:2024/05/21 03:54
Description
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, xi 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.
Input
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 x1, x2, ..., xn (0 ≤ xi ≤ 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.
Output
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.
Sample Input
4RLRL2 4 6 10
1
3LLR40 50 60
-1
Hint
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.
#include<map>#include<set>#include<cmath>#include<queue>#include<bitset>#include<math.h>#include<vector>#include<string>#include<stdio.h>#include<cstring>#include<iostream>#include<algorithm>using namespace std;struct point{int x;int aim;}a[200000+10];char des[200000+10];int main(){int n;int i;int min=0x3f3f3f3f;scanf("%d",&n);scanf("%s",&des);for(i=0;i<n;i++){if(des[i]=='L')a[i+1].aim=0;if(des[i]=='R')a[i+1].aim=1;}for(i=1;i<=n;i++){scanf("%d",&a[i].x);}for(i=1;i<n;i++){if(a[i].aim&&!a[i+1].aim){int s=(a[i+1].x-a[i].x)/2;if(s<min)min=s;}}if(min!=0x3f3f3f3f)printf("%d\n",min);elseprintf("-1\n");return 0;}
- Launch of Collider
- A. Launch of Collider
- Launch of Collider
- Launch of Collider
- Codeforces 699A Launch of Collider
- Codeforces-Round-#363-Launch of Collider
- Codeforces 699A Launch of Collider
- Codeforces-699A Launch of Collider
- CodeForces 699A Launch of Collider
- CodeForces 699A Launch of Collider
- CodeForces 699A Launch of Collider
- 【模拟】Codeforces 699A Launch of Collider
- codeforces 699 A. Launch of Collider
- codeforces 699A Launch of Collider
- Codeforces Round #363 (Div. 2)[A]Launch of Collider
- Codeforces #363 (Div.2) A. Launch of Collider【水题】
- Codeforces 699A. Launch of Collider (模拟)
- 【CodeForces】699A - Launch of Collider(思维)
- 多线程编程-- 线程安全的queue II
- git 将一个本地文件目录提交到远程仓库的步骤
- 有序集合求交集
- Give My Text Back_hihoCoder
- C++ Primer学习总结_2_类的初探
- Launch of Collider
- 风险投资中的天使轮 | A轮 | B轮 | Pro-IPO轮
- 自识别标记(self-identifying marker) -(1) 简介
- 字符串归一化
- 多线程控制文件输出
- 京东前端工程化和静态资源管理全面总结
- GCC编程四个过程:预处理-编译-汇编-链接
- Zhou_Zy's first blog.
- HDOJ 3583 LOOPS(期望DP)