A. Launch of Collider Codeforces Round #363 (Div2)
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)的更多相关文章
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- 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 ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- 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 ...
随机推荐
- AJAX在Struts2中使用
前台页面: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...
- action 耦合方式
//ActionContext 方式 package com.hanqi.action; import java.util.Map; import com.opensymphony.xwork2.Ac ...
- GCD系列 之(二): 多核心的性能
全局队列的并发执行 for(id obj in array) [self doSomethingIntensiveWith:obj]; 假设,每个元素要做的事情-doSomethingIntensiv ...
- hibernate简单的增删改查
获取当前线程的session protected Session getSession() { return sessionFactory.getCurrentSession(); } 增加:save ...
- QTP脚本汇总比较有价值
1.Object Spy的Tips Hold the CTRL key to change the window focus or perform other mouse operations 2. ...
- Android WebView中显示一张或多张图片
最近需要在平板中显示多张图片,调查了下,决定用WebView(说实话,我还不清楚有没有其他android控件能够显示多张图片的.....), 主要是用HTML的img来显示多张图片. google百度 ...
- 云锁Linux服务器安全软件安装及防护webshell、CC、XSS跨站攻击设置
无论我们在使用电脑,还是使用VPS/服务器的时候,最为担心的就是服务器是否有安全问题,尤其是网站服务器再遭受攻击的时候如何得到防护.对于大 部分站长用户来说,我们可能只会使用基础的环境,如果真遇到问题 ...
- android --拍照,从相册获取图片,兼容高版本,兼容小米手机
前几天做项目中选择图片的过程中遇到高版本和小米手机出现无法选择和崩溃的问题,现在记录下来,后面出现同类问题,也好查找 1,定义常量: private static final int TAKE_PIC ...
- js-常用数组方法总结
[前面的话]说数组“万能”,可能夸张了一点,但是就个人观点,数组的运用是非常广泛的,这里的广泛当然也包含了在其他语言中的运用.举例说明,在javascript当中,由于字符串的不可变性,在进行字符串拼 ...
- Access denied for user 'root'@'localhost' (using password:YES) 解决方案[转]
关于昨天下午说的MySQL服务无法启动的问题,解决之后没有进入数据库,就直接关闭了电脑. 今早打开电脑,开始-运行 输入“mysql -uroot -pmyadmin”后出现以下错误: “Access ...