cf #363 a
2 seconds
256 megabytes
standard input
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.
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.
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.
4
RLRL
2 4 6 10
1
3
LLR
40 50 60
-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.
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxx = ;
struct Node{
int pos;
char dir;
}p[maxx];
bool cmp(Node a,Node b){
return a.pos<b.pos;
}
int main(){
int n;
scanf("%d",&n);
getchar();
for(int i=;i<n;i++){
scanf("%c",&p[i].dir);
}
for(int i=;i<n;i++){
scanf("%d",&p[i].pos);
} int ans=0x7fffffff;
for(int i=;i<n;i++){
if(p[i].dir!=p[i-].dir&&p[i].dir=='L'){
ans=min(ans,(p[i].pos-p[i-].pos)/);
}
}
if(ans<0x7fffffff){
printf("%d\n",ans);
}else{
printf("-1");
}
return ;
}
cf #363 a的更多相关文章
- cf #363 d
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output stan ...
- cf #363 c
C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- cf #363 b
B. One Bomb time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
随机推荐
- [POI2018]Plan metra
题目大意: 一棵$n(n\le5\times10^5)$个结点的树,每条边的边权均为正整数,告诉你$2\sim n-1$号结点到$1$号点和$n$号点的距离$d1[i]$和$d2[i]$.求是否存在这 ...
- 10.1(java学习笔记)JDBC基本操作(连接,执行SQL语句,获取结果集)
一.JDBC JDBC的全称是java database connection java数据库连接. 在java中需要对数据库进行一系列的操作,这时就需要使用JDBC. sun公司制定了关于数据库操作 ...
- 组合式MapReduce计算作业
1)迭代MapReduce计算任务,就是在一个循环内多次执行一个MapReduce. 2)顺序组合式MapReduce作业的执行 MapReduce1—>MapReduce2—>MapRe ...
- 更新升级10.11 cocoapods安装出问题最简单的解决方法
这是因为10.11把cocoapods直接干掉了 sudo gem install -n /usr/local/bin cocoapods 再加一句,完美解决 sudo xcode-select -- ...
- JQuery提示$(...).on is not a function解决方法
版本太低了,引入较高的版本,如jquery-1.8.3.min.js
- 【sql】sql优化
sql优化: 1.最左前缀原则 如果contact表上的tenement_id列创建了索引,那么查询的时候将索引列放在最左边,查询的速度会快很多,因为扫描的范围是索引范围而不是整张表范围!! SELE ...
- Intellij IDEA System.out.println输出中文乱码问题
进行下列设置即可:
- cs-HtmlHelpers
ylbtech-Unitity: cs-HtmlHelpers PagingHelpers.cs SelectInputHelpers.cs TreeHelpers.cs 1.A,效果图返回顶部 ...
- Vue组件开发实例(详细注释)
Vue组件开发实例: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> &l ...
- java源码阅读LinkedList
1类签名与注释 public class LinkedList<E> extends AbstractSequentialList<E> implements List< ...