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
#include <bits/stdc++.h> using namespace std; const int inf = 2e9; int ara[200002]; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) cin >> ara[i]; int res = inf, test = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R' && s[i + 1] == 'L' && ara[i] < ara[i + 1]) res = min(res, (ara[i + 1] - ara[i]) / 2); } if (res == inf) res = -1; cout << res << 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
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String str = sc.next(); int max = 500000001; int now = 0; int prev; for(int i=0;i<n-1;i++){ prev = now; now = sc.nextInt(); if(str.charAt(i) == 'R'){ if(str.charAt(i+1) == 'L'){ prev = now; now = sc.nextInt(); max = Math.min(max, (now-prev)/2); i++; } } } if(max == 500000001){ System.out.println(-1); } else{ System.out.println(max); } } }
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() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; bool f = 0; cin >> n; string s; int sp[n]; cin >> s; int lol = INT_MAX; for (int i = 0; i < n; i++) { cin >> sp[i]; } for (int i = 0; i < n; i += 1) { if (s[i] == 'R' && s[i + 1] == 'L') { lol = min(lol, (sp[i + 1] - sp[i])); } } if (lol == INT_MAX) cout << -1; else cout << lol / 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
lst=[] z=int(input()) x=list(map(str,input())) c=list(map(int,input().split())) for v in range(z-1): if x[v]=='R': if x[v+1]=='L': b=(c[v+1]-c[v])//2 lst.append(b) if len(lst)!=0: print(min(lst)) 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 Launchofcollidor { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int n = input.nextInt(); String s = input.next(); int[] arr = new int[n]; for(int i=0;i<n;i++)arr[i] = input.nextInt(); int ans=Integer.MAX_VALUE; boolean condition = false; for(int i=1;i<n;i++){ if(s.charAt(i-1)=='R' && s.charAt(i)=='L'){ if((arr[i]-arr[i-1])<ans)ans = arr[i]-arr[i-1]; condition = true; } } if(condition)System.out.println(ans/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
#include <bits/stdc++.h> using namespace std; const int MN = 1e9 + 7, MXN = 2e6 + 5; int n, mn = MN; bool u[MXN]; string s; int main() { cin >> n >> s; for (int i = 0; i < s.size(); i++) if (s[i] == 'R') u[i + 1] = 1; int x, y; cin >> x; for (int i = 2; i <= n; i++) { cin >> y; if (u[i - 1] && !u[i]) mn = min(mn, y - x); swap(x, y); } if (mn == MN) cout << -1; else cout << mn / 2; 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()) moves = list(input()) pos = [int(x) for x in input().split()] minTime = 1000000000 for i in range (n - 1): if moves[i] == 'R' and moves[i + 1] == 'L': time = int((pos[i + 1] - pos[i]) / 2) minTime = min(time, minTime) if minTime != 1000000000: print(minTime) 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; void delbit(long long &a, long long k) { a &= (~(1 << k)); } bool getbit(long long a, long long k) { return 1 & (a >> k); } long long setbit(long long &a, long long k) { return a |= (1 << k); } inline long long mulmod(long long x, long long n, long long _mod) { long long res = 0; while (n) { if (n & 1) res = (res + x) % _mod; x = (x + x) % _mod; n >>= 1; } return res; } inline long long powmod(long long x, long long n, long long _mod) { long long res = 1; while (n) { if (n & 1) res = (res * x) % _mod; x = (x * x) % _mod; n >>= 1; } return res; } inline long long gcd(long long a, long long b) { long long t; while (b) { a = a % b; t = a; a = b; b = t; } return a; } inline int gcd(int a, int b) { int t; while (b) { a = a % b; t = a; a = b; b = t; } return a; } inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } inline long long gcd(long long a, long long b, long long c) { return gcd(gcd(a, b), c); } inline int gcd(int a, int b, int c) { return gcd(gcd(a, b), c); } double dist(double ax, double ay, double bx, double by) { return sqrt(((ax - bx) * (ax - bx)) + ((ay - by) * (ay - by))); } char s[200010]; int a[200010]; int calc(int a, int b) { return (b - a) / 2; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, ans = 2147483640; cin >> n; for (int(i) = (1); (i) < (n + 1); (i)++) { cin >> s[i]; } s[0] = '-'; for (int(i) = (1); (i) < (n + 1); (i)++) { cin >> a[i]; if (s[i] == 'L') { if (s[i - 1] == 'R') { ans = (((ans) < (calc(a[i - 1], a[i]))) ? (ans) : (calc(a[i - 1], a[i]))); } } } if (ans == 2147483640) cout << "-1\n"; 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
n,s=int(input()),input() l,nl=[int(ele) for ele in input().split()],[] for i in range(len(s)): try: if s[i]=='R' and s[i+1]=='L': app=(l[i+1]-l[i])/2 nl.append(int(app)) except:continue if len(nl)==0:print(-1) else:print(min(nl))
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 A1008 { public static void main(String [] args) /*throws Exception*/ { InputStream inputReader = System.in; OutputStream outputReader = System.out; InputReader in = new InputReader(inputReader);//new InputReader(new FileInputStream(new File("input.txt")));new InputReader(inputReader); PrintWriter out = new PrintWriter(outputReader);//new PrintWriter(new FileOutputStream(new File("output.txt"))); Algorithm solver = new Algorithm(); solver.solve(in, out); out.close(); } } class Algorithm { void solve(InputReader ir, PrintWriter pw) { int n = ir.nextInt(), max = 1000000000; String line = ir.next(); char [] moves = line.toCharArray(); int [] pos = new int[n]; for (int i = 0; i < n; i++) pos[i] = ir.nextInt(); for (int i = 0; i < n - 1; i++) { if (moves[i] == 'R' && moves[i + 1] == 'L') { if ((pos[i + 1] - pos[i]) / 2 < max) max = (pos[i + 1] - pos[i]) / 2; } } pw.print(max == 1000000000 ? "-1" : max); } private static void Qsort(int[] array, int low, int high) { int i = low; int j = high; int x = array[low + (high - low) / 2]; do { while (array[i] < x) ++i; while (array[j] > x) --j; if (i <= j) { int tmp = array[i]; array[i] = array[j]; array[j] = tmp; i++; j--; } } while (i <= j); if (low < j) Qsort(array, low, j); if (i < high) Qsort(array, i, high); } } class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } String nextLine(){ String fullLine = null; while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { fullLine = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return fullLine; } return fullLine; } String [] toArray() { return nextLine().split(" "); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } }
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
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner s= new Scanner(System.in); int n = s.nextInt(); String str = s.next(); int[] arr = new int[n]; for(int i=0 ; i<n ;i++){ arr[i] = s.nextInt(); } int minDist = Integer.MAX_VALUE; for(int i=0 ; i<n-1 ; i++){ if(i+1 < n && arr[i] == arr[i+1]) minDist = 0; else if(str.charAt(i) == 'R' && str.charAt(i+1) == 'L' ){ int exptime = (arr[i+1]- arr[i])/2; if(exptime < minDist) minDist = exptime; } } if(minDist == Integer.MAX_VALUE) System.out.println(-1); else System.out.println(minDist); } }
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.*; public class helloWorld { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String str = in.next(); int[] ar = new int[n]; int ans = -1; int last = in.nextInt(); for(int i = 1; i < n; i++) { int a = in.nextInt(); if(str.charAt(i-1) == 'R' && str.charAt(i) == 'L') if(ans == -1 || ans > (a-last) / 2) ans = (a-last)/2; last = a; } System.out.println(ans); in.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.*; import java.text.*; import java.math.*; import java.util.*; public class q { public static void main(String[] args) { IO io = new IO(); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); if(n == 1) { io.pln("-1"); return; } String s = sc.nextLine(); char[] dir = s.toCharArray(); //io.pln(s); //sc.next(); long[] pos = new long[n]; for(int i = 0; i<n; i++) pos[i] = sc.nextLong(); long min = 1000000000; int flag = 0; if(n == 2) { if(dir[0] == 'R' && dir[1] == 'L') { io.pln((pos[1]/2-pos[0]/2)); return; } io.pln("-1"); return; } //System.out.println("length" + dir.length); for(int i = 1; i<n-1; i++) { if(dir[i] == 'L' && dir[i-1] == 'R') { //System.out.println("1"); if(min > (pos[i] - pos[i-1]) ) { min = pos[i]-(pos[i-1]); flag = 1; } } else if(dir[i] == 'R' && dir[i+1] == 'L') { //System.out.println("2"); if(min > (pos[i+1] - pos[i])) { flag = 1; min = pos[i+1]-(pos[i]); } } } min = min/2; if(flag == 0) { io.pln("-1"); return; } io.pln(min); } } class IO { BufferedReader in; OutputStream out; public IO() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new BufferedOutputStream (System.out); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } /* Read an Integer */ public int iread() { try { return Integer.parseInt(readword()); } catch(NumberFormatException e) { e.printStackTrace(); System.exit(1); return -1; } } /********************/ /* Read a double */ public double dread() { try { return Double.parseDouble(readword()); } catch(NumberFormatException e) { e.printStackTrace(); System.exit(1); return -1; } } /*******************/ /* Read a long */ public long lread() { try { return Long.parseLong(readword()); } catch(NumberFormatException e) { e.printStackTrace(); System.exit(1); return -1; } } /************************/ /* Read a single word */ public String readword() { StringBuilder b = new StringBuilder(); int c; try { c = in.read(); while (c >= 0 && c <= ' ') c = in.read(); if (c < 0) return ""; while (c > ' ') { b.append((char) c); c = in.read(); } return b.toString(); } catch(Exception e) { e.printStackTrace(); System.exit(1); return ""; } } /************************/ /* Read an entire line */ public String readLine() { try { return in.readLine(); } catch(Exception e) { e.printStackTrace(); System.exit(1); return ""; } } /************************/ /* Read a BigInteger */ public BigInteger bread() { return new BigInteger(this.readword()); } /*************************/ /* PRINTING */ /*************************/ /* Print an integer */ public void p(int obj) { try { out.write((obj+"").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /***************************/ /* Print an integer with newline */ public void pln(int obj) { try { out.write((obj+"\n").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /**************************/ /* Print a long */ public void p(long obj) { try { out.write((obj+"").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /***************************/ /* Print a long with newline */ public void pln(long obj) { try { out.write((obj+"\n").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /**************************/ /* Print a double */ public void p(double obj) { try { out.write((obj+"").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /***************************/ /* Print a double with newline */ public void pln(double obj) { try { out.write((obj+"\n").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /******************/ /* Print a string */ public void p(String obj) { try { out.write((obj).getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /*****************************/ /* Print a string with newline */ public void pln(String obj) { try { out.write((obj+"\n").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /***************************/ /* Print a BigInteger */ public void p(BigInteger obj) { try { out.write((obj+"").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /*****************************/ /* Print a BigInteger with newline */ public void pln(BigInteger obj) { try { out.write((obj+"\n").getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /**********************************/ /* Print a string array */ public void p(String[] obj) { try { for(String str: obj) out.write((str + " ").getBytes()); out.write("\n".getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /*******************************/ /* Print an integer array */ public void p(int[] obj) { try { for(int el: obj) out.write((el + " ").getBytes()); out.write("\n".getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /********************************/ /* Print a double array */ public void p(double[] obj) { try { for(double el: obj) out.write((el + " ").getBytes()); out.write("\n".getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /********************************/ /* Print a long array */ public void p(long[] obj) { try { for(long el: obj) out.write((el + " ").getBytes()); out.write("\n".getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } /********************************/ /* Print a BigInteger array */ public void p(BigInteger[] obj) { try { for(BigInteger el: obj) out.write((el+" ").getBytes()); out.write("\n".getBytes()); out.flush(); } catch(Exception e) { e.printStackTrace(); System.exit(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
import java.util.*; /** * * @author Loay mansour */ public class CodeForces { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int ans = Integer.MAX_VALUE; int temp = 0; for (int i = 1; i < n; i++) { if (s.charAt(i) == 'L' && s.charAt(i - 1) == 'R') { temp = (arr[i] - arr[i - 1]) / 2; if (temp < ans) { ans = temp; } } } System.out.println((ans == Integer.MAX_VALUE ? -1 : ans)); }//End Main. }//End Class.
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
var nbOfElement = Number(readline()); var direction = readline(); var elements = readline() .split(' ') .map(Number); var pair = []; for (var i = 1; i < nbOfElement; ++i) { if (direction[i - 1] === 'R' && direction[i] === 'L') { pair.push([i - 1, i]); } } var smallestPair = Infinity; for (var i = 0; i < pair.length; i++) { smallestPair = Math.min( smallestPair, Math.round((elements[pair[i][1]] - elements[pair[i][0]]) / 2) ); } if (pair.length === 0) { print(-1); } else { print(smallestPair); }
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() m = raw_input() a = map(int,raw_input().split()) ans = 1000000001 if n == 1: print -1 else: for i in xrange(len(m)-1): if m[i] == 'R' and m[i+1] == 'L': ans = min(ans,a[i+1] - a[i]) if ans == 1000000001: 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
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string d; cin >> d; vector<long long> c; long long t; for (int i = 0; i < n; i++) { cin >> t; c.push_back(t); } long long mini = -1; for (int i = 0; i < n - 1; i++) { if (d[i] == 'R' && d[i + 1] == 'L') { if (mini == -1) mini = (c[i + 1] - c[i]) / 2; else mini = min(mini, (c[i + 1] - c[i]) / 2); } } cout << mini; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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 java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); char[] s = in.readString().toCharArray(); long[] a = IOUtils.readLongArray(in, n); long tr = -1; long ans = Long.MAX_VALUE; for (int i = 0; i < n; i++) { if (s[i] == 'L') { if (tr != -1) { ans = Math.min(ans, (a[i] - tr) / 2); } } else { tr = a[i]; } } out.printLine(ans == Long.MAX_VALUE ? -1 : ans); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { 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 long readLong() { 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 String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void printLine(long i) { writer.println(i); } } static class IOUtils { public static long[] readLongArray(InputReader in, int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = in.readLong(); } return array; } } }
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 long long mod = 1e9 + 7; void solve() { long long n; cin >> n; string s; cin >> s; vector<long long> v(n); for (long long i = 0; i <= n - 1; i++) cin >> v[i]; long long ans = mod; for (long long i = 0; i <= n - 2; i++) { if (s[i] == 'R' && s[i + 1] == 'L') ans = min(ans, abs(v[i] - v[i + 1])); } if (ans == mod) cout << -1; else cout << ans / 2; } int main() { long long tc = 1; while (tc--) { solve(); } }
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() a = list(map(int,input().split())) if "L" not in s: print(-1) exit(0) if "R" not in s: print(-1) exit(0) ans = [] flag = 0 for i in range(n): if s[i] == "R": right = a[i] flag = 1 elif flag and s[i] == "L": left = a[i] flag = 0 ans.append([right,left]) min = 10**10 if ans: for i in ans: val = abs(i[0]-i[1]) if val<min: min = val print(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
n = int(input()) s = input() l = list(map(int, input().split())) # if n==1: # print(-1) answer = 9999999999 for i in range(len(l)-1): if s[i] == "R" and s[i+1]=="L": answer = min(answer, (l[i+1] - l[i])//2) if answer == 9999999999: print(-1) else: print(answer)
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() { long long int t, min_t = -1; int n; long long int pos1, pos2; scanf("%d", &n); char a[n]; scanf("%s", &a); cin >> pos1; for (int i = 1; i < n; i++) { cin >> pos2; if (a[i - 1] == 'R' && a[i] == 'L') { t = (pos2 - pos1) / 2.0; if (min_t == -1) { min_t = t; } else { if (min_t > t) min_t = t; } } pos1 = pos2; } cout << min_t << 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
import java.util.Scanner; public class Q1 { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); String dir=s.next(); int cords[]=new int[n]; long temp=Long.MAX_VALUE; long min=Long.MAX_VALUE; for(int i=0;i<n;i++)cords[i]=s.nextInt(); for(int i=0;i<n-1;i++){ if(dir.charAt(i)=='R' && dir.charAt(i+1)=='L'){ min=Math.min(min,Math.abs(cords[i+1]-cords[i])); } } if(min==Long.MAX_VALUE)System.out.println("-1"); else System.out.println(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
I=input R=range S=sorted n=int(I()) r=[[],[]] for s,v in zip(I(),map(int,I().split())):r[s=='R']+=[v] m=10**9 i=0 j=0 a=S(r[0]) b=S(r[1]) while i<len(a) and j<len(b): if b[j]>a[i]:i+=1 else:m=min(m,(a[i]-b[j])//2);j+=1 print([m,-1][m==10**9])
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() Move = input() X = list(map(int, input().split())) Count = 10 ** 10 i = 0 while i < len(X): if Move[i] == 'R': while i + 1 < len(X) and Move[i + 1] == 'R': i += 1 if 'L' not in Move[i:]: break Count = min(Count, (X[Move[i:].index('L') + i] - X[i]) // 2) if Count == 1: print(1) exit() i += 1 print(-1 if Count == 10 ** 10 else Count)
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 ara[2000400]; int main() { int n; string s; long long int MIN = pow(2, 31); int dif = -1; cin >> n >> s; for (int i = 0; i < n; i++) { cin >> ara[i]; } for (int i = 0; i < n; i++) { if (s[i] == 'R' && s[i + 1] != 'R') { for (int j = i + 1; j < n; j++) { if (s[j] == 'L') { dif = ara[j] - ara[i]; dif /= 2; if (dif < MIN) { MIN = dif; } break; } } } } if (dif == -1) { cout << dif << endl; } else { cout << MIN << 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
#include <bits/stdc++.h> using namespace std; int n; int a[200001]; string s; long long giay = 1000000000; int main() { cin >> n; cin >> s; for (int i = 0; i < n; i++) cin >> a[i]; int i = 0; while (s[i] == 'L') i++; int r = n - 1; while (s[r] == 'R') r--; if (i > r) { cout << -1; return 0; } else { for (int k = i + 1; k <= r; k++) if (s[k] != s[k - 1] && s[k] == 'L') { long long tam = (a[k] + a[k - 1]) / 2; long long na = a[k] - tam; long long nb = tam - a[k - 1]; long long mn = na; if (na > nb) mn = nb; if (nb < giay) giay = nb; } cout << giay; } 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.*; import java.io.*; public class P699A { private static void solve() { int n = nextInt(); char[] dir = next().toCharArray(); int[] dist = new int[n]; for (int i = 0; i < n; i++) { dist[i] = nextInt(); } int ans = Integer.MAX_VALUE; for (int i = 0; i < n - 1; i++) { if(dir[i] == 'R' && dir[i + 1] == 'L') { ans = Math.min(ans, (dist[i + 1] - dist[i]) / 2); } } System.out.println(ans == Integer.MAX_VALUE ? -1 : ans); } private static void run() { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } private static StringTokenizer st; private static BufferedReader br; private static PrintWriter out; private static String next() { while (st == null || !st.hasMoreElements()) { String s; try { s = br.readLine(); } catch (IOException e) { return null; } st = new StringTokenizer(s); } return st.nextToken(); } private static int nextInt() { return Integer.parseInt(next()); } private static long nextLong() { return Long.parseLong(next()); } public static void main(String[] args) { run(); } }
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/python3 inf = 1e9 def main(): n = int(input()) dir = input() coords = list(map(int, input().split())) res = inf maxr = -1 for i in range(n): if dir[i] == "R": maxr = coords[i] else: if maxr != -1: res = min((coords[i] - maxr) / 2, res) if res == inf: print(-1) else: print(int(res)) 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
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class RUNNING { /** * @param args */ public static void main(String[] args) { Scanner sc= new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); long[]a= new long[n]; for(int i=0;i<n;i++){ a[i]=sc.nextLong(); } long start=-1; long ans=Long.MAX_VALUE; for(int i=0;i<n;i++){ if(s.charAt(i)=='R'){ start=a[i]; } else if(s.charAt(i)=='L'&&start!=-1){ long w=((a[i]-start)/2); ans=Math.min(ans,w); start=-1; } } if(ans!=Long.MAX_VALUE) System.out.println(ans); 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 = int(input()) if N == 1: print(-1) exit() S = input() X = list(map(int, input().split())) stk = [] ans = int(1e9) for s, x in zip(S, X): if len(stk) == 0: stk.append((s, x)) continue top = stk[-1] if top[0] == "R" and s == "L": ans = min(ans, x - (top[1] + x) // 2) stk.pop() else: stk.append((s, x)) if ans == int(1e9): 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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; int lr = -1; int ans = 1000000001; for (int i = 0; i < n; i++) { int x; cin >> x; if (s[i] == 'R') { lr = x; } else { if (lr >= 0) { ans = min(ans, (x - lr) / 2); } } } if (ans == 1000000001) { 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
n=int(input()) s=input() l=list(map(int,input().split())) res=float("inf") ans=False if n==1: print(-1) else: for i in range(n-1): if (s[i]=="R" and s[i+1]=="L"): ans=True res=min(res,abs(l[i]-l[i+1])//2) if not ans: print(-1) else: 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
#include <bits/stdc++.h> using namespace std; int a[200001], b[200001]; int main() { long long n; cin >> n; for (long long i = 0; i < n; i++) { char s; cin >> s; if (s == 'L') a[i] = -1; else a[i] = 1; } for (int i = 0; i < n; i++) cin >> b[i]; bool flag = false; long long i = 0, dif; int min1; if (a[0] == 1 && a[1] == -1) { min1 = (b[1] - b[0]) / 2; flag = true; } else min1 = INT_MAX; for (i = 1; i < n - 1; i++) { if (a[i] == 1 && a[i + 1] == -1) { dif = (b[i + 1] - b[i]) / 2; if (dif < min1) min1 = dif; flag = true; } } if (flag == true) cout << min1 << endl; else cout << "-1" << 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class A { public static void main(String[] args) throws IOException { Scanner sc= new Scanner(System.in); int n= sc.nextInt(); int arr[]= new int [n]; String s= sc.nextLine(); for(int i=0; i<n;i++) arr[i]= sc.nextInt(); boolean flag=false; int mindist=0; for(int i=1; i<n; i++){ char c= s.charAt(i); int now=0; int dist= arr[i]-arr[i-1]; if((c=='L' && s.charAt(i-1)=='R')){ if(!flag){ flag= true; mindist=dist; } else mindist= Math.min(dist, mindist); } } if(flag) System.out.println(mindist/2); else System.out.println(-1); } 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
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5, oo = 2e9; char s[maxn]; int p[maxn], sh[maxn]; int ans = oo, n, i; bool cmp(int a, int b) { return p[a] < p[b]; } int main() { scanf("%d", &n); scanf("%s", s + 1); for (i = 1; i <= n; i++) { scanf("%d", &p[i]); sh[i] = i; } sort(sh + 1, sh + n + 1, cmp); for (i = 2; i <= n; i++) if (s[sh[i - 1]] == 'R' && s[sh[i]] == 'L') ans = min(ans, (p[sh[i]] - p[sh[i - 1]]) / 2); if (ans == oo) ans = -1; printf("%d", 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; int a[200000 + 10]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { cin >> a[i]; } int minn = INT_MAX; for (int i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { minn = min(minn, a[i + 1] - a[i]); } } if (minn == INT_MAX) cout << -1 << endl; else cout << minn / 2 << 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
def algoritmo(): n = int(input()) dir = input() pos = list(map(int, input().split(" "))) c = 1000000000 count = 0 for i in range(n-1): if dir[i]=="R" and dir[i+1]=="L": x = (pos[i+1]-pos[i])//2 count+=1 if x<c: c=x else: pass else: pass if count>=1: print(c) else: print(-1) algoritmo()
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 cev = 2000000000, n, a[200005]; char s[200005]; int main() { scanf("%d", &n); scanf("%s", s + 1); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } for (int i = 1; i <= n; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { cev = min(cev, (a[i + 1] - a[i]) / 2); } } printf("%d", cev == 2000000000 ? -1 : cev); }
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::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int i; int minn = 1000000001; int flag = 0; int a[200000]; for (i = 0; i < n; i++) { cin >> a[i]; } for (i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { minn = min(minn, (a[i + 1] - a[i]) / 2); flag = 1; } } if (flag == 1) cout << minn; 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
n = int(input()) str = input() collider = input().split(' ') min = -1 for i in range(n-1): y = int(collider[i]) z = int(collider[i + 1]) if((str[i] == "R") and (str[i+1] == "L")): if(min > -1): if((z-y)/2 < min): min = (z-y)/2 if(min == -1): min = (z-y)/2 print(int(min))
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 n; char s[200100]; int pos[200100]; int main() { scanf("%d", &n); int mn = -1; scanf("%s", s); for (int i = 0; i < n; i++) scanf("%d", &pos[i]); for (int i = 1; i < n; i++) { if (s[i - 1] == 'R' && s[i] == 'L') if (mn == -1 || mn > (pos[i] - pos[i - 1]) / 2) mn = (pos[i] - pos[i - 1]) / 2; } printf("%d\n", mn); 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,ans=input(),10**10 s=raw_input() a=map(int, raw_input().split()) for i in range(n-1): if s[i:i+2] == "RL": ans = min(ans, (a[i+1] - a[i]) / 2) print ans if ans < 10**10 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; char dir[200005]; int a[200005]; int main() { int len, le, ri, minn, tmp; bool flag = 0; minn = 1000000000; scanf("%d", &len); scanf("%s", dir); le = 0; ri = len - 1; while (le <= ri) { if (dir[le] == 'L') le++; else break; } while (le <= ri) { if (dir[ri] == 'R') ri--; else break; } for (int i = 0; i < len; i++) scanf("%d", &a[i]); for (int i = le; i < ri; i++) { if (dir[i] == 'R' && dir[i + 1] == 'L') { flag = 1; tmp = a[i + 1] - a[i]; if (tmp < minn) { minn = tmp; } } } if (flag) printf("%d\n", minn / 2); 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
n = int(raw_input().strip()) di = raw_input().strip() pos = [int(x) for x in raw_input().strip().split()] ans = 1e12 for i in range(n-1): if (di[i] == 'R' and di[i+1] == 'L'): ans = min(ans, (pos[i+1]-pos[i])/2) if ans == 1e12: 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; map<long long, long long> mp; int main() { int n; cin >> n; long long a[n], i, mn = 10000000000; char c[n + 1]; cin >> c; for (i = 0; i < n; i++) cin >> a[i]; for (i = 1; i < n; i++) { if (c[i] == 'L' && c[i - 1] == 'R') { mn = min(mn, a[i] - a[i - 1]); } } if (mn == 10000000000) { cout << "-1"; return 0; } cout << mn / 2; 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.*; import java.io.*; public class Solution699A { private static FastScanner in; private static PrintWriter out; public static void main(String[] args) { in = new FastScanner(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(System.out); new Solution().solve(); out.close(); } private static class Solution { public void solve() { int n = in.nextInt(); int minDistance = Integer.MAX_VALUE; int[] directions = new int[n]; String d = in.next(); for (int i = 0, pre = 0; i < n; i++) { int loc = in.nextInt(); if (i > 0 && d.charAt(i-1) == 'R' && d.charAt(i) == 'L') { minDistance = Math.min(loc - pre, minDistance); } pre = loc; } out.println(minDistance == Integer.MAX_VALUE ? -1 : (int) Math.ceil((double)minDistance / 2.0)); } } private static class FastScanner { private BufferedReader br; private StringTokenizer st; public FastScanner(BufferedReader br) { this.br = br; } private String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch(IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; 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 */ 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 word = in.next(); int A[] = new int[N]; for (int i = 0; i < N; i++) A[i] = in.nextInt(); int ans = Integer.MAX_VALUE; for (int i = 1; i < N; i++) { if (word.charAt(i) == 'L' && word.charAt(i - 1) == 'R') { ans = Math.min(ans, (A[i] - A[i - 1]) / 2); } } out.println(ans == Integer.MAX_VALUE ? -1 : ans); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
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 sys import math import bisect import itertools import random import re def solve(A, B): n = len(A) min_val = 10 ** 18 for i in range(1, n): if A[i-1] == 'R' and A[i] == 'L': val = (B[i] - B[i-1]) // 2 min_val = min(min_val, val) if min_val == 10 ** 18: return -1 return min_val def main(): n = int(input()) A = list(input()) B = list(map(int, input().split())) print(solve(A, B)) 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=input() d=raw_input() p=map(int,raw_input().split()) mini=float('inf') for i in range(len(p)-1): j=i+1 if d[i]=='R' and d[j]=='L': if p[j]-p[i]<mini: mini=p[j]-p[i] print mini//2 if mini !=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
c,k,n,a,l=-1,[],int(input()),input(),list(map(int,input().split())) for i in range(n): if a[i]=="R":c=i else: if c>=0:k.append((l[i]-l[c])//2) if len(k)==0:print(-1) else:print(min(k))
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 Test{ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String arr = in.next(); int coor[] = new int[n]; for(int i=0; i<n; i++) { coor[i] = in.nextInt(); } int temp = 0; int count = Integer.MAX_VALUE; for(int i=0; i<n-1; i++) { char a1 = arr.charAt(i); char a2 = arr.charAt(i+1); temp = 0; if( a1=='R' && a2=='L') { int n1 = coor[i]; int n2 = coor[i+1]; while(n1!=n2) { n1++; n2--; temp++; } if(temp<count) count = temp; } } if(count==Integer.MAX_VALUE) System.out.println("-1"); else System.out.println(count); } }
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())) ans =[l[i+1]-l[i] for i in range(n-1) if s[i+1] == 'L' and s[i] == 'R'] if ans: print((min(ans) // 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
n = int(input()) s = input() x = list(map(int, input().split())) t = [] flag = False for i in range(len(s)-1): if s[i]=='R' and s[i+1]=='L': t.append(i) flag = True if flag==False: print(-1) else: a = [] for i in t: a.append(x[i+1] - x[i]) print(min(a)//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()) mov = raw_input() pos = map(int, raw_input().split()) r = -1 for i in range(1, len(pos)): if mov[i-1] == mov[i]: continue else: if mov[i-1] == 'R' and mov[i] == 'L': if r == -1: r = pos[i] - pos[i - 1] r = min(r, (pos[i] - pos[i-1])/2) print r
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 sample{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); if(!s.contains("RL")){ System.out.println(-1); } else{ int min = Integer.MAX_VALUE; int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = sc.nextInt(); for(int i = s.indexOf("RL"); i <= s.lastIndexOf("RL"); i++){ if(s.charAt(i) == 'R' && s.charAt(i+1) == 'L'){ min = Math.min(arr[i+1]-arr[i],min); } } System.out.println(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
def main(): n = input() s = input() L = [int(x) for x in input().split()] print(solver(s, L)) def solver(s, L): minimum = -1 for i in range(len(s) - 1): if s[i: i + 2] == "RL": cur = (L[i + 1] - L[i]) // 2 if minimum == -1 or cur < minimum: minimum = cur return minimum # print(solver("RLRL", [2, 4, 6, 10])) # print(solver("LLR", [40, 50, 60])) 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
#include <bits/stdc++.h> using namespace std; string str; int main() { int n, arr[200001]; cin >> n; cin >> str; for (int i = 0; i < n; i++) { cin >> arr[i]; } int ans, min = 1000000007; for (int i = 0; i < n - 1; i++) { if (str[i] == 'R' && str[i + 1] == 'L') { ans = arr[i + 1] - (arr[i + 1] + arr[i]) / 2; if (min > ans) min = ans; } } if (min == 1000000007) { cout << -1 << endl; } else cout << min << 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.*; public class Solution699A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String s = sc.nextLine().trim(); int x1, x2, t = -1; x2 = sc.nextInt(); for (int i = 1; i < n; i++) { x1 = x2; x2 = sc.nextInt(); if (s.charAt(i - 1) == 'R' && s.charAt(i) == 'L') if (t == -1 || (x2 - x1)/2 < t) t = (x2 - x1)/2; } System.out.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
n = input() s = raw_input() arr = map(int, raw_input().split()) ans = 9999999999 i = 1 while i<n: if (s[i]=='L' and s[i-1]=='R') : k = abs(arr[i]-arr[i-1]) if ans>k: ans = k i+=1 #print ans/2 if ans == 9999999999: 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
""" author - Sayan Bose date - 29.01.2020 Brooklyn 99 is love! """ n = int(input()) s = input() li = list(map(int, input().split())) res = [] for i in range(n): if s[i] == 'R': try: if s[i+1] == 'L': res.append((li[i+1]-li[i])//2) except IndexError: continue print(min(res)) if res 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=input() st = raw_input(); arr = map(int,raw_input().split()) l1 = [arr[i+1]-arr[i] for i in xrange(0,n-1) if st[i+1]=='L' and st[i]=='R' ] if len(l1)==0: print -1 else: print min(l1)/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
#include <bits/stdc++.h> using namespace std; struct my { char ch; long long v; }; my ar[200010]; long long br[200010]; int main() { long long n; while (~scanf("%lld", &n)) { getchar(); long long i = 0, j = 0, x; char dir; for (j = 1; j <= n; j++) { scanf("%c", &dir); i++; ar[i].ch = dir; } i = 0; for (j = 1; j <= n; j++) { scanf("%lld", &x); i++; ar[i].v = x; } long long k = 1, cnt = 2147483647; for (i = 1; i <= n - 1; i++) { if (ar[i].ch == 'R' and ar[i + 1].ch == 'L') { cnt = min(cnt, (abs(ar[i].v - ar[i + 1].v)) / 2); } } if (cnt == 2147483647) { cnt = -1; } printf("%lld\n", cnt); } 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()) s = list(input()) x = input().split() min = -1 for i in range(n): x[i] = int(x[i]) for i in range(n-1): if(s[i]=='R' and s[i+1] == 'L'): m = int((x[i+1]-x[i])/2) if(min == -1 or m<min): min=m print(min)
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.Arrays; import java.util.Scanner; public class tmp { public static void main(String[] Args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); long ans = (long) 2e18; int last = -1; for (int i = 0; i < n; i++) { int cur = sc.nextInt(); if (i != 0 && s.charAt(i) == 'L' && s.charAt(i - 1) == 'R' && ans > (cur - last) / 2) ans = (cur - last) / 2; last = cur; } if (ans > 1e10) System.out.println(-1); else 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
raw_input() dirs = raw_input() nums = map(int, raw_input().split()) dist = 10e10 start = dist for i in range(len(nums)-1): if dirs[i] == 'R': if dirs[i+1] == 'L': dist = min(dist, nums[i+1]-nums[i]) if dist == start: print -1 else: print dist/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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; public class codeforces { public static void main(String[] args) throws IOException { PrintWriter out=new PrintWriter(System.out); FastReader read=new FastReader(); int n=read.nextInt(); String str=read.next(); int arr[]=new int[n]; int res=0; List<Integer> l=new ArrayList(); for(int i=0;i<n;i++) arr[i]=read.nextInt(); for(int j=0;j<n-1;j++) { if(str.charAt(j)=='R'&&str.charAt(j+1)=='L') { res=(arr[j+1]-arr[j])/2; l.add(res); } } Collections.sort(l); if(l.size()>0) System.out.println(l.get(0)); else System.out.println(-1); } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br=new BufferedReader(new InputStreamReader(System.in)); } public String next() { while(st==null||!st.hasMoreElements()) { try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } public float nextFloat() { return Float.parseFloat(next()); } public String nextLine() { String str=""; try { str=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
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* numbers = new int[n]; for (int i = 0; i < n; i++) { cin >> numbers[i]; } int min_time = -1; for (int i = 0; i < n; i++) { if (s[i] == 'R') { int j = i + 1; if (j < n && s[j] == 'L') { int time = (numbers[j] - numbers[i]) / 2; if (min_time == -1 || time < min_time) { min_time = time; } } } } cout << min_time; 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 inf = 1e6 + 7, Inf = 1e9 + 7; int n, m, k = Inf, x, l, r, f, a[inf], b[inf], c[inf], d[inf]; map<int, int> p[inf]; vector<int> v; string s; int main() { cin >> n >> s; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 1; i < n; ++i) if (s[i] == 'L' && s[i - 1] == 'R') k = min(k, (a[i] - a[i - 1]) / 2); if (k == Inf) cout << -1; else cout << k; }
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 = 0, s = 1e9; cin >> n; char a[n]; int b[n]; cin >> a; for (int j = 0; j < n; j++) { cin >> b[j]; if (j > 0) { if (a[j - 1] == 'R' && a[j] == 'L') s = min(s, (b[j] - b[j - 1]) / 2); } } cout << ((s == 1e9) ? -1 : s); 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 n; int a[200001]; int dir[200001]; string s; int main() { cin >> n; cin >> s; for (int i = (0); i < (n); ++i) dir[i] = (s[i] == 'R'); for (int i = (0); i < (n); ++i) cin >> a[i]; int res = -1; for (int i = (0); i < (n - 1); ++i) { if ((dir[i] ^ dir[i + 1]) && dir[i]) { int curr = (a[i + 1] - a[i]) / 2; if (res == -1 || res > curr) { res = curr; } } } cout << res << 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
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner s= new Scanner(System.in); int n= s.nextInt(); s.nextLine(); int arr[]= new int[n]; String str = s.nextLine(); for(int i=0;i<n;i++){ arr[i]= s.nextInt(); } int ans=0, max = Integer.MAX_VALUE, flag=0; for(int i=0;i<n-1;i++){ if(str.charAt(i)=='R' && str.charAt(i+1)=='L'){ ans = arr[i+1] - arr[i]; if(ans < max) { max= ans; flag=1; } } } if(flag==1) System.out.println(max/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=int(input()) l1=list(input()) l2=list(map(int,input().split())) ans=[];k=0 for i in range(n-1): if l1[i]=="R" and l1[i+1]=="L": k=1 break if k==0: print(-1) else: for i in range(n-1): if l1[i]=="R" and l1[i+1]=="L": ans.append((l2[i+1]-l2[i])//2) print(min(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 Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); char[] s = input.next().toCharArray(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = input.nextInt(); } int min = Integer.MAX_VALUE; for (int i = 1; i < n; i++) { if (s[i-1] == 'R' && s[i] == 'L'){ int time = arr[i] - arr[i-1]; time /= 2; min = Math.min(min, time); } } if (min == Integer.MAX_VALUE) min = -1; 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; struct dbg_ { template <typename T> dbg_& operator,(const T& x) { cerr << x << ' '; return *this; } } dbg_t; struct cin_ { template <typename T> cin_& operator,(T& x) { cin >> x; return *this; } } cin_; template <typename T1, typename T2> static inline ostream& operator<<(ostream& os, std::pair<T1, T2> const& p) { os << "{" << p.first << ", " << p.second << "}"; return os; } int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int main() { int n; { cin_, n; }; cin.ignore(); string str; getline(cin, str); char prev = 'L'; int prevx, ret = 2000000007; for (int i = 0, _i = (n); i < _i; ++i) { int first; { cin_, first; }; if (prev == 'R' && str[i] == 'L') (ret) = min((ret), ((first - prevx) / 2)); prev = str[i]; prevx = first; } cout << ((ret == 2000000007) ? -1 : ret) << 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 = input() directions = raw_input() coords = raw_input().split() min_distance = -1 for i in xrange(n-1): cur_dir = directions[i] cur_coord = int(coords[i]) next_dir = directions[i+1] next_coord = int(coords[i+1]) if cur_dir == next_dir: continue elif cur_dir == 'L' and next_dir == 'R': continue cur_dist = (next_coord - cur_coord) / 2 if cur_dist < min_distance or min_distance == -1: min_distance = cur_dist print min_distance
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(void) { int n; cin >> n; string s; cin >> s; vector<long> pos; for (int i = 0; i < n; i++) { long tmp; cin >> tmp; pos.push_back(tmp); } long min_val = pos[n - 1]; bool is_answer = false; for (int i = 0; i < n - 1; i++) { if (!(s[i] == 'R' && s[i + 1] == 'L')) continue; long diff = pos[i + 1] - pos[i]; long new_speed = diff / 2; if (min_val > new_speed) { is_answer = true; min_val = new_speed; } } if (is_answer) cout << min_val; else cout << -1; cout << 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
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } bool ok = false; int ans = 1e9; for (int i = 0; i < n;) { if (s[i] == 'R' && s[i + 1] == 'L') { ok = true; ans = min(ans, (v[i + 1] - v[i]) / 2); i = i + 2; } else i++; } if (!ok) { cout << "-1\n"; } 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; long long int arr[200005]; int main() { long long int n, i, c, d, ans, mx, mn, k; string s; cin >> n; cin >> s; for (i = 0; i < n; i++) cin >> arr[i]; int f = 0; k = 0; mn = INT_MAX; for (i = 0; s[i]; i++) { if (s[i] == 'R') { f = 1; c = arr[i]; } if (s[i] == 'L' && f == 1) { k = 1; d = arr[i]; ans = (d - c) / 2; if (mn > ans) { mn = ans; } } } if (k == 0) { cout << "-1\n"; } else { cout << mn << 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()) s = input() x = list(map(int, input().split())) ans = 1000000001 r = s.find('R') l = s.find('L') if r!=-1 and l != -1: for i in range(0, n): if s[i] == 'R': r = i if s[i] == 'L': l = i if r < l: ans = min(ans, (x[l] - x[r])//2) if ans == 1000000001: ans = -1 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
#include <bits/stdc++.h> int main() { long n, x[200001], i, min = 1111111111, temp; char s[200001]; scanf("%d %s", &n, s); for (i = 0; i < n; i++) scanf("%d", x + i); for (i = 0; i < n; i++) { if (s[i] == 'R' && s[i + 1] == 'L') { temp = (x[i + 1] - x[i]) / 2; if (min > temp) min = temp; } } printf("%d", min == 1111111111 ? -1 : 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
import math n=int(input()) a=input() b=list(map(int,input().split())) t=10**10 flag=0 for i in range(n-1): if(a[i]=="R" and a[i+1]=="L"): c=(b[i+1]-b[i])/2 t=min(t,math.ceil(c)) flag=1 if(flag==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
import java.io.BufferedInputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.Scanner; import java.util.Stack; import java.util.List; public class Main { private static Scanner input=new Scanner(System.in); public static void main(String []args){ //test1(); //test2(); CF19A a=new CF19A(); a.solve(); } } class POJ1979{ private String []map; private int [][]visit; private Scanner input=new Scanner(new BufferedInputStream(System.in)); private int w,h; private int ans; public void solve(){ while(input.hasNext()){ w=input.nextInt(); h=input.nextInt(); input.nextLine(); if(w==0&&h==0)break; initMap(); getAns(); System.out.println(ans); } } private void initMap(){ map=new String[h]; visit=new int[h][w]; for(int i=0;i<h;i++){ map[i]=input.next(); Arrays.fill(visit[i],0); } ans=0; } private void getAns(){ int i=0,j=0; boolean ff=false; for(i=0;i<h;i++){ for(j=0;j<w;j++){ if(map[i].charAt(j)=='@'){ ff=true; break; } } if(ff)break; } find(i,j); } private void find(int i,int j){ if(i<0||i>=h||j<0||j>=w)return; if(visit[i][j]==1)return; if(map[i].charAt(j)=='#')return; visit[i][j]=1; ans++; find(i-1,j); find(i+1,j); find(i,j-1); find(i,j+1); } } class POJ3009{ private int[][]m; private Scanner input=new Scanner(new BufferedInputStream(System.in)); private int h,w; private int ans; private int starti,startj,endi,endj; public void solve(){ while(input.hasNext()){ w=input.nextInt(); h=input.nextInt(); if(w==0&&h==0)break; init(); getAns(); if(ans>10)ans=-1; System.out.println(ans); } } private void init(){ m=new int[h][w]; ans=100; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ m[i][j]=input.nextInt(); if(m[i][j]==2){ starti=i; startj=j; } if(m[i][j]==3){ endi=i; endj=j; } } } } private void getAns(){ find(starti,startj,0); } private void find(int i,int j,int step){ if(i<0||i>=h||j<0||j>=w)return; if((i==endi&&j==endj)||step>10){ ans=Math.min(ans, step); return; } for(int dir=1;dir<=4;dir++){ if(dir==1){ boolean ok=false; int ti=i; while(ti-1>=0&&m[ti-1][j]!=1){ if(ti-1==endi&&j==endj){ find(ti-1,j,step+1); ok=false; break; } else{ ti--; ok=true; } } if(ok&&ti-1>=0){ m[ti-1][j]=0; find(ti,j,step+1); m[ti-1][j]=1; } } if(dir==2){ boolean ok=false; int tj=j; while(tj+1<w&&m[i][tj+1]!=1){ if(tj+1==endj&&i==endi){ find(i,tj+1,step+1); ok=false; break; } else { tj++; ok=true; } } if(ok&&tj+1<w){ m[i][tj+1]=0; find(i,tj,step+1); m[i][tj+1]=1; } } if(dir==3){ boolean ok=false; int ti=i; while(ti+1<h&&m[ti+1][j]!=1){ if(ti+1==endi&&j==endj){ find(ti+1,j,step+1); ok=false; break; } else { ok=true; ti++; } } if(ok&&ti+1<h){ m[ti+1][j]=0; find(ti,j,step+1); m[ti+1][j]=1; } } if(dir==4){ boolean ok=false; int tj=j; while(tj-1>=0&&m[i][tj-1]!=1){ if(tj-1==endj&&i==endi){ find(i,tj-1,step+1); ok=false; break; } else { tj--; ok=true; } } if(ok&&tj-1>=0){ m[i][tj-1]=0; find(i,tj,step+1); m[i][tj-1]=1; } } } } } class POJ3669{ private int [][]m=new int[305][305]; private int n; private Scanner input=new Scanner(new BufferedInputStream(System.in)); private ArrayList<Two>in; private class Two{ int x,y; } public void solve(){ while(input.hasNext()){ n=input.nextInt(); init(); bfs(0,0,0); } } private void init(){ } private void bfs(int i,int j,int time){ } } class RMQ{ public long mark; public long value; public int start,end; } class POJ3468{ private Scanner input=new Scanner(new BufferedInputStream(System.in)); private int n,q; private RMQ []a; public void solve(){ while(input.hasNext()){ n=input.nextInt(); q=input.nextInt(); input.nextLine(); init(); build(1,n,1); operator(q); } } private void init(){ int max=n*4+5; a=new RMQ[max]; for(int i=0;i<max;i++){ a[i]=new RMQ(); a[i].mark=0; a[i].value=0; a[i].start=0; a[i].end=0; } } private void build(int start,int end,int index){ if(start==end){ a[index].value=input.nextInt(); a[index].start=a[index].end=start; return; } int mid=(start+end)/2; build(start,mid,index*2); build(mid+1,end,index*2+1); a[index].value=a[index*2].value+a[index*2+1].value; a[index].start=a[index*2].start; a[index].end=a[index*2+1].end; } private void operator(int times){ String s=null; int a,b; long v; while(times-->0){ s=input.next(); if(s.equals("Q")){ a=input.nextInt(); b=input.nextInt(); System.out.println(query(a,b,1,n,1)); } else if(s.equals("C")){ a=input.nextInt(); b=input.nextInt(); v=input.nextLong(); update(a,b,v,1,n,1); } } } private long query(int qStart,int qEnd,int start,int end,int index){ if(qStart==start&&qEnd==end)return a[index].value; putDown(index); int mid=(start+end)/2; if(qEnd<=mid)return query(qStart,qEnd,start,mid,index*2); if(qStart>mid)return query(qStart,qEnd,mid+1,end,index*2+1); return query(qStart,mid,start,mid,index*2)+query(mid+1,qEnd,mid+1,end,index*2+1); } private void update(int uStart,int uEnd,long value,int start,int end,int index){ if(uStart==start&&uEnd==end){ a[index].value+=(end-start+1)*value; a[index].mark+=value; return; } putDown(index); int mid=(start+end)/2; if(uEnd<=mid){ update(uStart,uEnd,value,start,mid,index*2); return; } if(uStart>mid){ update(uStart,uEnd,value,mid+1,end,index*2+1); return; } update(uStart,mid,value,start,mid,index*2); update(mid+1,uEnd,value,mid+1,end,index*2+1); a[index].value=a[index*2].value+a[index*2+1].value; } private void putDown(int index){ if(a[index].mark>0){ a[index*2].mark+=a[index].mark; a[index*2].value+=(a[index*2].end-a[index*2].start+1)*a[index].mark; a[index*2+1].mark+=a[index].mark; a[index*2+1].value+=(a[index*2+1].end-a[index*2+1].start+1)*a[index].mark; a[index].mark=0; } } } class Shu{ private Scanner input=new Scanner(new BufferedInputStream(System.in)); private int n,q; private String []color; private int []a; public void solve(){ while(input.hasNext()){ n=input.nextInt(); q=input.nextInt(); init(); while(q-->0){ int index=input.nextInt(); String tc=input.nextLine(); add(index,tc); System.out.println(query(n)); } } } private void init(){ color=new String[n+1]; a=new int [n+1]; Arrays.fill(a, 0); Arrays.fill(color, "0 0 0"); int i=1; while(i<=n){ a[i]+=1; i+=i&-i; } } private void add(int i,String col){ while(i<=n){ int count=0; if(!col.equals(color[i]))count=1; else count=-1; a[i]+=count; color[i]=col; i+=i&-i; } } private int query(int i){ int ans=0; while(i>0){ ans+=a[i]; i-=i&-i; } return ans; } } class Shu2{ private Scanner input=new Scanner(new BufferedInputStream(System.in)); private int n,q; public void solve(){ HashMap<Integer,String>index=new HashMap<Integer,String>(); HashMap<String,Integer>colors=new HashMap<String,Integer>(); while(input.hasNext()){ n=input.nextInt(); q=input.nextInt(); index.clear(); colors.clear(); colors.put(" 0 0 0", n); int ans=1; while(q-->0){ int tn=input.nextInt(); String co=input.nextLine(); if(!index.containsKey(tn)){ if(!colors.containsKey(co)){ ans++; colors.put(co, 1); } } else { if(!colors.containsKey(co)){ colors.put(co,1); ans++; } else { int value=colors.get(co); value--; if(value==0){ ans--; colors.remove(co); } else colors.put(co, value); } } index.put(tn,co); System.out.println(ans); } } } } class BIT{ private Scanner input=new Scanner(new BufferedInputStream(System.in)); private final int max=100000+1; private int n,q; private long []bit0=new long[max]; private long []bit1=new long[max]; public void solve(){ while(input.hasNext()){ Arrays.fill(bit0, 0); Arrays.fill(bit1, 0); n=input.nextInt(); q=input.nextInt(); for(int i=1;i<=n;i++){ add(bit0,i,input.nextInt()); } while(q-->0){ String op=input.next(); if(op.equals("C")){ int a=input.nextInt(); int b=input.nextInt(); int v=input.nextInt(); add(bit0,a,-v*(a-1)); add(bit1,a,v); add(bit0,b+1,v*b); add(bit1,b+1,-v); } else{ int a=input.nextInt(); int b=input.nextInt(); long ans=0; ans+=sum(bit0,b)+sum(bit1,b)*b; ans-=sum(bit0,a-1)+sum(bit1,a-1)*(a-1); System.out.println(ans); } } } } private void add(long[]b,int i,int v){ while(i<=n){ b[i]+=v; i+=i&-i; } } private long sum(long[]b,int i){ long ans=0; while(i>0){ ans+=b[i]; i-=i&-i; } return ans; } } class MPS{ private int n; private int[]a=new int [100]; Scanner input=new Scanner(new BufferedInputStream(System.in)); public void solve(){ while(input.hasNext()){ n=input.nextInt(); int ans=0; Arrays.fill(a, 0); for(int i=0;i<n;i++){ int t=input.nextInt(); ans+=i-sum(t); add(t,1); } System.out.println(ans); } } private int sum(int i){ int ans=0; while(i>0){ ans+=a[i]; i-=i&-i; } return ans; } private void add(int i,int v){ while(i<=n){ a[i]+=v; i+=i&-i; } } } class MS{ private int []all; private int []a; private int max; private Scanner input=new Scanner(new BufferedInputStream(System.in)); public void solve(){ int t=input.nextInt(); int n,m; while(t-->0){ n=input.nextInt(); a=new int[n+1]; for(int i=1;i<=n;i++)a[i]=input.nextInt(); max=(int)Math.pow(2,(int)Math.ceil(Math.log(n)/Math.log(2))+1); all=new int[max]; build(1,n,1); m=input.nextInt(); while(m-->0){ int left=input.nextInt(); int right=input.nextInt(); System.out.println(query(left,right,1,1,n)); } } } private int gcd(int a,int b){ if(b==0)return a; else return gcd(b,a%b); } private int query(int left,int right,int start,int l,int r){ int mid=(l+r)/2; if(left==l&&right==r)return all[start]; if(right<=mid)return query(left,right,start*2,l,mid); if(left>mid)return query(left,right,start*2+1,mid+1,r); return gcd(query(left,mid,start*2,l,mid), query(mid+1,right,start*2+1,mid+1,r)); } private void build(int left,int right,int index){ int mid=(left+right)/2; if(left==right){ all[index]=a[left]; return; } build(left,mid,index*2); build(mid+1,right,index*2+1); all[index]=gcd(all[index*2], all[index*2+1]); } } class CF19A{ private Scanner input=new Scanner(System.in); public void solve(){ int n; while(input.hasNext()){ n=input.nextInt(); input.nextLine(); String s=input.next(); int []a=new int[n+1]; for(int i=0;i<n;i++){ a[i]=input.nextInt(); } int t=1000000000; int ans=t; for(int i=0;i<s.length()-1;i++){ if(s.charAt(i)=='R'&&s.charAt(i+1)=='L'){ ans=Math.min(ans,(a[i+1]-a[i])/2); } } if(ans!=t)System.out.println(ans); 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
# print ("Input n") n = int(input()) # print ("Input the string of Ls and Rs") st = input() # print ("Input the starting positions, all on one line") a = list(int(x) for x in input().split()) collide = False smallesttime = None for i in range(0, len(a)-1): if st[i] == "R" and st[i+1] == "L": time = (a[i+1] - a[i])//2 if collide == False: collide = True smallesttime = time else: if time < smallesttime: smallesttime = time if not collide: print (-1) else: print (smallesttime)
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 eps = 1000000007; int inf = -1000000007; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<char> A(n); vector<int> B(n); for (int i = 0; i < n; i++) { cin >> A[i]; } for (int i = 0; i < n; i++) { cin >> B[i]; } int min1 = eps; for (int i = 0; i < n - 1; i++) { if (A[i] == 'R' && A[i + 1] == 'L') { min1 = min((B[i + 1] - B[i]) / 2, min1); } } if (min1 != eps) { cout << min1; } 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; int i, n, r = 2e9, a[200005]; char s[200005]; int main() { scanf("%d%s", &n, s + 1); for (i = 1; i <= n; i++) scanf("%d", a + i); for (i = 1; i < n; i++) if (s[i] == 'R' && s[i + 1] == 'L') r = min(r, a[i + 1] - a[i]); printf("%d", r < 2e9 ? r / 2 : -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() { long int n; cin >> n; string s; cin >> s; long long int dha[n]; for (long long int a = 0; a < n; a++) { cin >> dha[a]; } long long int time = pow(10, 10); for (long long int a = 0; a < n - 1; a++) { if (s.at(a) == 'R' && s.at(a + 1) == 'L') { long long int x = ((dha[a + 1] - dha[a]) / 2); if (x < time) { time = x; } } } if (time == pow(10, 10)) { cout << -1; } else { cout << time; } }
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(NULL), cout.tie(NULL); long long n, arr[300000], x, l = -1, ans = 10000000000, flag = 0; string s; cin >> n >> s; for (int i = 0; i < n; i++) { cin >> arr[i]; if (s[i] == 'R') l = arr[i]; else { if (l != -1) { flag = 1; if ((arr[i] - l) % 2 == 0) ans = min((arr[i] - l) / 2, ans); else ans = min((arr[i] - l) / 2 + 1, ans); } } } if (!flag) puts("-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; vector<int> part; string s; int k, n; int main() { cin >> n; cin >> s; for (int i = 1; i <= n; i++) { cin >> k; part.push_back(k); } int ans = -1; for (int i = 1; i < n; i++) if (s[i - 1] == 'R' && s[i] == 'L') if ((part[i] - part[i - 1]) / 2 < ans || ans == -1) ans = (part[i] - part[i - 1]) / 2; 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
n = int(input()) d = list(input()) k = [] m = 1000000001 k = [int(i) for i in input().split()] for i in range(n-1): if d[i] == 'R' and d[i+1] == 'L': if abs((k[i] - k[i+1])//2) < m: m = abs((k[i] - k[i+1])//2) if m == 1000000001: print(-1) else: print(m)
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 = int(2e6) + 256; const int INF = int(1e9); const int mod = (int)(1e9) + 7; const double pi = 3.1415926535897932384626433832795; long long n, m, t, ans = INF, a[MaxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; string second; cin >> second; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 1; i < n; i++) { if (second[i - 1] == 'R' && second[i] == 'L') { ans = min(ans, (a[i] - a[i - 1]) / 2); } } if (ans != INF) cout << ans; 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 sys, math n=int(input()) s=input() z=list(map(int,input().split())) best = 10**9 for i in range(len(s)-1): if s[i]=='R' and s[i+1]=='L': best=min(best, z[i+1]-(z[i]+z[i+1])//2) if best != 10**9: print(best) 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 LaunchOfCollider { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); String symbols = sc.nextLine(); if(symbols.indexOf("RL") == -1) { sc.close(); System.out.print("-1"); return ; } int[] a = new int[n]; int index = 0; while(sc.hasNextInt()) { a[index] = sc.nextInt(); index++; } sc.close(); int min = 0; boolean isFirst = true; for(int i = 0; i < n - 1; i++) { int j = symbols.substring(i).indexOf("RL"); if(j != -1) { int dif = a[j + i + 1] - a[j + i]; if(isFirst) { min = dif; isFirst = false; } else { min = dif < min ? dif : min; } i += j + 1; } else { break ; } } 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
n = int(raw_input()) ds = list(raw_input()) cors = map(int, raw_input().split()) res = 10**20 for _t in range(1, n): # judge cors[_t - 1] & cors[_t] if ds[_t - 1] == 'R' and ds[_t] == 'L': res = min(res, abs(cors[_t - 1] - cors[_t])/2) if res == 10**20: print -1 else: print res
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> const long long inf = 1e10; const int maxn = 200000 + 10; struct NN { int d; int x; } node[maxn]; int main() { char a; int n; while (std::cin >> n) { for (int i = 0; i < n; i++) { std::cin >> a; if (a == 'R') node[i].d = 1; else node[i].d = 0; } for (int i = 0; i < n; i++) { std::cin >> node[i].x; } long long minn = inf; for (int i = 0; i < n - 1; i++) { if (node[i].d == 1 && node[i + 1].d == 0) { if (node[i + 1].x - node[i].x < minn) minn = node[i + 1].x - node[i].x; } } if (minn == inf) std::cout << -1 << std::endl; else std::cout << minn / 2 << std::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(raw_input()) directions = raw_input().strip() positions = list(map(int, raw_input().split())) result = -1 for i in range(1, n): if directions[i - 1] == 'R' and directions[i] == 'L': t = (positions[i] - positions[i - 1]) // 2 if result == -1 or t < result: result = t print(result)
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()) d = list(input()) p = list(map(int, input().split())) output = -1 for i in range(1, n): if d[i - 1] == 'R' and d[i] == 'L': if output > 0: output = min(output, (p[i] - p[i - 1]) / 2) else: output = (p[i] - p[i - 1]) / 2 print(int(output))
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()) directions = input().strip() positions = list(map(int, input().split())) last_right_going = None min_t = None for position, direction in zip(positions, directions): if direction == 'L': if last_right_going is not None: time = (position - last_right_going) // 2 if min_t is None: min_t = time else: min_t = min(time, min_t) else: last_right_going = position print(min_t if min_t is not None 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 = 200010; char mov[maxn]; int n, x[maxn], dis[maxn]; int ans = 0x7fffffff; void init() { cin >> n; cin >> (mov + 1); memset(dis, -1, sizeof(dis)); for (int i = 1; i <= n; i++) cin >> x[i]; } int firstfind() { for (int i = 1; i <= n; i++) if (mov[i] == 'R') return i; return -1; } void work() { int last = -1; for (int i = 1; i <= n; i++) if (mov[i] == 'R' && mov[i + 1] == 'L') ans = min(ans, (x[i + 1] - x[i]) / 2); } void print() { if (ans == 0x7fffffff) ans = -1; cout << ans << endl; } int main() { init(); work(); print(); 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 a[200001]; int main() { int n; cin >> n; string s; cin >> s; s = '*' + s; for (int i = 1; i <= n; i++) { cin >> a[i]; } int mins = 1e9; for (int i = 1; i < n; i++) if (s[i] == 'R') if (s[i + 1] == 'L') { mins = min(mins, (a[i + 1] - a[i]) / 2); } if (mins != 1e9) { cout << mins; } else { cout << -1; } return 0; }
CPP