Codeforces Round #363 (Div. 2) A 水

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

Input

4RLRL2 4 6 10

Output

1

Input

3LLR40 50 60

Output

-1

题意: n个碰撞机  给你每个初始的运动方向 (只有‘L’‘R’) 给你初始的位置 (位置不同且都为偶数)  每个碰撞机器每秒运动一米  问你第一次发生碰撞的时刻是什么时候。

题解:最快发生碰撞肯定是相邻的一组‘L’‘R’     所以遍历一遍 找最小值  若不存在则输出‘-1’;
 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<queue>
 5 #include<stack>
 6 #include<vector>
 7 #include<map>
 8 #include<algorithm>
 9 #define ll __int64
10 #define mod 1e9+7
11 #define PI acos(-1.0)
12 using namespace std;
13 int n;
14 struct node
15 {
16     int pos;
17     char  dir;
18 }N[200005];
19 int main()
20 {
21     scanf("%d",&n);
22     getchar();
23     int  minx=1e9+7;
24     for(int i=1;i<=n;i++)
25         scanf("%c",&N[i].dir);
26     for(int i=1;i<=n;i++)
27         scanf("%d",&N[i].pos);
28     int flag=0;
29     for(int i=2;i<=n;i++)
30     {
31         if(N[i].dir==‘L‘&&N[i-1].dir==‘R‘)
32         {
33             flag=1;
34             minx=min(minx,(N[i].pos-N[i-1].pos)/2);
35         }
36     }
37     if(flag==0)
38         cout<<"-1"<<endl;
39     else
40         cout<<minx<<endl;
41     return 0;
42 }
				
时间: 2024-11-05 21:52:29

Codeforces Round #363 (Div. 2) A 水的相关文章

Codeforces Round #363 (Div. 2)

A. Launch of Collider 根据字符左移或右移,输出第一次碰撞的位置,不然输出-1 1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 #define LL long long 7 char ch[200005]; 8 LL a[200005],ans; 9 int n; 1

CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))

要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情况)) : dp(第i天呆在家里) = min(dp(第i-1天的三种情况))+1: 1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 #define inf 0x3f3f3f3f 5 int a[10

Codeforces Round #363 Div.2[11110]

好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位长度.输入给出每个点的坐标及其移动的方向,求发生第一次碰撞的时间,若不会碰撞,则输出-1 最先发生碰撞的是一定是初始时相邻的两个点,因此只需对每个点循环一边,判断其是否会与下一个点碰撞,并求出其时间即可. #include<stdio.h> #include<stdlib.h> int

Codeforces Round #310 (Div. 1)——A水——Case of Matryoshkas

Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka dolls

Codeforces Round #363 (Div. 1) C. LRU

题意: n个数,长度为k的缓存,每次询问,每个数以pi的概率被选,如果不在缓存区则加入,如果缓存区满了,则第一个进缓存的出来,问10^100次询问以后每个数在缓存的概率 思路: 状压DP,看了hzwer的代码 f[x]表示当前状态为x的概率 枚举不在缓存区的数:f[t]+=f[x]*(p[i]/tot);  t=x|(1<<(i-1)); tot是当前状态情况下,不在缓存区的所有概率 如果缓存区数大于k,则当前状态概率为0 1 // #pragma comment(linker, "

Codeforces Round #363 (Div. 2)A-D

699A 题意:在一根数轴上有n个东西以相同的速率1m/s在运动,给出他们的坐标以及运动方向,问最快发生的碰撞在什么时候 思路:遍历一遍坐标,看那两个相邻的可能相撞,更新ans #include<cstdio> int n,num[200100]; char s[200100]; int main() { scanf("%d",&n); scanf("%s",s+1); for(int i=1;i<=n;i++) scanf("%

Codeforces Round #363 (Div. 2) C

Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this ndays: whether that gym opened and whether a contest was carried out in the Internet on that day.

Codeforces Round #363 (Div. 2) B 暴力

Description You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x

Codeforces Round #363 (Div. 2) A-C

A. Launch of Collider 找最近的R和L之间的距离 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <iomanip> #include <math.h> #include <map> u