Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
699_A. Launch of Collider
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.
2
7
n=input() directions = str(input().strip()) items = list(map(int,input().strip().split())) l_bound = directions.find("R") if l_bound!=-1: min =None i=l_bound+1 #for i in range(l_bound+1,len(directions)): while i<len(directions): #print(i) if directions[i]=="L": if min==None or min>(items[i]-items[l_bound]): #print("L") min=(items[i]-items[l_bound]) #print(min) l_bound = directions.find("R",i) if l_bound==-1: break #print(l_bound) i=l_bound continue else: l_bound=i i+=1 if min!=None: print(int(min/2)) else: print("-1") else: print("-1")
PYTHON3
699_A. Launch of Collider
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.
2
7
n = int(raw_input()) str = raw_input() dis = map(int, raw_input().split(" ")) max = 100000000000000 dist = max for i in range(n-1): if str[i] == 'R' and str[i+1] == 'L' and dis[i+1]-dis[i]<dist: dist = dis[i+1]-dis[i] if dist == max: dist = -1 else: dist /= 2 print dist
PYTHON
699_A. Launch of Collider
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.
2
7
n = input() p = list(raw_input()) posi = map(int,raw_input().split()) mini = 987654321 curpo = -1 for i in range(len(p)) : if p[i] == 'R' : curpo = posi[i] elif p[i] == 'L' : if curpo != -1 : t = (posi[i] - curpo)/2 mini = min(mini,t) if mini != 987654321 : print mini else : print -1
PYTHON
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; char direction[N]; int position[N]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> direction[i]; for (int i = 0; i < n; ++i) cin >> position[i]; int answer = 0x3f3f3f3f; for (int rPtr = 0, lPtr = 0; rPtr < n; rPtr++) { if (direction[rPtr] == 'L') continue; for (; lPtr < n; ++lPtr) { if (lPtr <= rPtr) continue; if (direction[lPtr] == 'R') continue; answer = min(answer, (position[lPtr] - position[rPtr]) / 2); break; } } if (answer == 0x3f3f3f3f) answer = -1; cout << answer << endl; }
CPP
699_A. Launch of Collider
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.
2
7
n=int(input()) s=input() x = list(map(int, input().split(" "))) Min=10000000000000 for i in range(0,n-1): if s[i]=='R'and s[i+1]=='L': Min=min(Min,(x[i+1]-x[i])//2) print(Min if Min!=10000000000000 else -1)
PYTHON3
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int a[maxn]; char s[maxn]; int main() { int n; scanf("%d", &n); scanf("%s", s); for (int i = 0; i < n; ++i) { scanf("%d", a + i); } int ans = 2e9; for (int i = 1; i < n; ++i) { if (s[i - 1] == 'R' && s[i] == 'L') { ans = min(ans, a[i] - a[i - 1] >> 1); } } if (ans == 2e9) { ans = -1; } printf("%d\n", ans); }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 1000; const int inf = 0x7fffffff; char ch[N]; int s[N]; int main() { int n; scanf("%d", &n); scanf("%s", ch); for (int i = 0; i < n; i++) scanf("%d", &s[i]); int len = strlen(ch); bool judge = true; int ans = inf; for (int i = 0; i < len - 1; i++) { if (ch[i] == 'R' && ch[i + 1] == 'L') { judge = false; ans = min(ans, (s[i + 1] - s[i]) / 2); } } if (judge) { printf("-1\n"); return 0; } printf("%d\n", ans); return 0; }
CPP
699_A. Launch of Collider
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.
2
7
import sys n = int(raw_input()) s = raw_input() a = map(int,raw_input().split()) d = sys.maxint for i in xrange(n-1) : if s[i] =='R' and s[i+1] == 'L' : d = min(d,a[i+1]-a[i]) if d == sys.maxint : print '-1' else : print d/2
PYTHON
699_A. Launch of Collider
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.
2
7
n = int(raw_input()) s = raw_input() ans = 1e19 g =[] b = raw_input().split() for i in range(len(b)): g.append(int(b[i])) for i in range(1, n): if s[i - 1] == 'R' and s[i] == 'L': ans = min(ans, g[i] - g[i - 1]) if ans == 1e19: print(-1) else : print(ans // 2)
PYTHON
699_A. Launch of Collider
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.
2
7
import java.util.*; public class p106 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int n = in.nextInt(); String str = in.next(); int ans= Integer.MAX_VALUE; int a[] = new int [n]; for (int i = 0; i < a.length; i++) { a[i]=in.nextInt(); }if (!str.contains("RL")) { ans=-1; }else { for (int i = 0; i < a.length-1; i++) { if (str.charAt(i)=='R'&&str.charAt(i+1)=='L') { ans=Math.min(ans, (a[i+1]-a[i])/2); } } } System.out.println(ans); } }
JAVA
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { long int n, mx = 1000000000; string dir; cin >> n; cin >> dir; int arr[n]; cin >> arr[0]; for (int i = 1; i < n; i++) { cin >> arr[i]; if (dir[i - 1] == 'R' && dir[i] == 'L' && ((arr[i] - arr[i - 1]) / 2) < mx) mx = (arr[i] - arr[i - 1]) / 2; } if (mx == 1000000000) mx = -1; cout << mx; cout << endl; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; int n; cin >> n; vector<int> arr(n); string str; cin >> str; for (auto i = 0; i < (n); ++i) { cin >> arr[i]; } int MIN = INT_MAX; bool flag = false; for (auto i = 0; i < (n - 1); ++i) { if (str[i] == 'R' && str[i + 1] == 'L') { flag = true; MIN = min(MIN, (arr[i + 1] - arr[i]) / 2); } } if (!flag) cout << -1; else cout << MIN; }
CPP
699_A. Launch of Collider
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.
2
7
n = int(input()) m = input() p = list(map(int,input().split())) x = [] if (m.find('RL') == -1): print(-1) else: for i in range(n): if (i != n-1): if ((m[i] == 'R') & (m[i+1] == 'L')): x.append((p[i+1]-p[i])//2) else: exit print(min(x))
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.util.StringTokenizer; import java.util.TreeSet; public class cfvc15 { static BufferedReader reader; static StringTokenizer tokenizer; static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { tokenizer = new StringTokenizer(reader.readLine() ); } return tokenizer.nextToken(); } static long nextInt() throws IOException { return Long.parseLong( next() ); } static PrintWriter writer; static void outit(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } static void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } static void println(Object...objects) { print(objects); writer.println(); } static void close() { writer.close(); } static void flush() { writer.flush(); } public static void print_a(long [] a) { for(long i : a) { print(i+" ") ; } println() ; } public static void main(String [] args) throws IOException { init(System.in) ; outit(System.out) ; // int t = (int) nextInt() ; // for(int i =0 ; i<t ; i++) output() ; flush(); close(); } public static void output() throws IOException { int n = (int) nextInt() ; String s = next() ; long [] a = new long [n] ; for(int i = 0 ; i<n ; i++) { a[i] = nextInt() ; } long t = -1 ; for(int i = 0 ; i<(n-1) ; i++) { if(s.charAt(i)=='R'&&s.charAt(i+1)=='L') { if(t!=-1) { t = Math.min(t, (a[i+1]-a[i])/2) ; } else { t = (a[i+1]-a[i])/2 ; } } } println(t) ; } }
JAVA
699_A. Launch of Collider
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.
2
7
#!/usr/bin/python import sys def main(): number_of_steps = raw_input() directions = raw_input() x_coords_str = raw_input() if not is_exist_collision(directions): print -1 exit(0) x_coords = x_coords_str.split() x_coord_index = find_nearest(x_coords, directions) print((int(x_coords[x_coord_index + 1]) - int(x_coords[x_coord_index])) / 2) def find_nearest(coords, directions): result_index = -1 min_distance = sys.maxint for i in range(0, len(coords) - 1): distance = int(coords[i + 1]) - int(coords[i]) if distance < min_distance and directions[i + 1] == 'L' and directions[i] == 'R': result_index = i min_distance = distance return result_index def is_collision(x1, x2, time): return x1 + time == x2 + time def is_exist_collision(directions): exist_right_particle = False for direction in directions: exist_right_particle |= direction == 'R' if direction == 'L' and exist_right_particle: return True return False if __name__ == '__main__': main()
PYTHON
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; int m = 1e9; for (int i = 0; i < n; i++) if (s[i] == 'R' && s[i + 1] == 'L') m = min(m, (a[i + 1] - a[i]) / 2); if (m == 1e9) cout << -1 << endl; else cout << m << endl; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; const int mx = 200000; const int inf = 0x3f3f3f3f; int a[mx], z[mx], y[mx]; char s[mx]; int main() { int n, m; while (cin >> n) { scanf("%s", s); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int maxx = inf; for (int i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { int xx = (a[i + 1] - a[i]) / 2; if (xx < maxx) { maxx = xx; } } } if (maxx != inf) { printf("%d\n", maxx); } else { printf("-1\n"); } } return 0; }
CPP
699_A. Launch of Collider
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.
2
7
input() s = input() x = [int(i) for i in input().split()] res = -1 for i in range(len(x) - 1): if s[i] == "R" and s[i+1] == "L": if res == -1 or res > (x[i+1] - x[i]) // 2: res = (x[i+1] - x[i]) // 2 print(res)
PYTHON3
699_A. Launch of Collider
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.
2
7
import sys import math import itertools import collections def getdict(n): d = {} if type(n) is list or type(n) is str: for i in n: if i in d: d[i] += 1 else: d[i] = 1 else: for i in range(n): t = ii() if t in d: d[t] += 1 else: d[t] = 1 return d def divs(n, start=1): r = [] for i in range(start, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): r.append(i) else: r.extend([i, n // i]) return r def cdiv(n, k): return n // k + (n % k != 0) def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a*b) // math.gcd(a, b) def wr(arr): return ' '.join(map(str, arr)) def revn(n): return int(str(n)[::-1]) def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True def convn(number, base=3): newnumber = '' while number > 0: newnumber = str(number % base) + newnumber number //= base return newnumber n = ii() s = input() a = li() ans = 10 ** 9 for i in range(n - 1): if s[i: i + 2] == 'RL': ans = min(ans, (a[i + 1] - a[i]) // 2) print(-1) if ans == 10 ** 9 else print(ans)
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.io.*; import java.util.*; public class Main { public void solve(){ int N = nextInt(); int[] X = new int[N]; TreeSet<Integer> left = new TreeSet<>(); String str = next(); for(int i = 0; i < N; i++){ X[i] = nextInt(); if(str.charAt(i) == 'L'){ left.add(X[i]); } } int ans = Integer.MAX_VALUE; for(int i = 0; i < N; i++){ if(str.charAt(i) == 'R'){ Integer v = left.ceiling(X[i]); if(v != null){ ans = Math.min(ans, (v - X[i]) / 2); } } } if(ans == Integer.MAX_VALUE){ out.println("-1"); }else{ out.println(ans); } } private static PrintWriter out; public static void main(String[] args) { out = new PrintWriter(System.out); new Main().solve(); out.flush(); } public static int nextInt() { int num = 0; String str = next(); boolean minus = false; int i = 0; if (str.charAt(0) == '-') { minus = true; i++; } int len = str.length(); for (; i < len; i++) { char c = str.charAt(i); if (!('0' <= c && c <= '9')) throw new RuntimeException(); num = num * 10 + (c - '0'); } return minus ? -num : num; } public static long nextLong() { long num = 0; String str = next(); boolean minus = false; int i = 0; if (str.charAt(0) == '-') { minus = true; i++; } int len = str.length(); for (; i < len; i++) { char c = str.charAt(i); if (!('0' <= c && c <= '9')) throw new RuntimeException(); num = num * 10l + (c - '0'); } return minus ? -num : num; } public static String next() { int c; while (!isAlNum(c = read())) { } StringBuilder build = new StringBuilder(); build.append((char) c); while (isAlNum(c = read())) { build.append((char) c); } return build.toString(); } private static byte[] inputBuffer = new byte[1024]; private static int bufferLength = 0; private static int bufferIndex = 0; private static int read() { if (bufferLength < 0) throw new RuntimeException(); if (bufferIndex >= bufferLength) { try { bufferLength = System.in.read(inputBuffer); bufferIndex = 0; } catch (IOException e) { throw new RuntimeException(e); } if (bufferLength <= 0) return (bufferLength = -1); } return inputBuffer[bufferIndex++]; } private static boolean isAlNum(int c) { return '!' <= c && c <= '~'; } }
JAVA
699_A. Launch of Collider
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.
2
7
import re n = input() s = raw_input() x = map(int, raw_input().split()) y=[m.start() for m in re.finditer('RL', s)] if not y: print -1 else: minimaldistance = 10**9; for i in y: minimaldistance = min(minimaldistance,(x[i+1]-x[i])>>1) print minimaldistance
PYTHON
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j; cin >> n; string s; cin >> s; int a[n]; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } int flag = 0, mn = 1000000000, mid, x, y, d; for (i = 0; i < n; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { flag = 1; x = a[i]; y = a[i + 1]; mid = (x + y) / 2; d = mid - x; if (d < mn) mn = d; } } if (flag) { cout << mn; } else cout << "-1"; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; struct node { int rec; int dis; int left; int right; } ant[200005]; char st[200005]; bool cmp(node a, node b) { return (a.dis < b.dis); } int main() { int n; int a; scanf("%d", &n); scanf("%s", st); int len = strlen(st); for (int i = 0; i < len; ++i) { if (st[i] == 'L') ant[i].rec = 1; else ant[i].rec = 2; scanf("%d", &a); ant[i].dis = a; } sort(ant, ant + n, cmp); int right = -1; for (int i = 0; i < n; ++i) { if (ant[i].rec == 2) right = ant[i].dis; ant[i].right = right; } int left = -1; for (int i = n - 1; i >= 0; --i) { if (ant[i].rec == 1) left = ant[i].dis; ant[i].left = left; } int Min = 0x3f3f3f3f; for (int i = 0; i < n; ++i) { if (ant[i].left != -1 && ant[i].right != -1) { if ((ant[i].left - ant[i].right) / 2 < Min) Min = (ant[i].left - ant[i].right) / 2; } } if (Min == 0x3f3f3f3f) printf("-1\n"); else printf("%d\n", Min); return 0; }
CPP
699_A. Launch of Collider
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.
2
7
n, s, a = int(input()) - 1, input(), list(map(int, input().split())) b = [] for i in range(n): if s[i] == 'R' and s[i + 1] == 'L': b.append((a[i + 1] - a[i]) // 2) print(-1 if len(b) == 0 else min(b))
PYTHON3
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; vector<int> num(n); for (auto &x : num) cin >> x; int flag = 0; int t, res, min = 1e9; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { flag = 1; t = (num[i + 1] - num[i]) / 2; res = ceil(t); if (res < min) min = res; } } if (flag == 0) cout << -1 << endl; else cout << min << endl; cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " sec" << endl; ; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
T = input() cmds = raw_input().strip() nums = map(int, raw_input().strip().split()) pot = [] for i in xrange(len(cmds) - 1): if cmds[i:i+2] == "RL": pot.append(nums[i+1] - nums[i]) print min(pot)/2 if len(pot) != 0 else -1
PYTHON
699_A. Launch of Collider
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.
2
7
n = int(input()) s = input() x = list(map(int, input().split())) minimum = 10000000000 if s.count('RL') == 0: print(-1) else: for i in range(n - 1): if s[i] == 'R' and s[i + 1] == 'L' and x[i + 1] - x[i] < minimum: minimum = x[i + 1] - x[i] print(minimum // 2)
PYTHON3
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long n; cin >> n; string s; cin >> s; vector<long long> pos(n); for (long long i = 0; i < n; i++) cin >> pos[i]; long long ans = 1e12; bool found = 0; for (long long i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { ans = min(pos[i + 1] - pos[i], ans); found = 1; } } cout << (found ? ans / 2 : -1) << "\n"; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int count = scanner.nextInt(); char[] dir = scanner.next().toCharArray(); int[] pos = new int[count]; for (int i = 0 ; i < count ; i++){ pos[i] = scanner.nextInt(); } int min = Integer.MAX_VALUE; for (int i = 0 ; i < count - 1 ; i++){ int next = i + 1; if ( dir[i] == 'R' && dir[next] == 'L'){ int temp = ((pos[i] + pos[next]) / 2) - pos[i]; if (temp < min) min = temp; } } if (min != Integer.MAX_VALUE) System.out.println(min); else System.out.println(-1); scanner.close(); } }
JAVA
699_A. Launch of Collider
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.
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashSet; import java.util.StringTokenizer; import javax.swing.plaf.synth.SynthSplitPaneUI; public class ProblemA { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt() , ans = 1000000000 , prevpos , currpos; String s = sc.next() ; char prev = s.charAt(0) , curr ; prevpos = sc.nextInt() ; for(int i = 1 ; i < n ; i ++) { curr = s.charAt(i) ; currpos = sc.nextInt() ; if(prev == 'R' && curr =='L')ans= Math.min(ans,Math.abs( prevpos - currpos) / 2 ) ; prevpos = currpos ; prev = curr ; } pw.println(ans==1000000000? -1 :ans); pw.flush(); pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } }
JAVA
699_A. Launch of Collider
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.
2
7
n = int(input()) s = input() l = list(map(int,input().split())) d = [] for i in range(n-1): if s[i] == 'R' and s[i+1] == 'L': t =l[i+1] - l[i] t =t // 2 d.append(t) if d == []: print(-1) else: print(min(d))
PYTHON3
699_A. Launch of Collider
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.
2
7
#!/usr/bin/python import sys def main(): number_of_steps = raw_input() directions = raw_input() x_coords_str = raw_input() x_coords = x_coords_str.split() x_coord_index = find_nearest(x_coords, directions) distance = (int(x_coords[x_coord_index + 1]) - int(x_coords[x_coord_index])) print -1 if distance <= 0 else distance / 2 def find_nearest(coords, directions): result_index = -1 min_distance = sys.maxint for i in range(0, len(coords) - 1): distance = int(coords[i + 1]) - int(coords[i]) if distance < min_distance and directions[i + 1] == 'L' and directions[i] == 'R': result_index = i min_distance = distance return result_index def is_collision(x1, x2, time): return x1 + time == x2 + time def is_exist_collision(directions): exist_right_particle = False for direction in directions: exist_right_particle |= direction == 'R' if direction == 'L' and exist_right_particle: return True return False if __name__ == '__main__': main()
PYTHON
699_A. Launch of Collider
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.
2
7
n = int(input()) s = input() a = list(map(int, input().split())) maxl = -1 mini = 100000000000000000000000 for i in range(n): if s[i] == 'R': maxl = a[i] if s[i] == 'L' and maxl != -1: mini = min(mini, a[i] - maxl) if mini == 100000000000000000000000: print(-1) else: print(mini // 2)
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; /** * Created by pantism on 03/02/2016. */ public class _363_A{ public static int n,a[] = new int[200001]; static String x; public static void readData() { Scanner sc = new Scanner(System.in); n=sc.nextInt(); x = sc.nextLine(); x = sc.nextLine(); x=x.trim(); for(int i=0;i<n;i++) a[i]=sc.nextInt(); } public static void main(String args[]) { int i; readData(); int min=1012345678; int dev=min; for(i=1;i<n;i++) { if(x.charAt(i)=='L'&&x.charAt(i-1)=='R') { if(a[i]-a[i-1]<dev) dev=a[i]-a[i-1]; } } if(dev==min) dev=-2; System.out.println(dev/2); } }
JAVA
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[200000]; for (int i = 0; i < n; i++) cin >> a[i]; int ans = 1e9; for (int i = 0; i < n - 1; i++) if (s[i] == 'R' && s[i + 1] == 'L') ans = min(ans, (a[i + 1] - a[i]) / 2); if (ans == 1e9) cout << -1 << endl; else cout << ans << endl; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string s; cin >> s; vector<int> v; for (auto i = (0); i < (n); i++) { int x; cin >> x; v.push_back(x); } int ans = 2000000000; int i = 0; while (i < n) { if ((i < n - 1) and (s[i] == 'R') and (s[i + 1] == 'L')) { ans = min(ans, (v[i + 1] - v[i]) / 2); i += 2; continue; } if ((i > 0) and (s[i - 1] == 'R') and (s[i] == 'L')) { ans = min(ans, (v[i] - v[i - 1]) / 2); i += 2; continue; } i++; } cout << (ans == 2000000000 ? -1 : ans) << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) solve(); return 0; }
CPP
699_A. Launch of Collider
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.
2
7
import math n = int(input()) s = input() x = list(map(int,input().split())) i = 1 v = 10000000009 while(i<len(s)): if (s[i-1]=="R" and s[i]=="L" and math.ceil(( x[i]-x[i-1] ) / 2) < v ): v = math.ceil(( x[i]-x[i-1] ) / 2) i=i+1 if v!=10000000009: print(v) else: print(-1)
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; public class Launch_of_Collider { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; sc.nextLine(); // buffer String d = sc.nextLine(); for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } // WE KNOW THAT ONLY SEQUENCE 'RL' CAN MAKE COLLISIONS int res = arr[n-1] - arr[0]; boolean collision = false; for (int i = 0; i < n - 1; i++) { if (d.charAt(i) == 'R' && d.charAt(i + 1) == 'L') { collision = true; int tmp = (arr[i + 1] - arr[i]) / 2; res = tmp < res ? tmp : res; } } if (!collision) System.out.println(-1); else System.out.println(res); } }
JAVA
699_A. Launch of Collider
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.
2
7
n = int(raw_input()) d = raw_input() x = map(int,raw_input().split()) ret = 1100000000 for i in range(1, n): if d[i-1] == 'R' and d[i] == 'L': ret = min(ret, (x[i] - x[i-1])//2) print ret if ret != 1100000000 else -1
PYTHON
699_A. Launch of Collider
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.
2
7
import java.util.*; import java.lang.*; import java.io.*; public class R363A { public static void main (String[] args) throws java.lang.Exception { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); TreeSet<Integer> tsr = new TreeSet<>(); TreeSet<Integer> tsl = new TreeSet<>(); int n = in.nextInt(); char[] ca = in.next().toCharArray(); for (int i = 0; i < n; i++) { if (ca[i] == 'R') tsr.add(in.nextInt()); else tsl.add(in.nextInt()); } int ans = -1; for (int x : tsl) { Integer found = tsr.lower(x); if (found != null && (ans == -1 || Math.abs(x - found) < ans)) ans = Math.abs(x - found); } if (ans > 0) w.println(ans / 2); else w.println(ans); w.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new UnknownError(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new UnknownError(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int peek() { if (numChars == -1) return -1; if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) return -1; } return buf[curChar]; } public void skip(int x) { while (x-- > 0) read(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public String nextString() { return next(); } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { StringBuffer buf = new StringBuffer(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public boolean hasNext() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value != -1; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }
JAVA
699_A. Launch of Collider
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.
2
7
def row(fn): return map(fn, raw_input().strip().split()) N = input() dir = list(raw_input()) pos = row(int) mi = float('+inf') for i in xrange(len(pos)): if i > 0 and dir[i] == 'L' and dir[i-1] == 'R': mi = min(mi, (pos[i] - pos[i-1]) / 2) print mi if mi < float('+inf') else -1
PYTHON
699_A. Launch of Collider
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.
2
7
import java.util.*; public class Dcoder { public static void main(String args[]) { Scanner input=new Scanner(System.in); int n = input.nextInt(); String s =input.next(); long [] a = new long[n]; for(int i=0;i<n;i++){ a[i]=input.nextInt(); } long min=1000000009; for(int i =0;i<n-1;i++){ if(s.charAt(i)=='R' && s.charAt(i+1)=='L'){ if( min>a[i+1]-a[i]){ min=a[i+1]-a[i]; } } } if(min==1000000009){ System.out.print("-1"); }else{ System.out.print(min/2); } } }
JAVA
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; public class Solution { private static final String RL = "RL"; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); String directions = scanner.next(); int[] positions = new int[n]; for (int i = 0; i < n; i++) { positions[i] = scanner.nextInt(); } int index = directions.indexOf(RL); if (index == -1) { System.out.println(-1); return; } int minDistance = Integer.MAX_VALUE; while (index >= 0) { minDistance = Math.min(minDistance, positions[index + 1] - positions[index]); index = directions.indexOf(RL, index + 1); } System.out.println(minDistance / 2); } }
JAVA
699_A. Launch of Collider
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.
2
7
n = int(raw_input()) d = raw_input() x = map(int, raw_input().split()) y = [x[i] - x[i-1] for i in xrange(1, n) if d[i-1] == 'R' and d[i] == 'L'] print min(y)/2 if len(y) > 0 else -1
PYTHON
699_A. Launch of Collider
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.
2
7
import java.util.*; import java.io.*; import java.math.BigDecimal; public class TestClass{ static PrintWriter out = new PrintWriter(System.out); static HashMap v; static HashMap d; public static void main(String args[]) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); String s = in.readLine(); String s1[] = in.readLine().split(" "); Node node[] = new Node[n]; for(int i=0;i<n;i++) { node[i] = new Node(Character.toString(s.charAt(i)),Integer.parseInt(s1[i])); } Arrays.sort(node); int min=Integer.MAX_VALUE; int f=0; /*for(int i=0;i<n;i++) { out.println(node[i].p+" "+node[i].x); }*/ for(int i=0;i<n-1;i++) { //System.out.println(node[i].p+" "+node[i+1].p); if(node[i].p.equals("R") && node[i+1].p.equals("L")) { //System.out.println(node[i].x+" "+node[i+1].x); int m = (node[i+1].x - node[i].x)/2; f=1; min = Math.min(m, min); } } if(f==1) { out.println(min); } else { out.println(-1); } out.close(); } } class Node implements Comparable<Node>{ String p; int x; Node(String p,int x) { this.p=p; this.x=x; } public int compareTo(Node o) { return Integer.compare(this.x,o.x); } }
JAVA
699_A. Launch of Collider
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.
2
7
n = int(input()) movement = list(input()) coord = list(map(int, input().split())) first_collision = float('inf') flag=False for i in range(len(coord) - 1): if movement[i] == 'R' and movement[i+1] == 'L': flag = True first_collision = min(first_collision, (coord[i+1] - coord[i]) // 2) if flag: print(first_collision) else: print(-1)
PYTHON3
699_A. Launch of Collider
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.
2
7
import sys input = sys.stdin.readline print = sys.stdout.write def main(): n = int(input()) st = input().rstrip() arr = list(map(int, input().split())) answer = 10**18 for i in range(len(arr) - 1): if st[i] == "R" and st[i + 1] == "L": answer = min(answer, (arr[i + 1] - arr[i] + 1) // 2) if answer == 10**18: answer = -1 print(str(answer)) main()
PYTHON3
699_A. Launch of Collider
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.
2
7
n = int(input()) direction = str(input()) coord = list(map(int, input().split())) res = 10**9 + 1 for x in range(len(direction) - 1): if (direction[x] == 'R') and (direction[x+1] == 'L'): if (coord[x+1] - coord[x]) < res: res = coord[x+1] - coord[x] if res == 10**9 + 1: print('-1') else: print(res//2)
PYTHON3
699_A. Launch of Collider
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.
2
7
particles = int(input()) arrayOfMovement = list(str(input())) arrayOfCoordinates = list(map(int, input().split())) min = 10000000000 flag= 0 for i in range(0,len(arrayOfMovement)): if i != len(arrayOfMovement)-1 and arrayOfMovement[i] == 'R' and arrayOfMovement[i+1] == 'L': x = arrayOfCoordinates[i+1] - arrayOfCoordinates[i] x /= 2 if x < min: flag = 1 min = x if flag==1: print(int(min)) else: print("-1")
PYTHON3
699_A. Launch of Collider
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.
2
7
n=int(input()) s=input() a=[int(x) for x in input().split()] if 'RL' not in s: print(-1) exit(0) ans=1000000001 for i in range(0,n-1): if s[i]=='R' and s[i+1]=='L': if (a[i+1]-a[i])//2<ans: ans=(a[i+1]-a[i])//2 print(ans)
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.io.*; import java.util.*; import java.lang.*; public class CfCOntest { static long mod = 1000000007; public static long power(long n,long k) { if(k==1) { return n; } if(k==0) { return 1; } long p = power(n, k/2); long d = (p%mod *p%mod)%mod; if(k%2==0) { return d; } else { return (d * n)%mod; } } // //public static void takeinput(int arr[],int n,Scanner s) // { // for(int i = 0;i<n;i++) // { // arr[i] = s.nextInt(); // } // } public static void main(String[] args) { // TODO Auto-generated method stub Scanner s = new Scanner(System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); HashMap<Integer, Integer>map = new HashMap<>(); long n = s.nextLong(); String str = s.next(); long arr[] = new long[(int)n]; for(int i=0;i<n;i++) { arr[i] = s.nextLong(); } long min = Integer.MAX_VALUE; for(int i=0;i<str.length()-1;i++) { if(str.charAt(i)=='R' && str.charAt(i+1)=='L') { long temp = arr[i+1]-arr[i]; temp = temp/2; if(temp<min) { min = temp; } } } if(min == Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(min); } } }
JAVA
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { char str[200005]; scanf("%s", str); int pos = 0; int r = -1; bool rf = false; bool lf = false; int ans = (1 << 30); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); x = x >> 1; if (str[i] == 'R') { rf = true; r = x; } else { if (!rf) continue; else { lf = true; ans = min(ans, x - r); } } } if (!lf) ans = -1; cout << ans << endl; } return 0; }
CPP
699_A. Launch of Collider
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.
2
7
n = int(input()) d = input() if 'RL' not in d: print (-1) else: l = list(map(int,input().split())) r = min((l[x+1] - l[x]) // 2 for x in range(n-1) if d[x:x+2] =='RL') print (r)
PYTHON3
699_A. Launch of Collider
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.
2
7
#!/usr/bin/env python3 try: while True: n = int(input()) s = input() a = list(map(int, input().split())) result = -1 for i in range(1, n): if s[i - 1] == 'R' != s[i]: t = (a[i] - a[i - 1]) >> 1 if result == -1 or t < result: result = t print(result) except EOFError: pass
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.PrintStream; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Wolfgang Beyer */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); String temp = in.next(); boolean[] left = new boolean[n]; for (int i = 0; i < n; i++) { if (temp.charAt(i) == 'L') left[i] = true; else left[i] = false; } int[] x = in.readIntArray(n); int lastR = -1; int diff; int min = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { if (left[i] == false) { lastR = i; } else { if (lastR > -1) { diff = x[i] - x[lastR]; if (diff < min) min = diff; } } } if (min == Integer.MAX_VALUE) out.println("-1"); else out.println(min / 2); } } static class InputReader { private static BufferedReader in; private static StringTokenizer tok; public InputReader(InputStream in) { this.in = new BufferedReader(new InputStreamReader(in)); } public int nextInt() { return Integer.parseInt(next()); } public int[] readIntArray(int n) { int[] ar = new int[n]; for (int i = 0; i < n; i++) { ar[i] = nextInt(); } return ar; } public String next() { try { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } } catch (IOException ex) { System.err.println("An IOException was caught :" + ex.getMessage()); } return tok.nextToken(); } } }
JAVA
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int x, i, j, k, p = 10e9, c = 0; vector<int> v; cin >> x; char n[x + 1]; cin >> n; for (i = 0; i < x; i++) { cin >> k; v.push_back(k); } for (i = 0; i < x - 1; i++) { if (n[i] == 'R' && n[i + 1] == 'L') { k = v[i + 1] - v[i]; if (k < p) p = k; c = 1; } } if (c == 1) { cout << p / 2; return 0; } cout << -1; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; int ans = INT_MAX; string s; cin >> n >> s; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n; i++) { if (s[i - 1] == 'R' && s[i] == 'L') ans = min(ans, (a[i] - a[i - 1]) >> 1); } if (ans == INT_MAX) cout << "-1" << endl; else cout << ans << endl; }
CPP
699_A. Launch of Collider
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.
2
7
n = int(input()) directions = input() positions = [int(c) for c in input().split()] collisions = [] for i in range(len(directions) - 1): if directions[i] == 'R' and directions[i + 1] == 'L': collisions.append((positions[i+1] - positions[i]) // 2) if not collisions: print(-1) else: print(min(collisions))
PYTHON3
699_A. Launch of Collider
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.
2
7
n = int(raw_input()) directs = raw_input() a = map(int,raw_input().split(' ')) ans = 15**9 for i in range(1,n): if (directs[i] == 'L') & (directs[i-1] == 'R'): ans = min(ans, (a[i]-a[i-1])/2) if ans == 15**9: print -1 else: print ans
PYTHON
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, min = 10000000000000, c = 0, FLAG = 0; cin >> n; long long a[n + 1]; char s[n + 1]; cin >> s; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n - 1; i++) { if ((s[i] == 'R') && (s[i + 1] == 'L')) { c = (a[i + 1] - a[i]) / 2; FLAG = 1; if (c < min) min = c; } } if (FLAG == 1) cout << min; else cout << "-1"; }
CPP
699_A. Launch of Collider
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.
2
7
cases = int(input()) directions = [i for i in input()] array = [int(i) for i in input().split()] count = -1 for i in range(1, cases): if directions[i] == 'L' and directions[i-1] == 'R': if array[i] - array[i-1] < count or count == -1: count = array[i] - array[i-1] if count == -1: print(count) else: print(int(count/2))
PYTHON3
699_A. Launch of Collider
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.
2
7
n = int(raw_input()) dir = list(raw_input()) cor = map(int, raw_input().split()) mat = [] i = 0 while i < n - 1: if dir[i] == 'R' and dir[i+1] == 'L': mat.append((cor[i+1] - cor[i])/2) i += 2 else: i += 1 if len(mat) > 0: print min(mat) else: print -1
PYTHON
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = Integer.valueOf(s.nextLine()); int[] pos = new int[n]; char[] dir = s.nextLine().toCharArray(); int j = 0; int k = n; while(k-- > 0) { pos[j++] = s.nextInt(); } int firstColl = Integer.MAX_VALUE; for(int i = 0; i < n - 1; i++) { if(dir[i] == 'R' && dir[i+1] == 'L') { firstColl = Math.min(firstColl, (pos[i+1] - pos[i]) / 2); } } if(firstColl == Integer.MAX_VALUE) { System.out.println(-1); } else { System.out.println(firstColl); } } }
JAVA
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), res = Integer.MAX_VALUE; String d = sc.next(); int prevx = sc.nextInt(); for(int i = 1 ; i < n; i++) { int x = sc.nextInt(); if(d.charAt(i-1) == 'R' && d.charAt(i) == 'L') res = Math.min(res, x - prevx); prevx = x; } if(res == Integer.MAX_VALUE) System.out.println(-1); else System.out.println(res/2); sc.close(); } }
JAVA
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); long r=1000000000; int r0; int l=in.nextInt(); boolean b=false; String s=in.next(); int []arr=new int[l]; for (int i=0;i<l;i++){ arr[i]=in.nextInt(); } for (int k=0;k<l-1;k++){ if (s.charAt(k)=='R'&&s.charAt(k+1)=='L'){ r0=(arr[k+1]-arr[k])/2; if (r0<r){ r=r0;b=true; } } } if (!b)r=-1; System.out.println(r); } }
JAVA
699_A. Launch of Collider
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.
2
7
n=int(input()) s=input().rstrip() a=list(map(int,input().rstrip().split())) maxi=float('inf') for i in range(n-1): if s[i]=='R' and s[i+1]=='L': maxi=min(maxi,(a[i+1]-a[i])//2) if maxi==float('inf'): print(-1) else: print(maxi)
PYTHON3
699_A. Launch of Collider
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.
2
7
n = int(input()) t = input() z = float('inf') list1 = list(map(int,input().split())) for i in range(1,n): if t[i-1] == "R" and t[i] == "L": k = (list1[i]-list1[i-1])//2 z = min(z,k) if z == float("inf"): print(-1) else: print(z)
PYTHON3
699_A. Launch of Collider
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.
2
7
n=int(input()) s=input() m=list(map(int,input().split())) ans=[] if "RL" in s: f = s.index('R') s = s[f:] m = m[f:] for i in range(0,len(s)-1): a=s[i]+s[i+1] if a=="RL": ans.append((m[i+1]-m[i])//2) print(min(ans)) else: print(-1)
PYTHON3
699_A. Launch of Collider
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.
2
7
n = int(input()) dirs = input() vals = list(map(int, input().split())) found = False min = None for i in range(n - 1): ri = dirs[i] le = dirs[i + 1] if ri + le == 'RL': if (vals[i + 1] - vals[i]) % 2 == 0: found = True if min == None: min = (vals[i + 1] - vals[i]) else: if min > vals[i + 1] - vals[i]: min = (vals[i + 1] - vals[i]) if found == True: print(int(min/2)) else: print(-1)
PYTHON3
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int main() { int n, ans = 1e9; string s; cin >> n >> s; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'L') ans = min(ans, ((arr[i + 1] - arr[i]) / 2)); } if (ans == 1e9) cout << -1; else cout << ans; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; vector<int> adj[2002]; bool visited[2002]; int V; int dist[2001]; vector<int> ans; vector<int> indegree; void BFS() { for (int k = 1; k <= V; k++) { int maxi = 0; int s = k; if (!visited[s] && indegree[s] == 1) { dist[s] = 0; list<int> q; visited[s] = true; q.push_back(s); vector<int>::iterator itr; while (!q.empty()) { s = q.front(); q.pop_front(); for (itr = adj[s].begin(); itr != adj[s].end(); ++itr) { if (!visited[*itr]) { dist[*itr] = dist[s] + 1; visited[*itr] = true; q.push_back(*itr); } } } } } } int main() { int n; cin >> n; char str[n]; int posi[n]; scanf("%s", str); for (int i = 0; i < n; i++) cin >> posi[i]; int mini = 1000000000; for (int i = 0; i < n - 1; i++) { if (str[i] == 'R' && str[i + 1] == 'L') mini = min(mini, (posi[i + 1] - posi[i]) / 2); } if (mini < 1000000000) cout << mini; else cout << "-1"; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
from sys import stdin, stdout import sys INF=1e11 import bisect def get_int(): return int(stdin.readline().strip()) def get_ints(): return map(int,stdin.readline().strip().split()) def get_array(): return list(map(int,stdin.readline().strip().split())) def get_string(): return stdin.readline().strip() def op(c): return stdout.write(c) from collections import defaultdict import math #for _ in range(int(stdin.readline())): n=get_int() s=get_string() a=get_array() ans=INF f=0 for i in range(n-1): if s[i]=="R" and s[i+1]=="L": f=1 ans=min(ans,(a[i+1]-a[i])//2) if f==0: print(-1) else: print(ans)
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; public class LaunchOfCollider { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); scan.nextLine(); String s = scan.nextLine(); String[] arr = scan.nextLine().split(" "); int ans = Integer.MAX_VALUE; for(int i = 0; i < n-1; i++){ int z = Integer.parseInt(arr[i]); int x = Integer.parseInt(arr[i+1]); if(s.charAt(i+1) == 'L' && s.charAt(i) == 'L') i++; else if(s.charAt(i) == 'R' && s.charAt(i+1) == 'L'){ ans = Math.min(ans, (x-z)/2); } } System.out.println(ans == Integer.MAX_VALUE ? "-1" : ans); } }
JAVA
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int a[n]; int dis = INT_MAX; for (int i = 0; i < n; i++) { cin >> a[i]; if (i != 0) { if (s[i] == 'L' && s[i - 1] == 'R') { int x = a[i] - a[i - 1]; if (x < dis) dis = x; } } } if (dis == INT_MAX) cout << "-1" << endl; else cout << dis / 2 << endl; }
CPP
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; /** * Created by Hp on 7/19/2016. */ public class A { public static void main(String [] ar){ Scanner s=new Scanner(System.in); int n=s.nextInt(); s.nextLine(); String st=s.nextLine(); long [] a=new long[n]; for(int i=0;i<n;i++)a[i]=s.nextLong(); long min=Integer.MAX_VALUE; boolean f=false; for(int i=0;i<n-1;i++){ char p=st.charAt(i); char q=st.charAt(i+1); if(p=='R'&&q=='L'){ f=true; long d=a[i+1]-a[i]; if(min>d) min=d; } } if(f) { System.out.println(min / 2); } else System.out.println(-1); } }
JAVA
699_A. Launch of Collider
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.
2
7
n = input() s = raw_input() a = map(int, raw_input().split()) ans = 1 << 60 for i in range(1, n): if s[i - 1] == 'R' and s[i] == 'L': ans = min(ans, a[i] - a[i - 1] >> 1) print ans if ans < (1 << 60) else -1
PYTHON
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; const double PI = acos(0) * 2; const double EPS = 1e-8; const long long MOD = 1e9 + 7; const int MAXN = 1e5 + 5; const int oo = 1e9 + 10; const double foo = 1e30; template <class T> int getbit(T s, int i) { return (s >> i) & 1; } template <class T> T onbit(T s, int i) { return s | (T(1) << i); } template <class T> T offbit(T s, int i) { return s & (~(T(1) << i)); } template <class T> int cntbit(T s) { return __builtin_popcounll(s); } inline void addmod(int& a, int val, int p = MOD) { if ((a = (a + val)) >= p) a -= p; } inline void submod(int& a, int val, int p = MOD) { if ((a = (a - val)) < 0) a += p; } inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } int n; char s[200100]; int a[200100]; int ans = oo; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { ans = min(ans, a[i + 1] - a[i]); } } if (ans == oo) { cout << -1; return 0; } cout << ans / 2; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long int n, count = 0; cin >> n; long long int c[n]; string s; cin >> s; for (long long int i = 0; i < n; i++) { cin >> c[i]; } for (long long int i = 1; i < n; i++) { if (s.at(i) == 'L' && s.at(i - 1) == 'R') { c[count++] = abs(c[i] - c[i - 1]); } } long long int max = c[0]; for (long long int i = 1; i < count; i++) { if (c[i] < max) max = c[i]; } if (count > 0) cout << max / 2; else cout << "-1"; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
import java.util.*; public class Main { private static Scanner in = new Scanner(System.in); public static void main(String[] args) { // write your code here int n = in.nextInt(); int i, h; String direction = in.next(); if (!direction.contains("RL")) { System.out.println(-1); return; } int[] arr = new int[n]; List<Integer> arr2 = new ArrayList<>(); for (i = 0; i < n; i++) { arr[i] = in.nextInt(); } for (i = 0; i < direction.length() - 1; i ++) { if (direction.charAt(i) == 'R' && direction.charAt(i + 1) == 'L') { arr2.add(arr[i]); arr2.add(arr[i + 1]); } } List<Integer> arr3 = new ArrayList<>(); for (i = 1, h = 0; i < arr2.size(); i+=2, h++) { int x = (arr2.get(i) - arr2.get(i - 1)) / 2; arr3.add(x); } Collections.sort(arr3); System.out.println(arr3.get(0)); } }
JAVA
699_A. Launch of Collider
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.
2
7
n = int(input()) s = input() l = [int(x) for x in input().split()] t = float('inf') for i in range(1, n): if s[i-1] == 'R' and s[i] == 'L': x = (l[i]-l[i-1])//2 t = min(x, t) if t == float('inf'): print(-1) else: print(t)
PYTHON3
699_A. Launch of Collider
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.
2
7
n = int(input()) s = input() l = list(map(int, input().split())) x=[] for i in range(n-1): if (s[i] == 'R' and s[i+1] == 'L'): x.append((l[i+1] - l[i])//2) if(len(x) == 0): print(-1) else: print(min(x))
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.util.*; public class Car { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String a = sc.next(); int[] arr = new int[n]; if (!a.contains("RL")) { System.out.print(-1); return; } int min = 1000000001; for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); for (int i = 1; i < n; i++) { if (a.charAt(i) == 'L' && a.charAt(i-1) == 'R') { if ((arr[i] - arr[i-1]) / 2 < min) min = (arr[i] - arr[i-1]) / 2; } } System.out.print(min); } }
JAVA
699_A. Launch of Collider
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.
2
7
n=int(raw_input()) s=list(raw_input()) l=list(map(long,raw_input().split())) min_=789465561456545 c=0 for i in xrange(n-1): if s[i]=='R' and s[i+1]=='L': c=1 k=l[i+1]-l[i] if k<min_: min_=k if min_==1: break if c==0: print -1 else: print min_/2
PYTHON
699_A. Launch of Collider
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.
2
7
def main(): n_particles = int(input()) movements = input() positions = [int(_) for _ in input().split()] happened = -1 for i in range(n_particles - 1): if movements[i] == 'R' and movements[i + 1] == 'L': will_happen_in = (positions[i + 1] - positions[i]) // 2 if happened == -1 or will_happen_in < happened: happened = will_happen_in print(happened) if __name__ == '__main__': main()
PYTHON3
699_A. Launch of Collider
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.
2
7
n = int(input()) val = input() crd = list(map(int, input().split())) cur = -1 ans = 10 ** 19 for i in range(n): if val[i] == 'R': cur = i else: if cur != -1: ans = min(ans, (crd[i] - crd[cur]) // 2) if ans < 10 ** 19: print(ans) else: print(-1)
PYTHON3
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; long long choose(long long n, long long k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } long long gcd(long long a, long long b) { if (!a) return b; return gcd(b % a, a); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; cin >> n; string s; cin >> s; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } long long ans = LONG_LONG_MAX; for (long long i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { ans = min(ans, (a[i + 1] - a[i]) / 2); } } if (ans == LONG_LONG_MAX) cout << -1; else cout << ans; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll mod = 1e9 + 7; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char c) { return string(1, c); } string to_string(const char* s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (int i = int(N) - 1; i >= 0; --i) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto& x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } int main() { ios::sync_with_stdio(0); cin.tie(0); ll n; cin >> n; string s; cin >> s; vector<ll> A(n); for (auto& _a : A) cin >> _a; vector<int> left, right; for (int i = 0; i < n; ++i) { if (s[i] == 'L') { left.push_back(A[i]); } else { right.push_back(A[i]); } } if (0) { }; if (0) { }; sort(left.begin(), left.end()); sort(right.begin(), right.end()); int nl = left.size(), nr = right.size(); ll ans = INT_MAX; for (int r = 0; r < nr; ++r) { auto it = lower_bound(left.begin(), left.end(), right[r]); if (it != left.end()) { ans = min(ans, ll(*it - right[r]) / 2); } } if (ans == INT_MAX) ans = -1; cout << ans << '\n'; }
CPP
699_A. Launch of Collider
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.
2
7
k=['RL','LR'] n=int(input()) s=input() l=list(map(int, input().split())) minn=10**10; p=0 for i in range(n-1): if s[i:i+2]=='RL': minn=min(minn,(l[i+1]-l[i])//2) print(-1 if minn==10**10 else minn)
PYTHON3
699_A. Launch of Collider
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.
2
7
# input() # directions = input() # positions = list(map(int, input().split())) # times = [] # while directions.find('RL') != -1: # index = directions.find('RL') # times.append((positions[index+1] - positions[index])//2) # dir1 = directions[:index] # dir2 = directions[index + 2:] # directions = dir1 + dir2 # positions.pop(index) # positions.pop(index) # print(min(times) if len(times) > 0 else -1) """ hallar la distancia entre cada partΓ­cula iterar una vez, y hallarla de nuevo, guardar las que disminuyeron hallar la distancia mΓ­nima de estas que disminuyeron calcular el tiempo de colisiΓ³n t = abs(p1-p2)/2 una partΓ­cula colisiona con otra si estΓ‘ a la izquierda y tiene velocidad R y la otra tiene velocidad """ n = int(input()) directions = list(input()) positions = list(map(int, input().split())) times = [] for i in range(n-1): if directions[i] == 'R' and directions[i+1] == 'L': times.append((positions[i+1]-positions[i])//2) print(min(times) if len(times) > 0 else -1)
PYTHON3
699_A. Launch of Collider
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.
2
7
import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Dell */ public class NewMain59 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner s = new Scanner(System.in); int n = s.nextInt(); String str = s.next(); int[] ar = new int[n]; for (int i = 0; i < n; i++) { ar[i] = s.nextInt(); } if (!str.contains("RL")) { System.out.println("-1"); return; } int min = Integer.MAX_VALUE; for (int i = 0; i < n - 1; i++) { if (str.charAt(i) == 'R' && str.charAt(i + 1) == 'L') { int m = Math.min(ar[i], ar[i + 1]); int x = (ar[i] + ar[i + 1]) / 2; min = Math.min(min, x - m); } } System.out.println(min); } }
JAVA
699_A. Launch of Collider
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.
2
7
n = int(raw_input()) f = raw_input() s = map(int,raw_input().split()) flag = 0 p = float('inf') for i in xrange(n): if f[i]=='L' and i>0 and f[i-1]=='R': p = s[i]-s[i-1] if s[i]-s[i-1]<p else p flag = 1 print p/2 if flag==1 else -1
PYTHON
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector<int> x(n, 0); for (int i = 0; i < n; i++) cin >> x[i]; int i = 0; int res = INT32_MAX; for (; i < n;) { if (s[i] != 'R') { ++i; continue; } else if (i < n - 1) { while (i < n - 1) { if (s[i + 1] == 'L') { break; } else { ++i; } } if (i + 1 < n && s[i + 1] == 'L') { res = min(res, (x[i + 1] - x[i]) / 2); } } ++i; } if (res == INT32_MAX) cout << -1 << endl; else cout << res << endl; }
CPP
699_A. Launch of Collider
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.
2
7
#77 n=int(input()) a=input() b=list(map(int,input().split())) r=[] for x in range(len(a)-1): if a[x]=='R' and a[x+1]=='L': r.append((b[x+1]-b[x])//2) if r== []: print(-1) else: print(min(r))
PYTHON3
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int a[maxn]; int main() { int n; string ss; vector<int> L, R; cin >> n >> ss; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { if (ss[i] == 'R') R.push_back(a[i]); else L.push_back(a[i]); } int minn = 0x3f3f3f3f; for (int i = 0; i < R.size(); i++) { auto it = lower_bound(L.begin(), L.end(), R[i]); if (it == L.end()) continue; else { minn = min(minn, (*it - R[i]) / 2); } } if (minn == 0x3f3f3f3f) minn = -1; cout << minn << endl; return 0; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> int main() { char RL[200005]; int m = 1000000000, n, a = 0, h = 0, i, j = 0, min; int coor[200005], orz[200005]; scanf("%d", &n); scanf("%s", RL); for (i = 0; i < n; i++) scanf("%d", &coor[i]); int b = n - 1; while (a < n && RL[a] == 'L') a++; while (b >= 0 && RL[b] == 'R') b--; for (i = a; i < b; i++) { if (RL[i] == 'R' && RL[i + 1] == 'L') { h = 1; min = (coor[i + 1] - coor[i]) / 2; if (m > min) m = min; } } if (h) printf("%d\n", m); else printf("%d\n", -1); return 0; }
CPP
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; char s[200001]; int a[200001]; int main() { int n; scanf("%d", &n); scanf("%s", &s); int i; for (i = 0; i < n; ++i) scanf("%d", &a[i]); int ans = 0x3f3f3f3f; int l, r; for (i = 1; i < n; ++i) { if (s[i] == 'L' && s[i - 1] == 'R') ans = min((a[i] - a[i - 1]) / 2, ans); } if (ans == 0x3f3f3f3f) printf("-1\n"); else printf("%d\n", ans); return 0; }
CPP
699_A. Launch of Collider
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.
2
7
import java.io.IOException; import java.util.InputMismatchException; public class AryansStuckAgain { public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int n = Integer.parseInt(sc.nextLine()); char[] ch = sc.nextLine().toCharArray(); int[] arr = sc.nextIntArray(n); int a=1000000001,ans=1000000001; for(int i=0;i<n-1;i++){ if(ch[i]=='R' && ch[i+1]=='L'){ a = (arr[i+1]-arr[i])/2; } if(a<ans) ans=a; } if(ans==1000000001) System.out.println("-1"); else System.out.println(ans); } public static class FasterScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
JAVA
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> using namespace std; const int inf = 1000000000; const int maxn = 200005; char d[maxn]; int x[maxn]; int main() { int n, ans = inf; scanf("%d%s", &n, d); for (int i = 0; i < n; ++i) scanf("%d", x + i); for (int i = 1; i < n; ++i) { if (d[i - 1] == 'R' && d[i] == 'L') ans = min(ans, (x[i] - x[i - 1]) / 2); } if (ans == inf) ans = -1; printf("%d", ans); }
CPP
699_A. Launch of Collider
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.
2
7
# import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("outp.out",'w') n=int(input()) s=input() a=list(map(int,input().split())) f=0 for i in range(n): if f==0 and i<n-1 and s[i]=="R" and s[i+1]=="L": t=(a[i+1]-a[i])//2 f=1 elif i<n-1 and s[i]=="R" and s[i+1]=="L": t=min(t,(a[i+1]-a[i])//2) if f==0: print(-1) else: print(t)
PYTHON3
699_A. Launch of Collider
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.
2
7
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n, x; string s; cin >> n >> s; vector<int> left, right; for (int i = 0; i < n; i++) { cin >> x; if (s[i] == 'L') left.push_back(x / 2); else right.push_back(x / 2); } sort(left.begin(), left.end()); sort(right.begin(), right.end()); int ans = INT_MAX; bool collide = false; for (int i = 0; i < right.size(); i++) { vector<int>::iterator f = upper_bound(left.begin(), left.end(), right[i]); if (f == left.end()) continue; else { collide = true; ans = min(*f - right[i], ans); } } if (collide) cout << ans; else cout << -1; return 0; }
CPP