A. Launch of Collider

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples

Input

4 RLRL 2 4 6 10

Output

1

Input

3 LLR 40 50 60

Output

-1

Note

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.

___________________

题意:

第一行表示有n个粒子,第二行表示他们分别向R(ight)或L(eft)方向移动,第三个是他们从哪个点开始移动。问当第一个粒子相撞的时候时间是多少?

——————————————————————

这道题我蠢了,一开始写了个O(n^2)级别的代码,枚举了每两个数的各种可能取最小值。以为数据20W*20W是4e9左右,实际上是4e10……要是4e10根本不会去试O(n^2)了……当时大概知道O(n^2)应该过不了,但是想着A题应该不会用高级算法吧(我甚至想到了线段树之类的) , 然后想着优化一下或许能过。

附O(n^2)自带超级大常数代码(后来还试了几下是不是cin cout 效率低换了 scanf printf ):

这道题最蠢在英语上……后来去查了下题解,发现别人写的if ( a[j] == 'R' && a[j+1] == 'L' ) 这样的代码才意识到我遗漏了什么。

回去重新读题发现坐标是按升序排列,也就是说只要找相邻的RL区间最小就是答案。

被自己气哭了……

附AC代码:

#include<cstdio>
struct
{
char a ;
int b;
} x[200010]; int main()
{
int n ;
scanf("%d",&n);
getchar(); // 吞掉键盘缓冲区的换行符
//(这里曾以为CF是LINUX,所以用了两个getchar(),wrong了才改的)
for( int i = 0 ; i < n ; i++ )
scanf("%c",&x[i].a);
getchar();
int min = 1e9 + 1 ;
int flag = 1 ;
for( int i = 0 ; i < n ; i++)
scanf("%d",&x[i].b);
for( int j = 0 ; j < n ; j++)
if( x[j+1].a == 'L' && x[j].a == 'R' && x[j].b < x[j+1].b )
{
if ( x[j+1].b - x[j].b < min) min = x[j+1].b - x[j].b ;
flag = 0;
}
if( flag == 0 )cout << (min >> 1) << endl ;
else cout << "-1" << endl ;
return 0;
}

A. Launch of Collider Codeforces Round #363 (Div2)的更多相关文章

  1. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  2. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  3. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  4. Codeforces Round 363 Div. 1 (A,B,C,D,E,F)

    Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...

  5. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  6. Codeforces Round #363 (Div. 2)->A. Launch of Collider

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #363 Div.2[111110]

    好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...

  8. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  9. Codeforces Round #363 (Div. 2) A、B、C

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. centos7 搭建elk

    CentOS 7.x安装ELK(Elasticsearch+Logstash+Kibana)  云计算 Aug 162015 第一次听到ELK,是新浪的@ARGV 介绍内部使用ELK的情况和场景,当时 ...

  2. 清除HTML标记

    public static string DropHTML(string Htmlstring)        {            if (string.IsNullOrEmpty(Htmlst ...

  3. java中转换json方式(JSONArray,JSONObject),json解析

    package com.yunos.tv.video.resource.controller.web; import java.util.ArrayList; import java.util.Has ...

  4. mysql最大连接数问题

    进入mysql系统就, 查询最大连接数:show variables like 'max_connections'; 修改最大连接数:set global max_connections=1000;

  5. Hibernate HQL查询语句总结

    Hibernate HQL查询语句总结 1. 实体查询:有关实体查询技术,其实我们在先前已经有多次涉及,比如下面的例子:String hql="from User user ";L ...

  6. freemarker + spring mvc + spring + mybatis + mysql + maven项目搭建

    今天说说搭建项目,使用freemarker + spring mvc + spring + mybatis + mysql + maven搭建web项目. 先假设您已经配置好eclipse的maven ...

  7. docker安装升级linux内核(2.6.32->3.12.17)

    1.内核升级环境准备 #查看已经安装的和未安装的软件包组,来判断我们是否安装了相应的开发环境和开发库:yum grouplist#一般是安装这两个软件包组,这样做会确定你拥有编译时所需的一切工具yum ...

  8. PHP中 post 与get的区别 详细说明

    1.Get 方法通过 URL 请求来传递用户的数据,将表单内各字段名称与其内容,以成对的字符串连接,置于 action 属性所指程序的 url 后,如[url]http://www.jincaib.c ...

  9. jqgrid参数

    jqGrid参数 名称 类型 描述 默认值 可修改 url string 获取数据的地址 datatype string 从服务器端返回的数据类型,默认xml.可选类型:xml,local,json, ...

  10. Apache .htaccess语法之RewriteRule

    [说明]定义重写的规则[语法]RewriteRule Pattern rewritePattern [flags] # 开启 rewrite 功能 Options +FollowSymlinks Re ...