exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k ⌀ | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k ⌀ | difficulty int64 -1 3.5k ⌀ | prob_desc_output_spec stringlengths 17 1.47k ⌀ | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 539b2e08dd64246a04389b324dbbc975 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class Solution
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(--t>=0)
{
int k=0;
Map<Character,Integer> p=new HashMap<>();
int a=sc.nextInt();
int b=sc.nextInt();
sc.nextLine();
String s=sc.nextLine();
for(char c:s.toCharArray())
{
if(p.containsKey(c))
p.put(c,p.get(c)+1);
else
p.put(c,1);
}
if(a>0&&p.containsKey('R'))
{
if(p.get('R')>=a)
k++;
}
if(b>0&&p.containsKey('U'))
{
if(p.get('U')>=b)
k++;
}
if(a<0&&p.containsKey('L'))
{
if(p.get('L')>=Math.abs(a))
k++;
}
if(b<0&&p.containsKey('D'))
{
if(p.get('D')>=Math.abs(b))
k++;
}
if(a==0)
k++;
if(b==0)
k++;
if(k==2)
System.out.println("yes");
else
System.out.println("no");
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 8eb73cd7829aa7545d316d63d562929d | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.io.*;
public class Planet
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0)
{
String[] line1 = br.readLine().split(" ");
int px = Integer.parseInt(line1[0]);
int py = Integer.parseInt(line1[1]);
String line2 = br.readLine();
HashMap<Character,Integer> hmap = new HashMap<Character,Integer>();
for(char ch:line2.toCharArray())
hmap.put(ch,hmap.getOrDefault(ch,0) + 1);
int count1 = 0;
int count2 = 0;
int flag = 0;
// Stored in HAshMap
if(px == 0 && py == 0 )
{
System.out.println("YES");
flag = 1;
}
else if(px >= 0 && py >= 0)
{
for(char ch:line2.toCharArray())
{
if(ch == 'R' && count1 < px)
count1++;
if(ch == 'U' && count2 < py)
count2++;
if(count1 == px && count2 == py)
{
System.out.println("YES");
flag = 1;
break;
}
}
}
else if(px >= 0 && py <= 0)
{
for(char ch:line2.toCharArray())
{
if(ch == 'R' && count1 < px)
count1++;
if(ch == 'D' && count2 > py)
count2--;
if(count1 == px && count2 == py)
{
System.out.println("YES");
flag = 1;
break;
}
}
}
else if(px <= 0 && py >= 0)
{
for(char ch:line2.toCharArray())
{
if(ch == 'L' && count1 > px)
count1--;
if(ch == 'U' && count2 < py)
count2++;
if(count1 == px && count2 == py)
{
System.out.println("YES");
flag = 1;
break;
}
}
}
else if(px <= 0 && py <= 0)
{
for(char ch:line2.toCharArray())
{
if(ch == 'L' && count1 > px)
count1--;
if(ch == 'D' && count2 > py)
count2--;
if(count1 == px && count2 == py)
{
System.out.println("YES");
flag = 1;
break;
}
}
}
if(flag == 0)
System.out.println("No");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 3b6e9ccd80e5b46fe40da9e871372d93 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.* ;
public class QuarentinePractice {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
int t = sc.nextInt() ;
while( t-- != 0) {
int px = sc.nextInt() ;
int py = sc.nextInt() ;
String s = sc.next() ;
int u = 0 ;
int d = 0 ;
int r = 0 ;
int l = 0 ;
for(int i = 0 ; i< s.length() ; i++) {
if(s.charAt(i) == 'U') u ++ ;
if(s.charAt(i) == 'D') d ++ ;
if(s.charAt(i) == 'R') r ++ ;
if(s.charAt(i) == 'L') l ++ ;
}
int ans = 0 ;
if(px == 0) ans ++ ;
if(px > 0 && r >= px) ans ++ ;
if(px < 0 && l >= -px) ans ++ ;
if(py == 0) ans ++ ;
if(py > 0 && u >= py) ans ++ ;
if(py < 0 && d >= -py) ans ++ ;
System.out.println(ans == 2 ? "YES" : "NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 05d3ac5e596e909d062bb87f4baf08d1 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
long i,t;
Scanner sc=new Scanner(System.in);
t=sc.nextLong();
for(i=1;i<=t;i++)
{ long x,y,u=0,d=0,r=0,l=0,c=0;
String s;char a;int j;
x=sc.nextLong();
y=sc.nextLong();
s=sc.next();
for(j=0;j<s.length();j++)
{a=s.charAt(j);
if(a=='U'){u++;}
if(a=='D'){d++;}
if(a=='R'){r++;}
if(a=='L'){l++;}}
if(x>=0){if(r>=x){c++;}}
if(x<0){if(l>=(-1*x)){c++;}}
if(y>=0){if(u>=y){c++;}}
if(y<0){if(d>=(-1*y)){c++;}}
if(c==2){System.out.println("YES");}
else{System.out.println("NO");}}}}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 217dd80c42f0adeabb2426abe5412fe0 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc =new FastReader();
int t=sc.nextInt();
while(t-->0)
{
int x,y;
x=sc.nextInt();
y=sc.nextInt();
char arr[] = sc.next().toCharArray();
int n=arr.length;
int l=0,r=0,u=0,d=0;
for(int i=0;i<n;i++)
{
if(arr[i]=='L')
{
l++;
}
else if(arr[i]=='R')
{
r++;
}
else if(arr[i]=='U')
{
u++;
}
else if(arr[i]=='D')
{
d++;
}
}
if(x>=0 && y>=0)
{
if(r>=x && u>=y)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
else if(x>=0 && y<0)
{
if(r>=x && d>=Math.abs(y))
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
else if(x<0 && y>=0)
{
if(l>=Math.abs(x) && u>=y)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
else if(x<0 && y<0)
{
if(l>=Math.abs(x) && d>=Math.abs(y))
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
float nextFloat()
{
return Float.parseFloat(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning
// and the end of the string
int i = 0, j = str.length() - 1;
// While there are characters to compare
while (i < j) {
// If there is a mismatch
if (str.charAt(i) != str.charAt(j))
return false;
// Increment first pointer and
// decrement the other
i++;
j--;
}
// Given string is a palindrome
return true;
}
static boolean palindrome_array(int arr[], int n)
{
// Initialise flag to zero.
int flag = 0;
// Loop till array size n/2.
for (int i = 0; i <= n / 2 && n != 0; i++) {
// Check if first and last element are different
// Then set flag to 1.
if (arr[i] != arr[n - i - 1]) {
flag = 1;
break;
}
}
// If flag is set then print Not Palindrome
// else print Palindrome.
if (flag == 1)
return false;
else
return true;
}
static boolean allElementsEqual(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
static boolean allElementsDistinct(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]!=arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
public static void reverse(int[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
int temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
static int LowerBound(int a[], int x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
static int UpperBound(int a[], int x) {// x is the key or target value
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]<=x) l=m;
else r=m;
}
return l+1;
}
static boolean isSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static boolean isReverseSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] < a[i + 1]) {
return false;
}
}
return true;
}
static int[] rearrangeEvenAndOdd(int arr[], int n)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
int[] array = list.stream().mapToInt(i->i).toArray();
return array;
}
static long[] rearrangeEvenAndOddLong(long arr[], int n)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
long[] array = list.stream().mapToLong(i->i).toArray();
return array;
}
static boolean isPrime(int n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (int i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
public static boolean is_Optimized_Prime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static boolean is_Optimized_Long_Prime(long n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (long i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static boolean isPrime_Long(long n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (long i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static int getSum(int n)
{
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcdLong(long a, long b)
{
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcdLong(a-b, b);
return gcdLong(a, b-a);
}
static void swap(int[] arr, int i, int j)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int countDigit(long n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 4371575e034312f1709d206c734e3f9b | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class VC699D2P1{
public static void main(String[] args){
FS sc = new FS();
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-->0){
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc.next();
// edge cases
// +ve X-, Y- Axes
// -ve X-, Y- Axes
int r = 0, l = 0, u = 0, d = 0;
// U, R, D, L
for(Character c : s.toCharArray()){
if(c.equals('U')) u++;
else if(c.equals('R')) r++;
else if(c.equals('D')) d++;
else l++;
}
boolean isX = false, isY = false;
if(x>=0 && x<=r) isX = true;
if(x<=0 && -x<=l) isX = true;
if(y>=0 && y<=u) isY = true;
if(y<=0 && -y<=d) isY = true;
pw.println(isX&&isY?"YES":"NO");
}
pw.flush();
pw.close();
}
static class FS{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next(){
while(!st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
} catch(Exception ignored){
}
}
return st.nextToken();
}
int[] nextArray(int n){
int[] a = new int[n];
for(int i = 0; i < n; i++){
a[i] = nextInt();
}
return a;
}
long[] nextLongArray(int n){
long[] a = new long[n];
for(int i = 0; i < n; i++){
a[i] = nextLong();
}
return a;
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 5a0d43c76686214016123eaaeb1b0243 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class SpaceNavigation
{
public static Scanner sc = new Scanner(System.in);
public static void main(String[] args)
{
int t = sc.nextInt();
while (t-- != 0)
fairnum();
}
public static void fairnum()
{
int i,u=0,d=0,r=0,l=0;
int px=sc.nextInt();
int py=sc.nextInt();
String s=sc.next();
int n=s.length();
for(i=0;i<n;i++)
{
if(s.charAt(i)=='U') u++;
else if(s.charAt(i)=='D') d++;
else if(s.charAt(i)=='R') r++;
else if(s.charAt(i)=='L') l++;
}
if(px>=0 && py>=0)
{
if(r>=px && u>=py)
System.out.println("YES");
else
System.out.println("NO");
return;
}
else if(px<=0 && py>=0)
{
if(l>=Math.abs(px) && u>=py)
System.out.println("YES");
else
System.out.println("NO");
return;
}
else if(px<=0 && py<=0)
{
if(l>=Math.abs(px) && d>=Math.abs(py))
System.out.println("YES");
else
System.out.println("NO");
return;
}
else if(px>=0 && py<=0)
{
if(r>=px && d>=Math.abs(py))
System.out.println("YES");
else
System.out.println("NO");
return;
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | e3825aaf4c61433e772bde2d4f7f6f27 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main
{
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] nextArray(int n){
int ar[] = new int[n];
for(int i=0;i<n;i++)
ar[i] = this.nextInt();
return (ar);
}
}
public static void main(String args[]){
FastReader in =new FastReader();
int no=in.nextInt();
int i,px,py,p,q;
char ch;
while(no-->0){
px=0;py=0;p=0;q=0;
int x=in.nextInt();
int y=in.nextInt();
String s=in.next();
for(i=0;i<s.length();i++)
{
ch=s.charAt(i);
if(ch=='U'&&y>0&&p==0)
py++;
else if(ch=='D'&&y<0&&p==0)
py--;
else if(ch=='R'&&x>0&&q==0)
px++;
else if(ch=='L'&&x<0&&q==0)
px--;
if(px==x)
q=1;
if(py==y)
p=1;
}
if(px==x&&py==y)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 82d7c81d0c2151d99419aa0b49f67c61 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | // package codeforce.cf699;
import java.io.PrintWriter;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
// int t = 1;
for (int i = 0; i < t; i++) {
solve(sc, pw);
}
pw.close();
}
static void solve(Scanner in, PrintWriter out){
int x = in.nextInt(), y = in.nextInt();
String s = in.next();
char[] cs = s.toCharArray();
int[] arr = new int[4];
for(char c : cs){
if (c == 'U'){
arr[0]++;
}else if (c == 'D'){
arr[1]++;
}else if (c == 'R'){
arr[2]++;
}else{//L
arr[3]++;
}
}
// System.out.println(Arrays.toString(arr));
int abx = Math.abs(x), aby = Math.abs(y);
// System.out.println(abx+" "+aby);
if (x == 0){
if (y < 0 && arr[1] >= aby){
out.println("YES");
}else if (y > 0 && arr[0] >= aby){
out.println("YES");
}else{
out.println("NO");
}
return;
}else if (y == 0){
if (x < 0 && arr[3] >= abx){
out.println("YES");
}else if (x > 0 && arr[2] >= abx){
out.println("YES");
}else{
out.println("NO");
}
return;
}
if (x < 0 && y < 0){
if (arr[3] >= abx && arr[1] >= aby){
out.println("YES");
}else{
out.println("NO");
}
}else if (x > 0 && y > 0){
if (arr[2] >= abx && arr[0] >= aby){
out.println("YES");
}else{
out.println("NO");
}
}else if (x < 0 && y > 0){
if (arr[3] >= abx && arr[0] >= aby){
out.println("YES");
}else{
out.println("NO");
}
}else{// x >= 0 && y <= 0
if (arr[2] >= abx && arr[1] >= aby){
out.println("YES");
}else{
out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | af5588eff3a165e9b7fad478af3a833d | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.lang.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t!=0)
{
int i = sc.nextInt();
int x = Math.abs(i);
int j = sc.nextInt();
int y = Math.abs(j);
String s = sc.next();
int d =0,r=0,l=0,u=0;
if(i>=0&&j>=0)
{
for(int k=0;k<s.length();++k)
{
if(s.charAt(k) == 'U')
{
u++;
}
if(s.charAt(k) == 'R')
{
r++;
}
}
// System.out.println(u+" "+r+" ");
if( u>=y&&r>=x)
System.out.println("YES");
else
System.out.println("NO");
}
else if(i<=0&&j<=0)
{
for(int k=0;k<s.length();++k)
{
if(s.charAt(k) == 'L')
{
l++;
}
if(s.charAt(k) == 'D')
{
d++;
}
}
//System.out.println(l+" "+d+" ");
if(d-y>=0&&l-x>=0)
System.out.println("YES");
else
System.out.println("NO");
}
else if(i>=0&&j<=0)
{
for(int k=0;k<s.length();++k)
{
if(s.charAt(k) == 'D')
{
d++;
}
if(s.charAt(k) == 'R')
{
r++;
}
}
//System.out.println(d +" "+ l +" ");
if(d>=y&&r>=x)
System.out.println("YES");
else
System.out.println("NO");
}
else
{
for(int k=0;k<s.length();++k)
{
if(s.charAt(k) == 'L')
{
l++;
}
if(s.charAt(k) == 'U')
{
u++;
}
}
//System.out.println(l+" "+u+" ");
if(u-y>=0&&l-x>=0)
System.out.println("YES");
else
System.out.println("NO");
}
t--;
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 1fb7bdf120a6e1e01208eda6b18f7758 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.PrintWriter;
import java.util.*;
public class TP {
public static PrintWriter out = new PrintWriter(System.out);
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int t = 1;
t = ni();
while (t-- > 0) solve();
out.flush();
}
private static void solve() {
int x = ni(), y = ni();
String s = in.next();
int[] f = new int[128];
for (char c : s.toCharArray()) {
f[c]++;
}
int[] dir = {0, 0, 0, 0};
for (int i = 0; i < s.length(); i++) {
switch (s.charAt(i)) {
case 'U':
dir[0]++;
break;
case 'R':
dir[1]++;
break;
case 'D':
dir[2]++;
break;
case 'L':
dir[3]++;
break;
}
}
boolean ok1 = (x == 0) || (x > 0 && dir[1] >= x) || (x < 0 && dir[3] >= Math.abs(x));
boolean ok2 = (y == 0) || (y > 0 && dir[0] >= y) || (y < 0 && dir[2] >= Math.abs(y));
if (ok1 && ok2) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
private static boolean invalid(int[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] < a[i + 1]) return true;
}
return false;
}
private static int ni() {
return in.nextInt();
}
private static int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private static long[] nal(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nl();
return a;
}
private static long nl() {
return in.nextLong();
}
private float nf() {
return in.nextFloat();
}
private static double nd() {
return in.nextDouble();
}
public static int[] facs(int n, int[] primes) {
int[] ret = new int[9];
int rp = 0;
for (int p : primes) {
if (p * p > n) break;
int i;
i = 0;
while (n % p == 0) {
n /= p;
i++;
}
if (i > 0) ret[rp++] = p;
}
if (n != 1) ret[rp++] = n;
return Arrays.copyOf(ret, rp);
}
public static int[] sieveEratosthenes(int n) {
if (n <= 32) {
int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
for (int i = 0; i < primes.length; i++) {
if (n < primes[i]) {
return Arrays.copyOf(primes, i);
}
}
return primes;
}
int u = n + 32;
double lu = Math.log(u);
int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];
ret[0] = 2;
int pos = 1;
int[] isnp = new int[(n + 1) / 32 / 2 + 1];
int sup = (n + 1) / 32 / 2 + 1;
int[] tprimes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
for (int tp : tprimes) {
ret[pos++] = tp;
int[] ptn = new int[tp];
for (int i = (tp - 3) / 2; i < tp << 5; i += tp) ptn[i >> 5] |= 1 << (i & 31);
for (int j = 0; j < sup; j += tp) {
for (int i = 0; i < tp && i + j < sup; i++) {
isnp[j + i] |= ptn[i];
}
}
}
// 3,5,7
// 2x+3=n
int[] magic = {
0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21,
17, 9, 6, 16, 5, 15, 14
};
int h = n / 2;
for (int i = 0; i < sup; i++) {
for (int j = ~isnp[i]; j != 0; j &= j - 1) {
int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];
int p = 2 * pp + 3;
if (p > n) break;
ret[pos++] = p;
if ((long) p * p > n) continue;
for (int q = (p * p - 3) / 2; q <= h; q += p) isnp[q >> 5] |= 1 << q;
}
}
return Arrays.copyOf(ret, pos);
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 70ee40e13da1a9e00d0b7882d273d2ad | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.PrintWriter;
import java.util.*;
public class TP {
public static PrintWriter out = new PrintWriter(System.out);
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int t = 1;
t = ni();
while (t-- > 0) solve();
out.flush();
}
private static void solve() {
int x = ni(), y = ni();
String s = in.next();
int[] f = new int[128];
for (char c : s.toCharArray()) {
f[c]++;
}
// int[] dir = {0, 0, 0, 0};
// for (int i = 0; i < s.length(); i++) {
// switch (s.charAt(i)) {
// case 'U':
// dir[0]++;
// break;
// case 'R':
// dir[1]++;
// break;
// case 'D':
// dir[2]++;
// break;
// case 'L':
// dir[3]++;
// break;
// }
// }
boolean ok1 = (x == 0) || (x > 0 && f['R'] >= x) || (x < 0 && f['L'] >= Math.abs(x));
boolean ok2 = (y == 0) || (y > 0 && f['U'] >= y) || (y < 0 && f['D'] >= Math.abs(y));
if (ok1 && ok2) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
private static boolean invalid(int[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] < a[i + 1]) return true;
}
return false;
}
private static int ni() {
return in.nextInt();
}
private static int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = ni();
return a;
}
private static long[] nal(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nl();
return a;
}
private static long nl() {
return in.nextLong();
}
private float nf() {
return in.nextFloat();
}
private static double nd() {
return in.nextDouble();
}
public static int[] facs(int n, int[] primes) {
int[] ret = new int[9];
int rp = 0;
for (int p : primes) {
if (p * p > n) break;
int i;
i = 0;
while (n % p == 0) {
n /= p;
i++;
}
if (i > 0) ret[rp++] = p;
}
if (n != 1) ret[rp++] = n;
return Arrays.copyOf(ret, rp);
}
public static int[] sieveEratosthenes(int n) {
if (n <= 32) {
int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
for (int i = 0; i < primes.length; i++) {
if (n < primes[i]) {
return Arrays.copyOf(primes, i);
}
}
return primes;
}
int u = n + 32;
double lu = Math.log(u);
int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];
ret[0] = 2;
int pos = 1;
int[] isnp = new int[(n + 1) / 32 / 2 + 1];
int sup = (n + 1) / 32 / 2 + 1;
int[] tprimes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
for (int tp : tprimes) {
ret[pos++] = tp;
int[] ptn = new int[tp];
for (int i = (tp - 3) / 2; i < tp << 5; i += tp) ptn[i >> 5] |= 1 << (i & 31);
for (int j = 0; j < sup; j += tp) {
for (int i = 0; i < tp && i + j < sup; i++) {
isnp[j + i] |= ptn[i];
}
}
}
// 3,5,7
// 2x+3=n
int[] magic = {
0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21,
17, 9, 6, 16, 5, 15, 14
};
int h = n / 2;
for (int i = 0; i < sup; i++) {
for (int j = ~isnp[i]; j != 0; j &= j - 1) {
int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];
int p = 2 * pp + 3;
if (p > n) break;
ret[pos++] = p;
if ((long) p * p > n) continue;
for (int q = (p * p - 3) / 2; q <= h; q += p) isnp[q >> 5] |= 1 << q;
}
}
return Arrays.copyOf(ret, pos);
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | c59f498854b62f4dbfc41e0b2af965ed | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
short t = input.nextShort();
for(short i = 0; i < t; i++) {
int Px = input.nextInt();
int Py = input.nextInt();
String s = input.next();
char[] commands = s.toCharArray();
short XMax = 0;
short YMax = 0;
short XMin = 0;
short YMin = 0;
for(char command : commands) {
if(command == 'U')
YMax++;
if(command == 'R')
XMax++;
if(command == 'D')
YMin--;
if(command == 'L')
XMin--;
}
if(Px >= 0 && Py >= 0) {
if(XMax >= Px && YMax >= Py)
System.out.println("YES");
else
System.out.println("NO");
}
if(Px < 0 && Py > 0) {
if(XMin <= Px && YMax >= Py)
System.out.println("YES");
else
System.out.println("NO");
}
if(Px <= 0 && Py <= 0) {
if(XMin <= Px && YMin <= Py)
System.out.println("YES");
else
System.out.println("NO");
}
if(Px > 0 && Py < 0) {
if(XMax >= Px && YMin <= Py)
System.out.println("YES");
else
System.out.println("NO");
}
}
input.close();
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 3f1b8befbb194c18888591ca7291616a | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.io.*;
public class cf{
public static void main(String[] args)throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-->0){
StringTokenizer st = new StringTokenizer(br.readLine());
int xp = Integer.parseInt(st.nextToken());
int yp = Integer.parseInt(st.nextToken());
String str = br.readLine();
int U = 0 , D = 0 , R =0 , L = 0;
for(int i = 0 ; i < str.length();i++){
if(str.charAt(i) == 'U'){
U++;
}if(str.charAt(i) =='R'){
R++;
}if(str.charAt(i) =='L'){
L++;
}if(str.charAt(i) =='D'){
D++;
}
}
boolean verti = false;
boolean hori = false;
if(xp>=0){
if(R>=xp){
hori = true;
}
}else{
xp*=-1;
if(L>=xp){
hori = true;
}
}
if(yp>=0){
if(U>=yp){
verti = true;
}
}else{
yp*= -1;
if(D>= yp){
verti = true;
}
}
if(verti && hori){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | d1cde839fc07b08d6e704d28218e66b3 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.*;
public class A522021 {
public static void main(String args[]) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(in.readLine());
while(t-->0){
StringTokenizer st = new StringTokenizer(in.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
String s = in.readLine();
boolean hasX = false;
boolean hasY = false;
if(x>0){
int cnt = 0;
for(int i= 0; i<s.length(); i++){
if(s.charAt(i) =='R'){
cnt++;
}
}
if(cnt>=x){
hasX = true;
}
}
else{
int cnt = 0;
for(int i = 0; i<s.length(); i++){
if(s.charAt(i)=='L'){
cnt++;
}
}
if(cnt>=Math.abs(x)){
hasX = true;
}
}
if(y>0){
int cnt = 0;
for(int i = 0; i<s.length(); i++){
if(s.charAt(i)=='U'){
cnt++;
}
}
if(cnt>=y){
hasY = true;
}
}
else{
int cnt = 0;
for(int i = 0; i<s.length(); i++) {
if(s.charAt(i)=='D'){
cnt++;
}
}
if(cnt>=Math.abs(y)){
hasY= true;
}
}
if(hasX== true && hasY==true){
System.out.println("YES");
}
else System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | fe29574ca9015f2de7d569817e32361c | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.Scanner;
public class solution {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t= scn.nextInt();
while(t-- > 0){
int px = scn.nextInt();
int py = scn.nextInt();
String s = scn.next();
int u = 0;
int r= 0;
int d = 0;
int l = 0;
for(int i=0;i<s.length();i++){
if(s.charAt(i) == 'U')
u++;
else if(s.charAt(i) == 'L')
l--;
else if(s.charAt(i)=='R')
r++;
else d--;
}
boolean x= false;
boolean y = false;
if((px >= l && px <= 0) || (px <= r && px >= 0) )
x = true;
if((py <= u && py >= 0) || (py >= d && py <= 0))
y = true;
if(x && y)
System.out.println("YES");
else System.out.println("No");
// System.out.println(r+" "+d+" "+l+" "+u);
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 87b3141e899261a4e4d423fa71831c50 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int test=sc.nextInt();
while(test-->0){
int x=sc.nextInt();
int y=sc.nextInt();
String str=sc.next();
Map<Character,Integer> t=helper(x,y);
Map<Character,Integer> map=new HashMap<>();
for(int i=0;i<str.length();i++){
char ch=str.charAt(i);
map.put(ch,map.getOrDefault(ch,0)+1);
}
int count=0;
for(Character ch:map.keySet()){
if(t.containsKey(ch) && map.get(ch)>=t.get(ch)){
count++;
}
}
if(count==t.size()){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
public static Map<Character,Integer> helper(int x,int y){
Map<Character,Integer> map=new HashMap<>();
if(x>=0 && y>=0){
if(x!=0){
map.put('R',x);
}
if(y!=0){
map.put('U',y);
}
return map;
}
else if(x<=0 && y>=0){
if(x!=0){
map.put('L',x*-1);
}
if(y!=0){
map.put('U',y);
}
return map;
}
else if(x>=0 && y<=0){
if(x!=0){
map.put('R',x);
}
if(y!=0){
map.put('D',y*-1);
}
return map;
}
if(x!=0){
map.put('L',x*-1);
}
if(y!=0){
map.put('D',y*-1);
}
return map;
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 2953e4565c203ca9561c495d2f0046f0 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | //ღ(¯`◕‿◕´¯) ♫ ♪ ♫ YuSuF ♫ ♪ ♫ (¯`◕‿◕´¯)ღ
import java.util.*;
public class Space_Navigation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-- != 0) {
int location_X = in.nextInt();
int location_Y = in.nextInt();
String orders = in.next();
int x = 0;
int y = 0;
int ups = 0, downs = 0, rights = 0, lefts = 0;
for (int i = 0; i < orders.length(); i++) {
if (orders.charAt(i) == 'U') {
y++;
ups++;
} else if (orders.charAt(i) == 'D') {
y--;
downs++;
} else if (orders.charAt(i) == 'R') {
x++;
rights++;
} else {
x--;
lefts++;
}
}
int x_Diff = x - location_X;
int y_Diff = y - location_Y;
boolean xCord = false;
if (x_Diff < 0) { //left
if (lefts >= x_Diff * -1) {
xCord = true;
}
} else {
if (rights >= x_Diff) {
xCord = true;
}
}
boolean yCord = false;
if (y_Diff < 0) { //left
if (downs >= y_Diff * -1) {
yCord = true;
}
} else {
if (ups >= y_Diff) {
yCord = true;
}
}
if (xCord && yCord) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 8cd6875c3e8d828930797935c54cfa12 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | //ღ(¯`◕‿◕´¯) ♫ ♪ ♫ YuSuF ♫ ♪ ♫ (¯`◕‿◕´¯)ღ
import java.util.*;
public class Space_Navigation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-- != 0) {
int location_X = in.nextInt();
int location_Y = in.nextInt();
String orders = in.next();
int x = 0;
int y = 0;
int ups = 0, downs = 0, rights = 0, lefts = 0;
for (int i = 0; i < orders.length(); i++) {
if (orders.charAt(i) == 'U') {
y++;
ups++;
} else if (orders.charAt(i) == 'D') {
y--;
downs++;
} else if (orders.charAt(i) == 'R') {
x++;
rights++;
} else {
x--;
lefts++;
}
}
// System.out.println("Processed x " + x);
// System.out.println("Processed y " + y);
int x_Diff = x - location_X;
int y_Diff = y - location_Y;
boolean xCord = false;
if (x_Diff < 0) { //left
if (lefts >= x_Diff * -1) {
xCord = true;
}
} else {
if (rights >= x_Diff) {
xCord = true;
}
}
boolean yCord = false;
if (y_Diff < 0) { //left
if (downs >= y_Diff * -1) {
yCord = true;
}
} else {
if (ups >= y_Diff) {
yCord = true;
}
}
// System.out.println("x_Diff " + x_Diff);
// System.out.println("y_Diff " + y_Diff);
//
// System.out.println("ups " + ups);
// System.out.println("downs " + downs);
// System.out.println("rights " + rights);
// System.out.println("lefts " + lefts);
if (xCord && yCord) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | ca4b5b746b9dfcc79070f1c0f78d21a4 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
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 Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t-->0)
{
int x=in.nextInt(); int y=in.nextInt();
String s=in.next();
char arr[]=s.toCharArray();
int n=s.length(); int r=0; int u=0; int l=0; int d=0;
for (int i = 0; i < n; i++)
{
if(arr[i]=='R'){ r++;}
else if(arr[i]=='L') {l++;}
else if(arr[i]=='U') {u++;}
else {d++;}
}
if(x>=0 && y>=0)
{
x=Math.abs(x); y=Math.abs(y);
if(x<=r && y<=u)
{ System.out.println("YES"); continue;}
System.out.println("NO"); continue;
}
else if(x<=0 && y<=0)
{
x=Math.abs(x); y=Math.abs(y);
if(x<=l && y<=d)
{ System.out.println("YES"); continue;}
System.out.println("NO"); continue;
}
else if(x<=0 && y>=0)
{
x=Math.abs(x); y=Math.abs(y);
if(x<=l && y<=u)
{ System.out.println("YES"); continue;}
System.out.println("NO"); continue;
}
else
{
x=Math.abs(x); y=Math.abs(y);
if(x<=r && y<=d)
{ System.out.println("YES"); continue;}
System.out.println("NO"); continue;
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 1be4081522d53b769f93996f347a462e | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | // Working program with FastReader
import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader s = new FastReader();
int t = s.nextInt();
while (t-- > 0) {
long x = s.nextLong();
long y = s.nextLong();
String str = s.nextLine();
System.out.println(find(x,y,str));
}
}
public static String find(long x, long y, String str)
{
long countR = 0, countL = 0, countU = 0, countD = 0;
for(char ch:str.toCharArray())
{
if(ch=='R')
countR++;
else if(ch=='L')
countL--;
else if(ch=='U')
countU++;
else
countD--;
}
if(x==0 && y!=0)
{
if((y>0 &&countU>=y) || (y<0 && countD<=y))
return "YES";
}
if(x!=0 && y==0)
{
if((x>0 && countR>=x) || (x<0 && countL<=x))
return "YES";
}
if(x>0 && y>0)
{
if(countR>=x && countU>=y)
return "YES";
}
else if(x>0 && y<0)
{
if(countR>=x && countD<=y)
return "YES";
}
else if(x<0 && y>0)
{
if(countL<=x && countU>=y)
return "YES";
}
else if(x<0 && y<0)
{
if(countL<=x && countD<=y)
return "YES";
}
return "NO";
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | f5551a977f73113a98df322a10911ae6 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
long i,t;
Scanner sc=new Scanner(System.in);
t=sc.nextLong();
for(i=1;i<=t;i++)
{ long x,y,u=0,d=0,r=0,l=0,c=0;
String s;char a;int j;
x=sc.nextLong();
y=sc.nextLong();
s=sc.next();
for(j=0;j<s.length();j++)
{a=s.charAt(j);
if(a=='U'){u++;}
if(a=='D'){d++;}
if(a=='R'){r++;}
if(a=='L'){l++;}}
if(x>=0){if(r>=x){c++;}}
if(x<0){if(l>=(-1*x)){c++;}}
if(y>=0){if(u>=y){c++;}}
if(y<0){if(d>=(-1*y)){c++;}}
if(c==2){System.out.println("YES");}
else{System.out.println("NO");}}}}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 8147989aaa575141848281e545aa23de | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class Space
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-->0)
{
int px = sc.nextInt();
int py = sc.nextInt();
String s = sc.next();
int countU=0,countD=0,countL=0,countR=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='U')
{
countU++;
}
else if(s.charAt(i)=='D')
{
countD++;
}
else if(s.charAt(i)=='R')
{
countR++;
}
else if(s.charAt(i)=='L')
{
countL++;
}
}
boolean flag = false;
if(px>=0 && py>=0)
{
//System.out.println("Case 1");
if(countU>=py && countR>=px )
{
flag = true;
}
}
else if(px>=0 && py<=0)
{
//System.out.println("Case 2");
if(countD>=Math.abs(py) && countR>=px)
{
flag = true;
}
}
else if(px<=0 && py<=0)
{
//System.out.println("Case 3");
if(countD>=Math.abs(py) && countL>=Math.abs(px) )
{
flag = true;
}
}
else if(px<=0 && py>=0)
{
//System.out.println("Case 4");
if(countU>=py && countL>=Math.abs(px))
{
flag = true;
}
}
if(flag==true)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 19621c13febbdb29e8e0a834774b6e58 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class JavaTasks{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt(),x,y,count1=0,count2=0;
String s,ans="";
for (int i=0;i<n;i++){
x=sc.nextInt();
y=sc.nextInt();
s=sc.next();
if (x>=0 && y>=0 ){
for (int j=0;j<s.length();j++){
if (s.charAt(j)=='R')
count1++;
if (s.charAt(j)=='U')
count2++;
}
if (count1>=x && count2>=y)
ans+="YES\n";
else
ans+="NO\n";
}
else if (x>=0 && y<=0){
for (int j=0;j<s.length();j++){
if (s.charAt(j)=='R')
count1++;
if (s.charAt(j)=='D')
count2++;
}
if (count1>=x && count2>=(-1)*y)
ans+="YES\n";
else
ans+="NO\n";
}
else if (x<=0 && y>=0){
for (int j=0;j<s.length();j++){
if (s.charAt(j)=='L')
count1++;
if (s.charAt(j)=='U')
count2++;
}
if (count1>=(-1)*x && count2>=y)
ans+="YES\n";
else
ans+="NO\n";
}
else{
for (int j=0;j<s.length();j++){
if (s.charAt(j)=='L')
count1++;
if (s.charAt(j)=='D')
count2++;
}
if (count1>=(-1)*x && count2>=(-1)*y)
ans+="YES\n";
else
ans+="NO\n";
}
count1=0;
count2=0;
}
System.out.print(ans);
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 6976c6bec4bce65c27fd619704ee523c | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class spacenav {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args)
{
FastReader sc = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int testcase = sc.nextInt();
while(testcase-- > 0) {
int x = sc.nextInt();
int y = sc.nextInt();
String str = sc.next();
boolean res = solve(x, y, str);
if(res)
pw.println("YES");
else
pw.println("NO");
}
pw.flush();
}
public static boolean solve(int x, int y, String str) {
boolean xRes = false, yRes = false;
if(x == 0 && y == 0)
return true;
if(x >= 0) {
int count = 0;
for (int i = 0; i < str.length(); i++){
if(str.charAt(i) == 'R')
count++;
if(count >= Math.abs(x))
xRes = true;
}
//System.out.println(count);
}
if(x < 0) {
int count = 0;
for (int i = 0; i < str.length(); i++){
if(str.charAt(i) == 'L')
count++;
if(count >= Math.abs(x))
xRes = true;
}
// System.out.println(count);
}
if(y >= 0) {
int count = 0;
for (int i = 0; i < str.length(); i++){
if(str.charAt(i) == 'U')
count++;
if(count >= Math.abs(y))
yRes = true;
}
// System.out.println(count);
}
if(y < 0) {
int count = 0;
for (int i = 0; i < str.length(); i++){
if(str.charAt(i) == 'D')
count++;
if(count >= Math.abs(y))
yRes = true;
}
// System.out.println(count);
}
return xRes && yRes;
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 001b2aae742fc8abe21936d967d63b26 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t>0) {
int p1 = s.nextInt();
int p2 = s.nextInt();
s.nextLine();
String string = s.nextLine();
HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
for(int i=0;i<string.length();i++) {
if(hm.containsKey(string.charAt(i))) {
hm.put(string.charAt(i),hm.get(string.charAt(i))+1);
}else {
hm.put(string.charAt(i),1);
}
}
boolean printed = false;
if (p1>0) {
if (hm.containsKey('R')) {
if (hm.get('R')<p1) {
System.out.println("NO");
printed=true;
}
}else {
System.out.println("NO");
printed = true;
}
}
else if (p1<0){
if (hm.containsKey('L')) {
if (hm.get('L')<Math.abs(p1)) {
System.out.println("NO");
printed =true;
}
}else {
System.out.println("NO");
printed = true;
}
}
if (!printed) {
if (p2>0) {
if (hm.containsKey('U')) {
if (hm.get('U')<p2) {
System.out.println("NO");
printed=true;
}
}else {
System.out.println("NO");
printed = true;
}
}
else if (p2<0){
if (hm.containsKey('D')) {
if (hm.get('D')<Math.abs(p2)) {
System.out.println("NO");
printed =true;
}
}else {
System.out.println("NO");
printed = true;
}
}
}
if (!printed) {
System.out.println("YES");
}
t--;
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | e4389b30d2f6b85a3587b09615460253 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class A
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int px,py;String s;
int R,L,U,D,fl;char c;
while(n>0)
{
R=0;L=0;U=0;D=0;fl=0;
px=Integer.parseInt(sc.next());
py=Integer.parseInt(sc.next());
s=sc.next();
for(int i=0;i<s.length();i++)
{
c=s.charAt(i);
if(c=='L')
L++;
else if(c=='U')
U++;
else if(c=='D')
D++;
else
R++;
}
if(px>0 && R<px)
fl=1;
if(px<0 && L<-px)
fl=1;
if(py<0 && D<-py)
fl=1;
if(py>0 && U<py)
fl=1;
if(fl==1)
System.out.println("NO");
else
System.out.println("YES");
n--;
}
sc.close();
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 4f811a89a5e5db4ecc0fbb449c5d25b2 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | /* package codechef; // 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
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int x=sc.nextInt();
int y=sc.nextInt();
String a=sc.next();
int r=0,u=0,d=0,l=0;
for(int i=0;i<a.length();i++)
{
if(a.charAt(i)=='R')
r++;
else if(a.charAt(i)=='L')
l++;
else if(a.charAt(i)=='U')
u++;
else if(a.charAt(i)=='D')
d++;
}
// System.out.println(r+" "+l+" "+u+" "+d);
if(x>0 && y>0 && r>=x && u>=y )
System.out.println("YES");
else if(x<0 && y>0 && l>=-(x) && u>=y )
System.out.println("YES");
else if(x<0 && y<0 && l>=-(x) && d>=-(y) )
System.out.println("YES");
else if(x>0 && y<0 && r>=(x) && d>=(-(y)) )
System.out.println("YES");
else if(x>0 && y==0 && r>=x)
System.out.println("YES");
else if(x<0 && y==0 && l>=-(x))
System.out.println("YES");
else if(x==0 && y>0 && u>=y)
System.out.println("YES");
else if(x==0 && y<0 && d>=-(y))
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 42782b5f5d403a24121d683b179ccf8c | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class scratch{
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
int t = Integer.parseInt(br.readLine());
while (t-->0){
solve();
}
}
static void solve() throws IOException {
String[] s1 = br.readLine().split(" ");
int x = Integer.parseInt(s1[0]);
int y = Integer.parseInt(s1[1]);
String s = br.readLine();
int u=0,d=0,l=0,r=0;
for(int i=0;i<s.length();i++){
char curr = s.charAt(i);
if(curr=='U'){
u++;
}else if(curr=='D'){
d++;
}else if(curr == 'L'){
l++;
}else if(curr == 'R'){
r++;
}
}
if(y < 0 && x < 0){
if(d >= Math.abs(y) && l >= Math.abs(x)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}else if(y > 0 && x < 0){
if(u >= Math.abs(y) && l >= Math.abs(x)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}else if(y<0 && x>0){
if(d >= Math.abs(y) && r >= Math.abs(x)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}else if(y>0 && x>0){
if(u >= Math.abs(y) && r >= Math.abs(x)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}else if(x==0 && y!=0){
if(y<0){
if(d>=Math.abs(y)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}else{
if(u>=Math.abs(y)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}else if(x!=0 && y==0){
if(x<0){
if(l>=Math.abs(x)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}else{
if(r>=Math.abs(x)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 7bf6ca2db9f8f3390463b2e4e8c9004a | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
public class puzzle {
public static void main(String[] args) {
StdIn input = new StdIn();
int t = input.nextInt();
for (int l = 0; l < t; l++) {
int x = input.nextInt();
int y = input.nextInt();
String s=input.next();
int n=s.length();
char ch[]=new char[n];
for(int i=0;i<n;i++){
ch[i]=s.charAt(i);
}
int U=0;
int D=0;
int R=0;
int L=0;
for(int i=0;i<n;i++){
if(ch[i]=='U'){
U++;
}
else if(ch[i]=='D'){
D++;
}
else if(ch[i]=='R'){
R++;
}
else {
L++;
}
}
// System.out.println(" L "+ L+" R "+R+" D "+D+" U "+U);
if(y<=U&&x<=R&&x>=0&&y>=0)
System.out.println("YES");
else if(y<=U&&-x<=L&&x<=0&&y>=0)
System.out.println("YES");
else if(-y<=D&&-x<=L&&x<=0&&y<=0)
System.out.println("YES");
else if(-y<=D&&x<=R&&x>=0&&y<=0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
interface Input {
public String next();
public String nextLine();
public int nextInt();
public long nextLong();
public double nextDouble();
}
class StdIn implements Input {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public StdIn() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public StdIn(String filename) {
try {
din = new DataInputStream(new FileInputStream(filename));
} catch (Exception e) {
throw new RuntimeException();
}
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String next() {
int c;
while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r')) ;
StringBuilder s = new StringBuilder();
while (c != -1) {
if (c == ' ' || c == '\n' || c == '\r')
break;
s.append((char) c);
c = read();
}
return s.toString();
}
public String nextLine() {
int c;
while ((c = read()) != -1 && (c == ' ' || c == '\n' || c == '\r')) ;
StringBuilder s = new StringBuilder();
while (c != -1) {
if (c == '\n' || c == '\r')
break;
s.append((char) c);
c = read();
}
return s.toString();
}
public int nextInt() {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public int[] readIntArray(int n) {
int[] ar = new int[n];
for (int i = 0; i < n; ++i)
ar[i] = nextInt();
return ar;
}
public long nextLong() {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long[] readLongArray(int n) {
long[] ar = new long[n];
for (int i = 0; i < n; ++i)
ar[i] = nextLong();
return ar;
}
public double nextDouble() {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() {
try {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
} catch (IOException e) {
throw new RuntimeException();
}
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | f6f2fc0ec964e1e86a4f59ee8081a2d0 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.lang.*;
public class A {
public static void main(String[] args) {
FastScanner fs=new FastScanner();
PrintWriter pwr = new PrintWriter(System.out,true);
int t=fs.nextInt();
for(int i=0;i<t;i++) {
int x=fs.nextInt(),y=fs.nextInt();
String str=fs.next();
char arr[]=str.toCharArray();
int l=0,d=0,u=0,r=0;
for(int j=0;j<str.length();j++) {
if(arr[j]=='L') {
l++;
}
else if(arr[j]=='R') {
r++;
}
else if(arr[j]=='U') {
u++;
}
else {
d++;
}
}
boolean fx=false,fy=false;
if(x>=0 && r>=x) {
fx=true;
}
if(x<0 && l>=Math.abs(x)) {
fx=true;
}
if(y>=0 && u>=y) {
fy=true;
}
if(y<0 && d>=Math.abs(y)) {
fy=true;
}
//pwr.println(x+" "+y+" "+r+" "+l+" "+u+" "+d);
if(fx && fy) {
pwr.println("YES");
}
else {
pwr.println("NO");
}
}
}
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | f8a2052d7ba9a3c81f539818054da26c | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.io.*;
public class A12
{
public static void process()throws IOException
{
int x=I();int y=I();
String s=S();
int u=0;int d=0;int l=0;int r=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='U')
{
u++;
}
else
if(s.charAt(i)=='D')
{
d++;
}
else
if(s.charAt(i)=='L')
{
l++;
}
else
if(s.charAt(i)=='R')
{
r++;
}
}
boolean flag=false; boolean flag1=false;
if(x==0)
{
flag=true;
}
else
if(x>0)
{
if(r>=x)
{
flag=true;
}
}
else
if(x<0)
{
if(l>=Math.abs(x))
{
flag=true;
}
}
if(y==0)
{
flag1=true;
}
else
if(y>0)
{
if(u>=y)
{
flag1=true;
}
}
else
if(y<0)
{
if(d>=Math.abs(y))
{
flag1=true;
}
}
if(flag && flag1==true)
{
pn("YES");
}
else
{
pn("NO");
}
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
static void pn(Object o){out.println(o);out.flush();}
static void p(Object o){out.print(o);out.flush();}
static void pni(Object o){out.println(o);System.out.flush();}
static int I() throws IOException{return sc.nextInt();}
static long L() throws IOException{return sc.nextLong();}
static double D() throws IOException{return sc.nextDouble();}
static String S() throws IOException{return sc.next();}
static char C() throws IOException{return sc.next().charAt(0);}
static int[] Ai(int n) throws IOException{int[] arr = new int[n];for (int i = 0; i < n; i++)arr[i] = I();return arr;}
static String[] As(int n) throws IOException{String s[] = new String[n];for (int i = 0; i < n; i++)s[i] = S();return s;}
static long[] Al(int n) throws IOException {long[] arr = new long[n];for (int i = 0; i < n; i++)arr[i] = L();return arr;}
// *--------------------------------------------------------------------------------------------------------------------------------*//
static class AnotherReader {BufferedReader br;StringTokenizer st;AnotherReader() throws FileNotFoundException {br = new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a) throws FileNotFoundException {br = new BufferedReader(new FileReader("input.txt"));}
String next() throws IOException{while (st == null || !st.hasMoreElements()) {try {st = new StringTokenizer(br.readLine());} catch (IOException e) {e.printStackTrace();}}return st.nextToken();}
int nextInt() throws IOException {return Integer.parseInt(next());}
long nextLong() throws IOException {return Long.parseLong(next());}
double nextDouble() throws IOException {return Double.parseDouble(next());}
String nextLine() throws IOException {String str = "";try {str = br.readLine();} catch (IOException e) {e.printStackTrace();}return str;}}
public static void main(String[] args)throws IOException{try{boolean oj=true;if(oj==true)
{AnotherReader sk=new AnotherReader();PrintWriter out=new PrintWriter(System.out);}
else
{AnotherReader sk=new AnotherReader(100);out=new PrintWriter("output.txt");}
long T=L();while(T-->0)
{process();}out.flush();out.close();}catch(Exception e){return;}}}
//*-----------------------------------------------------------------------------------------------------------------------------------*// | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 79039bdb0fb93f094b15c8bf3c3f1d29 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t=in.nextInt();
for(int c=0;c<t;c++)
{
int x=in.nextInt();
int y=in.nextInt();
in.nextLine();
boolean result=false;
boolean result1=false;
String str=in.nextLine();
int u=0,l=-999999999,d=-999999999,r=0;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)=='U')
u++;
else if(str.charAt(i)=='L')
{
if(l==-999999999)
l=1;
else
l++;
}
else if(str.charAt(i)=='D')
{
if(d==-999999999)
d=1;
else
d++;
}
else
r++;
}
if(x>=0)
{
if(r>=Math.abs(x))
result=true;
else
result=false;
}
else
{
if(l>=Math.abs(x))
result=true;
else
result=false;
}
if(y>=0)
{
if(u>=y)
result1=true;
else
result1=false;
}
else
{
if(d>=Math.abs(y))
result1=true;
else
result1=false;
}
if(result&&result1)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 05c766a279a2579fe960a959250516ea | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | /**
* @author -- Sourav Joshi
*/
import java.io.*;
import java.util.*;
public class Solution {
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static FastScanner s = new FastScanner();
static FastWriter out = new FastWriter();
final static int mod = 1000000000 + 7;
final static int INT_MAX = Integer.MAX_VALUE;
final static int INT_MIN = Integer.MIN_VALUE;
final static long LONG_MAX = Long.MAX_VALUE;
final static long LONG_MIN = Long.MIN_VALUE;
final static double DOUBLE_MAX = Double.MAX_VALUE;
final static double DOUBLE_MIN = Double.MIN_VALUE;
final static float FLOAT_MAX = Float.MAX_VALUE;
final static float FLOAT_MIN = Float.MIN_VALUE;
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
static class FastScanner{BufferedReader br;StringTokenizer st;
public FastScanner() {br = new BufferedReader(new InputStreamReader(System.in));}
String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException e){e.printStackTrace();}}return st.nextToken();}
int nextInt(){return Integer.parseInt(next());}
long nextLong(){return Long.parseLong(next());}
double nextDouble(){return Double.parseDouble(next());}
String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}}
static class FastWriter{private final BufferedWriter bw;public FastWriter() {this.bw = new BufferedWriter(new OutputStreamWriter(System.out));}
public void print(Object object) throws IOException{bw.append(""+ object);}
public void println(Object object) throws IOException{print(object);bw.append("\n");}
public void close() throws IOException{bw.close();}}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
public static ArrayList<Integer> seive(int n){ArrayList<Integer> list = new ArrayList<>();int arr[] = new int[n+1];for(int i = 2; i <= n; i++) {if(arr[i] == 1) {continue;}else {list.add(i);for(int j = i*i; j <= n; j = j + i) {arr[j] = 1;}}}return list;}
public static long gcd(long a, long b){if(a > b) {a = (a+b)-(b=a);}if(a == 0L){return b;}return gcd(b%a, a);}
public static void swap(int[] arr, int i, int j) {arr[i] = arr[i] ^ arr[j]; arr[j] = arr[j] ^ arr[i]; arr[i] = arr[i] ^ arr[j];}
public static boolean isPrime(long n){if(n < 2){return false;}if(n == 2 || n == 3){return true;}if(n%2 == 0 || n%3 == 0){return false;}long sqrtN = (long)Math.sqrt(n)+1;for(long i = 6L; i <= sqrtN; i += 6) {if(n%(i-1) == 0 || n%(i+1) == 0) return false;}return true;}
public static void takeintarr(int arr[][]) {for(int i = 0; i < arr.length; i++) {for(int j = 0; j < arr[0].length; j++) {arr[i][j] = s.nextInt();}}}
public static void takeintarr(int arr[]) {for(int i = 0; i < arr.length; i++) {arr[i] = s.nextInt();}}
public static void printdoublearr(double arr[][]) {for(int i = 0 ; i < arr.length; i++) {for(int j = 0; j < arr[0].length; j++) {System.out.print(arr[i][j]+" ");}System.out.println();}}
public static void printdoublearr(long arr[][]) {for(int i = 0 ; i < arr.length; i++) {for(int j = 0; j < arr[0].length; j++) {System.out.print(arr[i][j]+" ");}System.out.println();}}
public static void printdoublearr(int arr[][]) {for(int i = 0 ; i < arr.length; i++) {for(int j = 0; j < arr[0].length; j++) {System.out.print(arr[i][j]+" ");}System.out.println();}}
public static void printlongarr(long[] arr) {for(int i = 0; i < arr.length; i++) {System.out.print(arr[i]+" ");}}
public static void printlongarr(int[] arr) {for(int i = 0; i < arr.length; i++) {System.out.print(arr[i]+" ");}}
public static void printlongarr(double[] arr) {for(int i = 0; i < arr.length; i++) {System.out.print(arr[i]+" ");}}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
public static void main(String[] args) throws IOException {
int test = s.nextInt();
for(int tt = 1; tt <= test; tt++) {
int x = s.nextInt();
int y = s.nextInt();
String str = s.nextLine();
int u = 0, d = 0, l = 0, r = 0;
for(int i = 0; i < str.length(); i++){
char ch = str.charAt(i);
if(ch == 'U') u++;
if(ch == 'D') d++;
if(ch == 'L') l++;
if(ch == 'R') r++;
}
boolean x_axis = false;
boolean y_axis = false;
if(x == 0){
x_axis = true;
}else if(x < 0){
int step = Math.abs(x);
if(l >= step) x_axis = true;
}else{
int step = Math.abs(x);
if(r >= step) x_axis = true;
}
if(y == 0){
y_axis = true;
}else if(y < 0){
int step = Math.abs(y);
if(d >= step) y_axis = true;
}else{
int step = Math.abs(y);
if(u >= step) y_axis = true;
}
if(x_axis && y_axis){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
out.close();
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | b8df6eef9376fcd7221739e003bd8bfc | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class calc
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t-->0)
{
int x=in.nextInt();
int y=in.nextInt();
String s=in.next();
int u=0,d=0,l=0,r=0;
for(int i=0;i<s.length();i++)
{
char ch=s.charAt(i);
if(ch=='U')
u++;
if(ch=='D')
d--;
if(ch=='L')
l--;
if(ch=='R')
r++;
}
if(r>=x && l<=x && u>=y && d<=y)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 3232b0e1c4e9d117c586a330c0c3b569 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class stringGame {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
try{
int t = scn.nextInt();
while(t-- > 0){
int x = scn.nextInt();
int y = scn.nextInt();
String str= scn.next();
boolean x1 = false;
boolean y1 = false;
int countR = 0;
int countL= 0;
int countU = 0;
int countD = 0;
for(int i = 0;i<str.length();i++){
if(str.charAt(i) == 'R'){
countR++;
}
else if(str.charAt(i) == 'L'){
countL++;
}
else if(str.charAt(i) == 'U'){
countU++;
}
else if(str.charAt(i) == 'D'){
countD++;
}
}
if(x > 0 && countR >= x){
x1 = true;
}
if(x < 0 && countL >= Math.abs(x)){
x1 = true;
}
if(y > 0 && countU>= y ){
y1 = true;
}
if(y < 0 &&countD >= Math.abs(y) ){
y1 = true;
}
if(x1 == true && y1 == true && x!=0 && y!=0){
System.out.println("YES");
}
else if(x != 0 && x1 == true && y == 0){
System.out.println("YES");
}
else if(y != 0 && y1 == true && x == 0){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
catch (Exception e){
return;
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | e6bdf4886af46036cb1910b0b18e9af6 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.*;
public class WUB {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int xx = 0; xx < t; xx++) {
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc.next();
for(int i=0;i<s.length();i++)
{
if(x>0)
{
if(s.charAt(i)=='R')
{
x--;
}
}
if(x<0)
{
if(s.charAt(i)=='L')
{
x++;
}
}
if(y<0)
{
if(s.charAt(i)=='D')
{
y++;
}
}
if(y>0)
{
if(s.charAt(i)=='U')
{
y--;
}
}
if(x==0&&y==0)
{
break;
}
}
if(x==0&&y==0)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 2edf15a4274eb9cdf82c846a6d5b50cb | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.*;
import java.io.*;
public class P07 {
static class FastReader{
BufferedReader br ;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st==null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}catch(IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
}catch(IOException e) {
e.printStackTrace();
}
return str ;
}
}
public static void main(String[] args)throws IOException {
FastReader fs = new FastReader();
int t = fs.nextInt();
while(t-->0) {
int x = fs.nextInt();
int y = fs.nextInt();
String s = fs.next();
int u =0,l=0,d=0,r=0;
for(int i =0;i<s.length();i++) {
if(s.charAt(i)=='L')l--;
else if(s.charAt(i)=='R')r++;
else if(s.charAt(i)=='U')u++;
else if(s.charAt(i)=='D')d--;
}
int c=0;
if(y<0) {
if(d<=y)c++;
// System.out.println(1);
}
else {
if(u>=y)c++;
// System.out.println(2);
}
if(x<0) {
if(l<=x)c++;
// System.out.println(3);
}
else {
if(r>=x)c++;
// System.out.println(4);
}
//System.out.println(u+" "+d+" "+l+" "+r+" "+c);
if(c==2) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
private static int gcd(int i, int j) {
if(j==0) {
return i;
}
return gcd(j,i%j);
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 6d71805cc471fe5801e08c0f826f74d4 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.util.StringTokenizer;
import java.io.*;
public class P04 {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int t = sc.nextInt();
while(t-->0) {
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc.next();
int u=0,d=0,r=0,l=0;
for(int i =0;i<s.length();i++) {
if(s.charAt(i)=='U') {
u++;
}
if(s.charAt(i)=='D') {
d--;
}
if(s.charAt(i)=='L') {
l--;
}
if(s.charAt(i)=='R') {
r++;
}
}
if(x>=l&&x<=r&&y>=d&&y<=u) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 353ffee7d8d9e2926d88ad2f1862505b | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codeforces {
public static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
FastReader sc=new FastReader();
int t=sc.nextInt();
while(t-->0)
{
int a=sc.nextInt();
int b=sc.nextInt();
String s=sc.nextLine();
HashMap<Character,Integer> hm=new HashMap<>();
if(a>=0 && b>=0)
{
hm=create('R','U',a,b);
}
else if(a>=0 && b<=0)
{
hm=create('R','D',a,(-1)*b);
}
else if(a<=0 && b>=0)
{
hm=create('L','U',(-1)*a,b);
}
else if(a<=0 && b<=0)
{
hm=create('L','D',(-1)*a,(-1)*b);
}
for(int i=0;i<s.length();i++)
{
char c=s.charAt(i);
if(hm.containsKey(c) && hm.get(c)>0)
hm.put(c,hm.get(c)-1);
}
int p=0;
for(Map.Entry<Character,Integer> e:hm.entrySet())
{
if(e.getValue()!=0)
{
p=1;
break;
}
}
if(p==1)
System.out.println("NO");
else
System.out.println("YES");
}
}
public static HashMap<Character,Integer> create(char c1,char c2,int n1,int n2)
{
HashMap<Character,Integer> hm=new HashMap<>();
hm.put(c1,n1);
hm.put(c2,n2);
return hm;
}
public static long digitSum(long n)
{
long sum=0;
while(n!=0)
{
sum=sum+n%10;
n=n/10;
}
return sum;
}
public static long gcd(long a,long b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 8cdab68816feec7f499049b99b66f2d7 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | // package CodeChef;
import java.util.*;
import java.io.*;
public class pract2 {
static long mod=1000000007;
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int test=sc.nextInt();
// int[] a= {1,11,111,1111,2,22,222,2222,3,33,333,3333,4,44,444,4444,5,55,555,5555,6,66,666,6666,7,77,777,7777,8,88,888,8888,9,99,999,9999};
while(test-->0) {
int px=sc.nextInt();
int py=sc.nextInt();
String str=sc.next();
int cl=0,cr=0,cd=0,cu=0;
if(px== 0&& py==0) {
System.out.println("YES");
continue;
}
for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='R')cr++;
else if(str.charAt(i)=='L')cl++;
else if(str.charAt(i)=='U')cu++;
else cd++;
}
boolean ok1=false;
boolean ok2=false;
if(px<0 && Math.abs(px)<=cl) {
ok1=true;
}
else if(px>=0 && cr>=px) {
ok1=true;
}
if(py<0 && Math.abs(py)<=cd) {
ok2=true;
}
else if(py>=0 && cu>=py) {
ok2=true;
}
if(ok1&& ok2)System.out.println("YES");
else System.out.println("NO");
}
}
public static void swap(int a, int b) {
int temp=a;
a=b;
b=temp;
}
public static boolean checkPallindrome(String str){
boolean ok=true;
int low=0;int high=str.length()-1;
while(low<high){
if(str.charAt(low)==str.charAt(high)){
ok=false;
break;
}
low++;high--;
}
return ok;
}
public static int[] primeArray(int n){
boolean prime[] = new boolean[n + 1];
for (int i = 0; i <= n; i++)
prime[i] = true;
for (int p = 2; p * p <= n; p++)
{
if (prime[p] == true)
{
for (int i = p * p; i <= n; i += p)
prime[i] = false;
}
}
int[] primeArray =new int[n+1];int pos=0;
for(int i=0;i<n;i++) {
if(prime[i]==true) {
primeArray[pos++]=i;
}
}
return primeArray;
}
public static boolean checkPrime(int n) {
for(int i=2;i*i<n;i++) {
if(n%i==0)return false;
}
return true;
}
public static int GCD2(int a, int b) {
if(a==0)return b;
if(b==0)return a;
if(a>b)return GCD2(a%b,b);
else return GCD2(b%a,a);
}
public static void sort(int[] arr,int strt,int lst) {
if(lst>arr.length-1) {
lst=arr.length-1;
}
while(strt<=lst) {
int temp=arr[strt];
arr[strt]=arr[lst];
arr[lst]=temp;
strt++;lst--;
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | ccf0fc9dfa033c9c30039fbb736bde46 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.Scanner;
public class Space_Navigation {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
int x=sc.nextInt(),y=sc.nextInt();
String s=sc.next();
int L=0,R=0,U=0,D=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='U')
U++;
if(s.charAt(i)=='D')
D++;
if(s.charAt(i)=='L')
L++;
if(s.charAt(i)=='R')
R++;
}
// System.out.println(L+" "+R+" "+U+" "+D);
if(x==0 && y==0)
System.out.println("YES");
else if(x>=0 && y>=0 && R>=Math.abs(x) && U>=Math.abs(y))
System.out.println("YES");
else if(x<=0 && y>=0 && L>=Math.abs(x) && U>=Math.abs(y))
System.out.println("YES");
else if(x>=0 && y<=0 && R>=Math.abs(x) && D>=Math.abs(y))
System.out.println("YES");
else if(x<=0 && y<=0 && L>=Math.abs(x) && D>=Math.abs(y))
System.out.println("YES");
else
System.out.println("NO");
t--;
}
sc.close();
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 64c6b9f378062248e16496761ddfb6a1 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int t=s.nextInt();
while(t-->0) {
int x=s.nextInt();
int y=s.nextInt();
String str = s.next();
if(x==0&&y==0) {
System.out.println("yes");
continue;
}
int r = 0,u = 0,l = 0,d = 0;
for(int i=0;i<str.length();i++) {
char ch=str.charAt(i);
if(ch=='R') {
r++;
}else if(ch=='U') {
u++;
}else if(ch=='D') {
d++;
}else {
l++;
}
}
if(x>=0&&y>=0) {
if(r>=x&&u>=y) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}else if(x>=0&&y<=0) {
if(r>=x&&d>=Math.abs(y)) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}else if(x<=0&&y>=0) {
if(l>=Math.abs(x)&&u>=y) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}else if(x<=0&&y<=0) {
if(l>=Math.abs(x)&&d>=Math.abs(y)) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | dcc77be4281333ce7fec7ef07e220ec2 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t;
t = input.nextInt();
while (t != 0) {
int px, py, countR = 0, countL = 0, i, countU = 0, countD = 0;
px = input.nextInt();
py = input.nextInt();
input.nextLine();
String s = input.nextLine();
s.toUpperCase();
char[] m = s.toCharArray(); //convert string to character type array
for (i = 0; i < s.length(); i++) {
if (m[i] == 'R') {
countR++;
} else {
if (m[i] == 'L') {
countL++;
} else {
if (m[i] == 'U') {
countU++;
} else {
countD++;
}
}
}
}
short j, k;
if (px >= 0) {
if (countR >= px) {
j = 1;
} else {
j = 0;
}
} else {
if (countL >= Math.abs(px)) {
j = 1;
} else {
j = 0;
}
}
if (py >= 0) {
if (countU >= py) {
k = 1;
} else {
k = 0;
}
} else {
if (countD >= Math.abs(py)) {
k = 1;
} else {
k = 0;
}
}
if (j == 1 && k == 1) {
System.out.println("yes");
} else {
System.out.println("no");
}
t--;
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | e4f012bed91f80a1b9689ea5e158fe4d | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class SpaceNavigation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-- > 0) {
int x = in.nextInt();
int y = in.nextInt();
String s = in.next();
boolean forX;
boolean forY;
int u = 0;
int d = 0;
int r = 0;
int l = 0;
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'U')
u++;
else if(s.charAt(i) == 'D')
d++;
else if(s.charAt(i) == 'R')
r++;
else if(s.charAt(i) == 'L')
l++;
}
if(x > 0) {
if(x <= r)
forX = true;
else forX = false;
}
else if(x < 0) {
x *= -1;
if(x <= l)
forX = true;
else forX = false;
}
else forX = true;
if(y > 0) {
if(y <= u)
forY = true;
else forY = false;
}
else if(y < 0) {
y *= -1;
if(y <= d)
forY = true;
else forY = false;
}
else forY = true;
if(forX && forY)
System.out.println("YES");
else System.out.println("NO");
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | fd6269b25f592b9dc157a19da4e5e48b | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.Scanner;
public class Scratch {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int checkCase = sc.nextInt();
for (int j = 0; j < checkCase; j++) {
int u = 0, d = 0, l = 0, r = 0;
int leftRight = sc.nextInt();
int upDown = sc.nextInt();
boolean isUpDown = false;
boolean isLeftRight = false;
String str= sc.next();
for (int i = 0; i < str.length(); i++) {
char a = str.charAt(i);
switch (a) {
case 'U':
u++;
break;
case 'D':
d++;
break;
case 'L':
l++;
break;
case 'R':
r++;
break;
default:
System.out.println("invalid input");
}
}
if(upDown == 0){
isUpDown = true;
}
else if(upDown > 0) {
if (u >= upDown) {
isUpDown = true;
}
} else if(upDown < 0){
if(d >= -(upDown)){
isUpDown = true;
}
}
if(leftRight == 0){
isLeftRight = true;
}
else if(leftRight > 0) {
if (r >= leftRight) {
isLeftRight = true;
}
} else if(leftRight < 0){
if(l >= -(leftRight)){
isLeftRight = true;
}
}
if(isLeftRight && isUpDown){
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | b2bf99a5abc40314c9477c82ee2172af | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class test{
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int T = s.nextInt();
for(int tt=0;tt<T;tt++){
int x = s.nextInt();
int y = s.nextInt();
String com = s.next();
int RCount = 0;
int LCount = 0;
int UCount = 0;
int DCount = 0;
boolean validX = false;
boolean validY = false;
for(int i = 0;i<com.length();i++){
char cur = com.charAt(i);
if(cur == 'R'){
RCount++;
}else if(cur == 'L'){
LCount++;
}else if(cur=='U'){
UCount++;
}else{
DCount++;
}
}
/*
System.out.println();
System.out.println("RCount: " + RCount);
System.out.println("LCount: "+LCount);
System.out.println("DCount: "+DCount);
System.out.println("UCount: "+UCount);
System.out.println("X: " + x + " " + "Y: " + y);
*/
if(x>=0&&RCount>=x){
validX = true;
}
if(x<=0&&LCount>=-x){
validX = true;
}
if(y>=0&&UCount>=y){
validY = true;
}
if(y<=0&&DCount>=-y){
validY = true;
}
if(validX&&validY){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
/*
1 0
LDDDLDLDRURURU
10 0
RRRRRRRRRRRRRLLLLLLLLLLLLLDD
*/ | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 8b579c96fdff7c3e726b83c691e2218e | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
import java.lang.Math;
public class SpaceNavigation
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int t=input.nextInt();
for(int i=0;i<t;i++)
{
int x=input.nextInt();
int y=input.nextInt();
input.nextLine();
String s=input.nextLine();
int n=s.length();
int U=0;
int D=0;
int R=0;
int L=0;
for(int j=0;j<n;j++)
{
if(s.charAt(j)=='U')
U++;
else if(s.charAt(j)=='D')
D++;
else if(s.charAt(j)=='R')
R++;
else
L++;
}
if(x>=0 && y>=0)
{
if(R>=Math.abs(x) && U>=Math.abs(y))
System.out.println("YES");
else
System.out.println("NO");
}
else if(x<=0 && y<=0)
{
if(L>=Math.abs(x) && D>=Math.abs(y))
System.out.println("YES");
else
System.out.println("NO");
}
else if(x>=0 && y<=0)
{
if(R>=Math.abs(x) && D>=Math.abs(y))
System.out.println("YES");
else
System.out.println("NO");
}
else
{
if(L>=Math.abs(x) && U>=Math.abs(y))
System.out.println("YES");
else
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 402935c084209db42881fe186215a471 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.lang.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int t=in.nextInt();
int i;
for(i=0;i<t;i++)
{
int n,k,j,x,y;
long u=0,r=0,l=0,d=0;
x=in.nextInt();
y=in.nextInt();
String s=in.next();
for(j=0;j<s.length();j++)
{
if(s.charAt(j)=='U')
{
u++;
}
else if(s.charAt(j)=='D')
{
d--;
}
else if(s.charAt(j)=='L')
{
l--;
}
else
{
r++;
}
}
if(y==0)
{
if((x>0&&r>=x)||(x<0&&l<=x))
System.out.println("YES");
else
System.out.println("NO");
}
else if(x==0)
{
if((y>0&&u>=y)||(y<0&&d<=y))
System.out.println("YES");
else
System.out.println("NO");
}
else if(x>0&&y>0)
{
if(r>=x&&u>=y)
System.out.println("YES");
else
System.out.println("NO");
}
else if(x>0&&y<0)
{
if(r>=x&&d<=y)
System.out.println("YES");
else
System.out.println("NO");
}
else if(x<0&&y>0)
{
if(l<=x&&u>=y)
System.out.println("YES");
else
System.out.println("NO");
}
else
{
if(l<=x&&d<=y)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 636b4792224c4aab48ea09d114edc354 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class solution {
static Scanner scr = new Scanner(System.in);
public static void main(String[] args) {
// TODO Auto-generated method stub
int t=scr.nextInt();
while(t-->0) {
solve();
}
}
static void solve() {
int x=scr.nextInt();
int y=scr.nextInt();
String s=scr.next();
int up=0;
int down=0;
int right=0;
int left=0;
int n=s.length();
for(int i=0;i<n;i++) {
if(s.charAt(i)=='U') {
up++;
}else if(s.charAt(i)=='D') {
down++;
}else if(s.charAt(i)=='R') {
right++;
}else {
left++;
}
}
boolean reachedX=false;
boolean reachedY=false;
if(y>=0 && up>=y) {
reachedY=true;
} if(y<0 && down>=-y) {
reachedY=true;
} if(x>=0 && right>=x){
reachedX=true;
}if(x<0 && left>=-x) {
reachedX=true;
}
if(reachedX==true && reachedY==true) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
class pair{
int x;
int y;
pair(int x,int y){
this.x=x;
this.y=y;
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 581afc63dd99d740eadd79bd00d4a933 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while (t-- > 0) {
int px = scn.nextInt();
int py = scn.nextInt();
String path = scn.next();
int n = path.length();
int[]freq = new int[26];
for(int i=0;i<n;i++) {
char ch = path.charAt(i);
freq[ch-'A']++;
}
int ans = 0;
if(px>=0 && py>=0) {
if(freq['R'-'A']>=px && freq['U'-'A']>=py) {
ans = 1;
}
}else if(px>=0) {
if(freq['R'-'A']>=px && freq['D'-'A']>=Math.abs(py)) {
ans = 1;
}
}else if(py>=0) {
if(freq['L'-'A']>=Math.abs(px) && freq['U'-'A']>=py) {
ans = 1;
}
}else {
if(freq['L'-'A']>=Math.abs(px) && freq['D'-'A']>=Math.abs(py)) {
ans = 1;
}
}
if(ans==1) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | d371352563af4d8213ffeca7907c1044 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class GFG {
public static void main (String[] args) {
// System.out.println("GfG!");
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t>0) {
int x=s.nextInt();
int y=s.nextInt();
String str=s.next();
int xt=0, resx=0;
int yt=0, resy=0;
char a;
for(int i=0;i<str.length();i++) {
a=str.charAt(i);
switch(a) {
case 'U':
if(yt<y) {
yt+=1;
}
break;
case 'D':
if(yt>y) {
yt-=1;
}
break;
case 'L':
if(xt>x) {
xt-=1;
}
break;
case 'R':
if(xt<x) {
xt+=1;
}
break;
default:
break;
}
if(xt==x) resx = x;
if(yt==y) resy = y;
}
if(resx == x && resy == y) {
System.out.println("YES");
} else {
System.out.println("NO");
}
t--;
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 376b3d7266d0cd1e0950af4e0f046f02 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class GFG {
public static void main (String[] args) {
// System.out.println("GfG!");
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t>0) {
int x=s.nextInt();
int y=s.nextInt();
String str = s.next();
// System.out.println(str);
int xt = 0;
int yt = 0;
int resx = 0;
int resy = 0;
for(int i = 0; i<str.length(); i++) {
char a = str.charAt(i);
switch(a) {
case 'U':
if(yt < y) {
yt+=1;
}
// System.out.print(yt);
break;
case 'D':
if(yt > y) {
yt-=1;
}
// System.out.print(yt);
break;
case 'L':
if(xt > x) {
xt-=1;
}
// System.out.print(xt);
break;
case 'R':
if(xt < x) {
xt+=1;
}
// System.out.print(xt);
break;
default :
break;
}
if(xt == x) {
resx = xt;
}
if(yt==y) {
resy = yt;
}
// System.out.print(a + ", ");
}
if(resx == x && resy == y) {
System.out.println("YES");
} else {
System.out.println("NO");
}
t--;
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | f03a436bbc1d4870332730d46d75bb13 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | 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.Random;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws IOException {
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t =sc.nextInt();
while (t-- != 0) {
int px=sc.nextInt(),py=sc.nextInt();
String s=sc.next();
int cl=0,cu=0,cd=0,cr=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='L')
cl++;
else if(s.charAt(i)=='R')
cr++;
else if(s.charAt(i)=='U')
cu++;
else
cd++;
}
int cx=0,cy=0;
if(px>=0 && cr>=px)
cx=1;
if(py>=0 && cu>=py)
cy=1;
if(px<=0 && cl>=Math.abs(px))
cx=1;
if(py<=0 && cd>=Math.abs(py))
cy=1;
if(cx==1 && cy==1)
out.println("YES");
else
out.println("NO");
}
out.close();
}
static void shuffleSort(int[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static void shuffleSort(long[] a) {
Random get = new Random();
for (int i = 0; i < a.length; i++) {
int r = get.nextInt(a.length);
long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | c257509ec3c3e396664e60df815e1b69 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.Scanner;
public class ProblemA {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
for(int i =1 ; i <= testCases; i++) {
int x1 = 0;
int y1 = 0;
int x2 = sc.nextInt();
int y2 = sc.nextInt();
sc.nextLine();
String lang = sc.nextLine();
lang= lang.toUpperCase();
int countfory1inc=0;
int countfory1dec=0;
int countforx1inc=0;
int countforx1dec=0;
for(int j =0 ; j < lang.length() ; j++) {
if(lang.charAt(j) == 'U') {
countfory1inc+=1;
}else if (lang.charAt(j) == 'D') {
countfory1dec+=1;
}else if (lang.charAt(j) == 'R') {
countforx1inc+=1;
}else if(lang.charAt(j) == 'L'){
countforx1dec+=1;
}
}
if(x2==0 && y2==0){
System.out.println("YES");
}else if(x2>0 && y2==0) {
if(countforx1inc>=x2) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(x2==0 && y2>0) {
if(countfory1inc>=y2) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if (x2>0 && y2>0) {
if(countforx1inc>=x2 && countfory1inc>=y2) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(x2<0 && y2==0) {
if(countforx1dec>=(-x2)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(x2==0 && y2<0) {
if(countfory1dec>=(-y2)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(x2<0 && y2<0) {
if(countforx1dec>=(-x2) && countfory1dec>=(-y2)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(x2>0 && y2<0) {
if(countforx1inc>=x2 && countfory1dec>=(-y2)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(x2<0 && y2>0) {
if(countforx1dec>=(-x2) && countfory1inc>=y2) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | f2046e54db608b6d625826990119e42f | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.io.*;
public class A{
public static void main(String args[])throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int test=Integer.parseInt(br.readLine().trim());
while(test-- >0){
String s1[]=br.readLine().trim().split("\\s+");
int x=Integer.parseInt(s1[0]);
int y=Integer.parseInt(s1[1]);
String s=br.readLine().trim();
HashMap<Character, Integer> map=new HashMap<>();
s=s.toUpperCase();
for(int i=0;i<s.length();i++){
if(map.containsKey(s.charAt(i)))
map.replace(s.charAt(i), map.get(s.charAt(i))+1);
else
map.put(s.charAt(i), 1);
}
int ans=1;
if(x!=0){
if(x>0){
if(!map.containsKey('R'))
ans=0;
else if(map.get('R')<x)
ans=0;
}
if(x<0){
if(!map.containsKey('L'))
ans=0;
else if(map.get('L')<Math.abs(x))
ans=0;
}
}
if(y!=0){
if(y>0){
if(!map.containsKey('U'))
ans=0;
else if(map.get('U')<y)
ans=0;
}
if(y<0){
if(!map.containsKey('D'))
ans=0;
else if(map.get('D')<Math.abs(y))
ans=0;
}
}
if(ans==1)
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | a16eee8c5f002fc1e3ed63bdbbe89f4a | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.lang.Math;
public final class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-->0){
int x = sc.nextInt();
int y = sc.nextInt();
String path = sc.next();
int temp_x = 0;
int temp_y = 0;
for(int i = 0; i<path.length(); i++){
char c = path.charAt(i);
if(temp_x != x){
if(x>0 && c == 'R'){
temp_x++;
}else if(x<0 && c =='L'){
temp_x--;
}
}
if(temp_y != y){
if(y>0 && c == 'U'){
temp_y++;
}else if(y<0 && c =='D'){
temp_y--;
}
}
if(x == temp_x && y == temp_y){
break;
}
//System.out.println(temp_x+" "+temp_y);
}
if(x == temp_x && y == temp_y){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 4bc21c09a8bf89fc4baab33215927df8 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import javax.swing.plaf.FontUIResource;
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef {
public static void main(String[] args) throws java.lang.Exception {
out = new PrintWriter(new BufferedOutputStream(System.out));
sc = new FastReader();
int test = sc.nextInt();
for (int t = 0; t < test; t++) {
int x = sc.nextInt();
int y = sc.nextInt();
char[] arr = sc.next().toCharArray();
if (x == 0 && y == 0) {
out.println("YES");
continue;
}
int U = 0, D = 0, R = 0, L = 0;
for(char c : arr) {
if (c == 'U') {
U++;
}
if (c == 'D') {
D++;
}
if (c == 'R') {
R++;
}
if (c == 'L') {
L++;
}
}
if (x >= 0 && y >= 0 && R >= Math.abs(x) && U >= Math.abs(y)) {
out.println("YES");
continue;
}
if (x >= 0 && y <= 0 && R >= Math.abs(x) && D >= Math.abs(y)) {
out.println("YES");
continue;
}
if (x <= 0 && y <= 0 && L >= Math.abs(x) && D >= Math.abs(y)) {
out.println("YES");
continue;
}
if (x <= 0 && y >= 0 && L >= Math.abs(x) && U >= Math.abs(y)) {
out.println("YES");
continue;
}
out.println("NO");
/*
int n = sc.nextInt();
int k = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
boolean ok = true;
for (int i = 1; i < n; i++) {
if (arr[i - 1] < arr[i]) {
ok = false;
}
}
int count = 0;
int max = arr[n - 1];
for (int i = n - 1; i >= 0; i--) {
max = Math.max(max, arr[i]);
count += max - arr[i];
}
if (ok || count < k) {
out.println("-1");
continue;
}
int res = 0;
while (true) {
for (int i = 1; i < n; i++) {
if (arr[i - 1] < arr[i]) {
count -= arr[i] - arr[i - 1];
arr[i - 1] = arr[i];
}
if (count == 0) {
res = i;
ok = true;
break;
}
}
if (ok) {
break;
}
}
out.println(res);
*/
}
out.close();
}
public static FastReader sc;
public static PrintWriter out;
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 1083475dd5481054b02ce4ff65604800 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class Main{
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0; i<t; i++){
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc.next();
int u=0;
int d=0;
int l =0;
int r = 0;
for(int j=0; j<s.length(); j++){
if(s.charAt(j)=='U'){
u++;
}
if(s.charAt(j)=='D'){
d++;
}
if(s.charAt(j)=='L'){
l++;
}
if(s.charAt(j)=='R'){
r++;
}
}
int count =0;
if(x>0){
if(r>=x){
count++;
}
}
else if(x==0){
count++;
}
else{
if(l>=Math.abs(x)){
count++;
}
}
if(y>0){
if(u>=y){
count++;
}
}
else if(y==0){
count++;
}
else{
if(d>=Math.abs(y)){
count++;
}
}
if(count==2){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 12c5495c2c2e6cbd23c01f05c10d522f | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class A_Space_Navigation {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int tc = scn.nextInt();
while(tc-- > 0) {
int v1 = scn.nextInt();
int v2 = scn.nextInt();
String s = scn.next();
int r = 0;
int l = 0;
int d = 0;
int u = 0;
for(int i=0 ; i<s.length() ; i++) {
char ch = s.charAt(i);
if(ch == 'R'){
r++;
} else if(ch == 'D') {
d++;
} else if(ch == 'U') {
u++;
} else if(ch == 'L') {
l++;
}
}
if(v1 >= 0 && v2 >= 0){
if(r >= v1 && u >= v2) {
System.out.println("YES");
} else {
System.out.println("NO");
}
} else if(v1 >= 0 && v2 <= 0){
if(r >= v1 && d >= Math.abs(v2)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
} else if(v1 <= 0 && v2 >= 0){
if(l >= Math.abs(v1) && u >= v2) {
System.out.println("YES");
} else {
System.out.println("NO");
}
} else if(v1 <= 0 && v2 <= 0){
if(l >= Math.abs(v1) && d >= Math.abs(v2)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
scn.close();
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 2ebdc941e18860c8e332a9a88146de4a | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t--!=0){
int px=s.nextInt();
int py=s.nextInt();
String str=s.next();
int cR=0,cU=0,cL=0,cD=0;
for(int i=0;i<str.length();i++){
char ch=str.charAt(i);
if(ch=='R') cR+=1;
else if(ch=='U') cU+=1;
else if(ch=='L') cL+=1;
else if(ch=='D') cD+=1;
}
boolean ans=false;
if(px<=0 && py<=0){
if(cL>=Math.abs(px) && cD>=Math.abs(py)) ans=true;
}else if(px<=0 && py>=0){
if(cL>=Math.abs(px) && cU>=py) ans=true;
}else if(px>=0 && py<=0){
if(cR>=px && cD>=Math.abs(py)) ans=true;
}else{
if(cR>=px && cU>=py) ans=true;
}
System.out.println(ans==true?"YES":"NO");
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 4b5c18b09b64cb4719859f7f38157f38 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
public class Main1 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine().split(" ")[0]);
while (t-->0){
String[] st = br.readLine().split(" ");
int x = Integer.parseInt(st[0]);
int y = Integer.parseInt(st[1]);
String str = br.readLine();
int[] arr = new int[4];
for(char ch : str.toCharArray()){
if(ch == 'U') {
arr[0]+=1;
}
if(ch == 'R') {
arr[1]+=1;
}
if(ch == 'D') {
arr[2]+=1;
}
if(ch == 'L') {
arr[3]+=1;
}
}
if(x>0){
//right
arr[1] = arr[1]-x;
}else if(x<0) {
arr[3] = arr[3]+x;
}
if(y>0) {
arr[0] = arr[0] - y;
}else if(y<0) {
arr[2] = arr[2] +y;
}
boolean flag = false;
for(int i=0; i<arr.length; i++) {
if(arr[i]<0) {
flag=true;
break;
}
}
if(flag==false) {
System.out.println("YES");
flag=false;
}else {
System.out.println("NO");
flag=false;
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 906d335b6563366afaf1a13e459c8f58 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
public class abc {
static PrintWriter pw;
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static boolean isPrime(long n) {
if (n == 2)
return true;
int i = 2;
while (i * i <= n) {
if (n % i == 0)
return false;
i++;
}
return true;
}
public static long[] remove(long n) {
long res[] = new long[1000000000];
long rese = 0;
int i = 0;
while (n > 0) {
long dig = n % 10;
n = n / 10;
if (dig > 0) {
rese = dig;
res[i++] = rese;
}
}
return res;
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static int max(int x, int y) {
return Math.max(x, y);
}
static int min(int x, int y) {
return Math.min(x, y);
}
static int abs(int x) {
return Math.abs(x);
}
static long abs(long x) {
return Math.abs(x);
}
static int log2(int N) {
int result = (int) (Math.log(N) / Math.log(2));
return result;
}
static long max(long x, long y) {
return Math.max(x, y);
}
static long min(long x, long y) {
return Math.min(x, y);
}
public static class pair {
int x;
int y;
public pair(int a, int b) {
x = a;
y = b;
}
}
public static class Comp implements Comparator<pair> {
public int compare(pair a, pair b) {
if (a.x != b.x) {
return a.x - b.x;
} else {
return a.y - b.y;
}
}
}
public static void extract(ArrayList<Integer> ar, int k, int d) {
int c = 0;
for (int i = 1; i < k; i++) {
int x = 0;
boolean dm = false;
while (x > 0) {
long dig = x % 10;
x = x / 10;
if (dig == d) {
dm = true;
break;
}
}
if (dm)
ar.add(i);
}
}
public static void dfs(int index, boolean vis[], int a[], int b[], int n) {
vis[index] = true;
for (int i = 0; i < n; i++) {
if (!vis[i] && (a[i] == a[index] || b[i] == b[index]))
dfs(i, vis, a, b, n);
}
}
public static int countSetBitsUtil(int x) {
if (x <= 0)
return 0;
return (x % 2 == 0 ? 0 : 1) + countSetBitsUtil(x / 2);
}
public static void main(String[] args) {
FastReader ob = new FastReader();
pw = new PrintWriter(System.out);
int t = ob.nextInt();
while (t-- > 0) {
int x = ob.nextInt();
int y = ob.nextInt();
String s=ob.next();
int l=s.length();
int x1=0,y1=0,k=0;
for (int i=0;i<l;i++)
{
char ch=s.charAt(i);
if(x>0 && x!=x1)
{
if(ch=='R')
x1++;
}
if(x<0 && x!=x1)
{
if(ch=='L')
x1--;
}
if(y>0 && y!=y1)
{
if(ch=='U')
y1++;
}
if(y<0 && y!=y1)
{
if(ch=='D')
y1--;
}
}
if(x==x1 && y==y1)
pw.println("YES");
else
pw.println("NO");
}
pw.flush();
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 45e6989b37ea2d99778c159b03a8fc67 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SpaceShip {
public static void main(String[] args) throws IOException {
Reader.init(System.in);
int N= Reader.nextInt();
for (int i=0;i<N;i++){
int x= Reader.nextInt();
int y=Reader.nextInt();
String str= Reader.next();
int up=0;
int down=0;
int Right=0;
int left=0;
boolean flag1=false;
boolean flag2=false;
for (int j=0;j<str.length();j++){
if (str.charAt(j)=='R') Right++;
else if (str.charAt(j)=='L') left++;
else if (str.charAt(j)=='U') up++;
else if (str.charAt(j)=='D') down++;
}
if (x>=0){
if (x-Right <= 0) flag1=true;
}
else if (x<0){
x= x*(-1);
if (x-left <= 0) flag1=true;
}
if (y>=0){
if (y-up <= 0) flag2=true;
}
else if (y<0){
y=y*(-1);
if (y-down <= 0) flag2=true;
}
if (flag1 && flag2) System.out.println("YES");
else System.out.println("NO");
}
}
}
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static long nextLong() throws IOException {
return Long.parseLong( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 6e534b4b48d08a9312464ca73954274a | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | //package recursion;
import java.util.*;
public class PossibleStrings {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- != 0)
{
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc.next();
if(x==0 && y == 0)
{
System.out.println("YES");
continue;
}
if(x>0)
{
int k = 0;
for(int i = 0;i<s.length();i++)
{
if(s.charAt(i) == 'R')
k++;
}
if(k<x)
{
System.out.println("NO");
continue;
}
}
else if(x<0)
{
int k = 0;
for(int i = 0;i<s.length();i++)
{
if(s.charAt(i) == 'L')
k++;
}
if(k<Math.abs(x))
{
System.out.println("NO");
continue;
}
}
if(y>0)
{
int k = 0;
for(int i = 0;i<s.length();i++)
{
if(s.charAt(i) == 'U')
k++;
}
if(k<y)
{
System.out.println("NO");
continue;
}
}
else if(y<0)
{
int k = 0;
for(int i = 0;i<s.length();i++)
{
if(s.charAt(i) == 'D')
k++;
}
if(k<Math.abs(y))
{
System.out.println("NO");
continue;
}
}
System.out.println("YES");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | a2606088b8d6ecb700045f4d777bd069 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class codee21 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
ArrayList<Character> ar = new ArrayList<>();
int testcase = in.nextInt();
for (int t = 0; t < testcase; t++){
int count_R = 0;
int count_U = 0;
int count_L = 0;
int count_D = 0;
int x = in.nextInt();
int y = in.nextInt();
in.nextLine();
String s = in.nextLine();
char c[] = s.toCharArray();
if (x > 0 && y > 0) {
for (int k = 0; k < c.length; k++){
if (c[k] == 'R'){
count_R++;
}else if (c[k] == 'U'){
count_U++;
}
}
if (count_R >= Math.abs(x) && count_U >= Math.abs(y)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
} else if (x < 0 && y < 0) {
for (int a = 0; a < c.length; a++){
if (c[a] == 'L'){
count_L++;
}else if (c[a] == 'D'){
count_D++;
}
}
if (count_L >= Math.abs(x) && count_D >= Math.abs(y)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
} else if (x < 0 && y > 0) {
for (int q = 0; q < c.length; q++){
if (c[q] == 'L'){
count_L++;
}else if (c[q] == 'U'){
count_U++;
}
}
if (count_L >= Math.abs(x) && count_U >= Math.abs(y)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if (x > 0 && y < 0) {
for (int w = 0; w < c.length; w++){
if (c[w] == 'R'){
count_R++;
}else if (c[w] == 'D'){
count_D++;
}
}
if (count_R >= Math.abs(x) && count_D >= Math.abs(y)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
} else if (x == 0 && y > 0) {
for (int r = 0; r < c.length; r++){
if (c[r] == 'U'){
count_U++;
}
}
if (count_U >= Math.abs(y)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if (x == 0 && y < 0) {
for (int z = 0; z < c.length; z++){
if (c[z] == 'D'){
count_D++;
}
}
if (count_D >= Math.abs(y)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if (y == 0 && x < 0) {
for (int e = 0; e < c.length; e++){
if (c[e] == 'L'){
count_L++;
}
}
if (count_L >= Math.abs(x)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if (y == 0 && x > 0) {
for (int g = 0; g < c.length; g++){
if (c[g] == 'R'){
count_R++;
}
}
if (count_R >= Math.abs(x)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 8c042aad984904f8fcc2e1ecae0f394e | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int goalX, goalY;
static int curU, curD, curR, curL;
static boolean[] visit;
static String answer;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringTokenizer st;
for(int tc = 0; tc < T; tc++) {
st = new StringTokenizer(br.readLine(), " ");
goalX = Integer.parseInt(st.nextToken());
goalY = Integer.parseInt(st.nextToken());
curU = 0; curD = 0; curR = 0; curL = 0;
answer = "NO";
String order = br.readLine();
visit = new boolean[order.length()];
solution(order, order.length());
System.out.println(answer);
}
}
static void whereGo(char c) {
switch(c) {
case 'U':
curU++;
break;
case 'D':
curD--;
break;
case 'R':
curR++;
break;
case 'L':
curL--;
break;
}
}
static void solution(String order,int N) {
for(int i = 0; i < N; i++) {
whereGo(order.charAt(i));
}
if(curL <= goalX && curR >= goalX) {
if(curU >= goalY && curD <= goalY) answer = "YES";
}
return;
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | f7554ecd9a8b53835adf8d300f824090 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
int u = 0, d = 0, r = 0, l = 0;
int px = sc.nextInt();
int py = sc.nextInt();
String s = sc.next();
char[] ch = new char[s.length()];
for (int i = 0; i < s.length(); i++) {
ch[i] = s.charAt(i);
}
if (px == 0 && py == 0) {
System.out.println("YES");
} else {
if (px >= 0 && py >= 0) {
for (int i = 0; i < s.length(); i++) {
if (ch[i] == 'U') {
u++;
} else if (ch[i] == 'R') {
r++;
}
}
if (r >= px && u >= py) {
System.out.println("YES");
} else {
System.out.println("NO");
}
} else if (px <= 0 && py <= 0) {
for (int i = 0; i < s.length(); i++) {
if (ch[i] == 'L') {
l--;
} else if (ch[i] == 'D') {
d--;
}
}
if (l <= px && d <= py) {
System.out.println("YES");
} else {
System.out.println("NO");
}
} else if (px >= 0 && py <= 0) {
for (int i = 0; i < s.length(); i++) {
if (ch[i] == 'R') {
r++;
} else if (ch[i] == 'D') {
d--;
}
}
if (r >= px && d <= py) {
System.out.println("YES");
} else {
System.out.println("NO");
}
} else if (px <= 0 && py >= 0) {
for (int i = 0; i < s.length(); i++) {
if (ch[i] == 'L') {
l--;
} else if (ch[i] == 'U') {
u++;
}
}
if (l <= px && u >= py) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 905ab3774a24e7729e5a9049b421b953 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class MainClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=1;i<=T;i++) {int R=0,U=0,D=0,L=0;
int x=sc.nextInt();
int y=sc.nextInt();
String s=sc.next();
for(int j=0;j<s.length();j++) {
if(s.charAt(j)=='R')R++;
else if(s.charAt(j)=='D')D++;
else if(s.charAt(j)=='U')U++;
else if(s.charAt(j)=='L')L++;
}
if(x==0&&y==0)System.out.println("YES");
else if(x==0) {
if(y>0&&U>=y||y<0&&D>=Math.abs(y)) {System.out.println("YES");}
else System.out.println("NO");
}
else if(y==0) {
if(x>0&&R>=x||x<0&&L>=Math.abs(x)) System.out.println("YES");
else System.out.println("NO");
}
else if(x>0&&R>=x||x<0&&L>=Math.abs(x)) {
if(y>0&&U>=y||y<0&&D>=Math.abs(y)) {System.out.println("YES");}
else System.out.println("NO");
}
else System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 1c2daa2c543dfb18f27a67a7736b0017 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.io.*;
import java.util.*;
public class NewClass {
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String in = br.readLine();
int t=Integer.parseInt(in);
while(t-->0){
String num[] = br.readLine().split(" ");
long x = Long.parseLong(num[0]);
long y = Long.parseLong(num[1]);
String st = br.readLine();
long u,d,r,l;
u=l=r=d=0;
boolean ch1,ch2;
ch1=ch2=false;
for(int i=0;i<st.length();i++){
if(st.charAt(i) =='U'){
u++;
}
else if(st.charAt(i)=='D'){
d++;
}
else if(st.charAt(i)=='R'){
r++;
}
else if(st.charAt(i)=='L'){
l++;
}
}
if(y>=0&&u>=y){
ch1=true;
}
else if(y<0&&d>=(-y)){
ch1=true;
}
if(x>=0&&r>=x){
ch2=true;
}
else if(x<0&&l>=(-x)){
ch2=true;
}
if(ch1&&ch2){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 360ffe16839b394bd8f8c36a638d346e | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class A {
public static void main(String[] args) throws Exception {
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(buffer.readLine());
while (t-- > 0) {
String [] inp = buffer.readLine().split(" ");
int px = Integer.parseInt(inp[0]), py = Integer.parseInt(inp[1]);
String s = buffer.readLine();
int l = 0, r = 0, u = 0, d = 0;
for (char ch : s.toCharArray()) {
switch (ch){
case 'L':
l++;
break;
case 'R':
r++;
break;
case 'D':
d++;
break;
case 'U':
u++;
break;
}
}
boolean a = false, b = false;
// sb.append(l+" "+r+" "+d+" "+u).append("\n");
if ((px > 0 && r >= px) || (px < 0 && l >= -px)||px==0)
a = true;
if ((py > 0 && u >= py) || (py < 0 && d >= -py)||py == 0)
b = true;
if (a && b)
sb.append("YES\n");
else
sb.append("NO\n");
}
System.out.println(sb);
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | dc3a35dde028f730c2dc02b001e98b8a | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class experiments
{
static int ans=0;
public static void main(String args[]) throws IOException
{
FastScanner fs = new FastScanner();
int T = fs.nextInt();
outer : while (T-- > 0) {
int a = fs.nextInt(),b = fs.nextInt();
int arr[] = new int[4];
String s = fs.next();
for(int i=0;i<s.length();i++) {
if(s.charAt(i) == 'U') arr[0]++;
else if (s.charAt(i) == 'D') arr[1]++;
else if (s.charAt(i) == 'R') arr[2]++;
else arr[3]++;
}
boolean check = false;
if(a>=0)
check = (arr[2] >= a);
if(a<0)
check = (arr[3] >= -a);
if(b<=0) check = check && (arr[1] >= -b);
if(b>0) check = check && (arr[0] >= b);
System.out.println(check ? "YES" : "NO");
}
}
static final Random random = new Random();
static void ruffleSort(int arr[])
{
int n = arr.length;
for(int i=0; i<n; i++)
{
int j = random.nextInt(n),temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
Arrays.sort(arr);
}
static class Pairs implements Comparable<Pairs>
{
int value,index;
Pairs(int value, int index)
{
this.value = value;
this.index = index;
}
public int compareTo(Pairs p)
{
return Integer.compare(value,p.value);
}
}
}
class FastScanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer str = new StringTokenizer("");
String next() throws IOException
{
while(!str.hasMoreTokens())
str = new StringTokenizer(br.readLine());
return str.nextToken();
}
char nextChar() throws IOException {
return next().charAt(0);
}
int nextInt() throws IOException
{
return Integer.parseInt(next());
}
float nextfloat() throws IOException
{
return Float.parseFloat(next());
}
double nextDouble() throws IOException
{
return Double.parseDouble(next());
}
long nextLong() throws IOException
{
return Long.parseLong(next());
}
byte nextByte() throws IOException
{
return Byte.parseByte(next());
}
int [] arrayIn(int n) throws IOException
{
int arr[] = new int[n];
for(int i=0; i<n; i++)
{
arr[i] = nextInt();
}
return arr;
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | a4f500aeac248e80fbbf7e8d0c501d85 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | //package credit;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main{
static boolean v[];
static int ans[];
int size[];
static int count=0;
static int dsu=0;
static int c=0;
static int e9=1000000007;
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
long max1=Long.MIN_VALUE;
long min1=Long.MAX_VALUE;
boolean aBoolean=true;
boolean y=false;
long m=0;
static boolean t1=false;
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
int parent[];
int rank[];
int n=0;
/*
100000
*/
ArrayList<ArrayList<Integer>> arrayLists;
boolean v1[];
static boolean t2=false;
boolean r=false;
int fib[];
int fib1[];
int min3=Integer.MAX_VALUE;
public static void main(String[] args) throws IOException {
Main g = new Main();
g.go();
}
public void go() throws IOException {
FastReader scanner=new FastReader();
// Scanner scanner = new Scanner(System.in);
// BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
// String s;
PrintWriter printWriter = new PrintWriter(System.out);
int t=scanner.nextInt();
for (int i = 0; i < t; i++) {
int x=scanner.nextInt();
int y=scanner.nextInt();
String s=scanner.next();
int fx=0;
int fy=0;
int u=0;
int d=0;
int r=0;
int l=0;
for (int j = 0; j < s.length(); j++) {
if(s.charAt(j)=='R'){
r++;
fx++;
}else if(s.charAt(j)=='L'){
l++;
fx--;
}else if(s.charAt(j)=='U'){
u++;
fy++;
}else{
d++;
fy--;
}
}
// System.out.println(fx+" "+fy);
boolean e=true;
if(fx==x&&fy==y){
printWriter.println("YES");
}else{
if(fx>x){
int a=fx-x;
if(a>r){
printWriter.println("NO");
e=false;
}else{
r-=a;
}
}else if(fx<x){
int a=x-fx;
if(a>l){
printWriter.println("NO");
e=false;
}else{
l-=a;
}
}if(y>fy&&e){
int a=y-fy;
if(a>d){
printWriter.println("NO");
e=false;
}else{
d-=a;
}
}else if(fy>y&&e){
int a=fy-y;
if(a>u){
printWriter.println("NO");
e=false;
}else{
u-=a;
}
}
if(e)
printWriter.println("YES");
}
}
printWriter.flush();
}
static final int mod=1_000_000_007;
public long mul(long a, long b) {
return a*b;
}
public long fact(int x) {
long ans=1;
for (int i=2; i<=x; i++) ans=mul(ans, i);
return ans;
}
public long fastPow(long base, long exp) {
if (exp==0) return 1;
long half=fastPow(base, exp/2);
if (exp%2==0) return mul(half, half);
return mul(half, mul(half, base));
}
public long modInv(long x) {
return fastPow(x, mod-2);
}
public long nCk(int n, int k) {
return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n-k))));
}
public void sieve(int n){
fib=new int[n+1];
fib[1]=-1;
fib[0]=-1;
for (int i =2; i*i<=n; i++) {
if(fib[i]==0)
for (int j =i*i; j <=n; j+=i){
fib[j]=-1;
// System.out.println("l");
}
}
}
public void parent(int n){
for (int i = 0; i < n; i++) {
parent[i]=i;
rank[i]=1;
size[i]=1;
}
}
public void union(int i,int j){
int root1=find(i);
int root2=find(j);
// if(root1 != root2) {
// parent[root2] = root1;
//// sz[a] += sz[b];
// }
if(root1==root2){
return;
}
if(rank[root1]>rank[root2]){
parent[root2]=root1;
size[root1]+=size[root2];
}
else if(rank[root1]<rank[root2]){
parent[root1]=root2;
size[root2]+=size[root1];
}
else{
parent[root2]=root1;
rank[root1]+=1;
size[root1]+=size[root2];
}
}
public int find(int p){
if(parent[p]!=p){
parent[p]=find(parent[p]);
}
return parent[p];
// if(parent[p]==-1){
// return -1;
// }
// else if(parent[p]==p){
// return p;
// }
// else {
// parent[p]=find(parent[p]);
// return parent[p];
// }
}
public double dist(double x1,double y1,double x2,double y2){
double e=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
double e1=Math.sqrt(e);
return e1;
}
public void make(int p){
parent[p]=p;
rank[p]=1;
}
Random rand = new Random();
public void sort(int[] a, int n) {
for (int i = 0; i < n; i++) {
int j = rand.nextInt(i + 1);
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
Arrays.sort(a, 0, n);
}
public long gcd(long a,long b){
if(b==0){
return a;
}
return gcd(b,a%b);
}
public void dfs(ArrayList<Integer> arrayLists1){
for (int i = 0; i < arrayLists1.size(); i++) {
if(v1[arrayLists1.get(i)]==false){
System.out.println(arrayLists1.get(i));
v1[arrayLists1.get(i)]=true;
count++;
dfs(arrayLists.get(arrayLists1.get(i)));
}
}
}
private void dfs2(ArrayList<Integer>[]arrayList,int j,int count){
ans[j]=count;
for(int i:arrayList[j]){
if(ans[i]==-1){
dfs2(arrayList,i,count);
}
}
}
private void dfs3(ArrayList<Integer>[] arrayList, int j) {
v[j]=true;
count++;
for(int i:arrayList[j]){
if(v[i]==false) {
dfs3(arrayList, i);
}
}
}
public double fact(double h){
double sum=1;
while(h>=1){
sum=(sum%e9)*(h%e9);
h--;
}
return sum%e9;
}
public long primef(double r){
long c=0;
long ans=1;
while(r%2==0){
c++;
r=r/2;
}
if(c>0){
ans*=2;
}
c=0;
// System.out.println(ans+" "+r);
for (int i = 3; i <=Math.sqrt(r) ;i+=2) {
while(r%i==0){
// System.out.println(i);
c++;
r=r/i;
}
if(c>0){
ans*=i;
}
c=0;
}
if(r>2){
ans*=r;
}
return ans;
}
public long divisor(double r){
long c=0;
for (int i = 1; i <=Math.sqrt(r); i++) {
if(r%i==0){
if(r/i==i){
c++;
}
else{
c+=2;
}
}
}
return c;
}
}
class Pair{
int x;
int y;
double z;
public Pair(int x,int y){
this.x=x;
this.y=y;
}
@Override
public int hashCode() {
int hash =27;
return this.x * hash + this.y;
}
@Override
public boolean equals(Object o1){
if(o1==null||o1.getClass()!=this.getClass()){
return false;
}
Pair o=(Pair)o1;
if(o.x==this.x&&o.y==this.y){
return true;
}
return false;
}
}
class Sorting implements Comparator<Pair> {
public int compare(Pair p1,Pair p2){
if(p1.x==p2.x){
return -1*Double.compare(p1.y,p2.y);
}
else {
return Double.compare(p1.x, p2.x);
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | a26099d8fbcf0ea6ef8986ce70864777 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class C {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static FastReader s = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
private static int[] rai(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
return arr;
}
private static int[][] rai(int n, int m) {
int[][] arr = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = s.nextInt();
}
}
return arr;
}
private static long[] ral(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = s.nextLong();
}
return arr;
}
private static long[][] ral(int n, int m) {
long[][] arr = new long[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = s.nextLong();
}
}
return arr;
}
private static int ri() {
return s.nextInt();
}
private static long rl() {
return s.nextLong();
}
private static String rs() {
return s.next();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader sc=new FastReader();
int t,n,i,j,k,c=0,sum=0,a,b,x,y,r=0,l=0,u=0,d=0,fg=0,min=Integer.MAX_VALUE,max=Integer.MIN_VALUE,avg;
String str,st;
BigInteger f=BigInteger.valueOf(1);
t=sc.nextInt();
while(t-->0)
{
x=sc.nextInt();
y=sc.nextInt();
str=sc.next();
for(i=0;i<str.length();i++)
if(str.charAt(i)=='R')
r++;
else if(str.charAt(i)=='L')
l++;
else if(str.charAt(i)=='U')
u++;
else
d++;
if(x<0)
{
if(l+x>=0)
x=0;
}
else
{
if(x-r<=0)
x=0;
}
if(y<0)
{
if(d+y>=0)
y=0;
}
else
{
if(y-u<=0)
y=0;
}
if(x==0&&y==0)
System.out.println("YES");
else
System.out.println("NO");
r=l=u=d=0;
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 0c067e3c18233fa4fb4e2087c47c7d26 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int testCases = sc.nextInt();
for (int t = 0; t < testCases; t++) {
int px = sc.nextInt();
int py = sc.nextInt();
String str = sc.next();
char c[] = str.toCharArray();
int n = c.length;
int x = 0;
int y = 0;
int l = 0;
int r = 0;
int u = 0;
int d = 0;
for (int i = 0; i < n; i++) {
char cur = c[i];
if (cur == 'R') {
x++;
r++;
} else if (cur == 'L') {
x--;
l++;
} else if (cur == 'U') {
y++;
u++;
} else {
y--;
d++;
}
}
int disx = x - px;
int disy = y - py;
boolean poss = true;
if (x != px) {
if ((l + r) < Math.abs(disx)) {
poss = false;
}
if (px < 0) {
if (l < Math.abs(px)) {
poss = false;
}
}
if (px > 0) {
if (r < px) {
poss = false;
}
}
}
if (y != py) {
if ((u + d) < Math.abs(disy)) {
poss = false;
}
if (py < 0) {
if (d < Math.abs(py)) {
poss = false;
}
}
if (py > 0) {
if (u < py) {
poss = false;
}
}
}
if (poss) {
sb.append("YES").append("\n");
} else {
sb.append("NO").append("\n");
}
}
System.out.print(sb);
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 05e69127b1e7f4aef143d4feca2fdcb3 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class Main implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new Main(), "Main", 1 << 27).start();
}
static class Pair {
int f;
int s;
int p;
PrintWriter w;
// int t;
Pair(int f, int s) {
// Pair(int f,int s, PrintWriter w){
this.f = f;
this.s = s;
// this.p = p;
// this.w = w;
// this.t = t;
}
public static Comparator<Pair> wc = new Comparator<Pair>() {
public int compare(Pair e1, Pair e2) {
// 1 for swap
if (Math.abs(e1.f) - Math.abs(e2.f) != 0) {
// e1.w.println("**"+e1.f+" "+e2.f);
return (Math.abs(e1.f) - Math.abs(e2.f));
} else {
// e1.w.println("##"+e1.f+" "+e2.f);
return (Math.abs(e1.s) - Math.abs(e2.s));
}
}
};
}
public static ArrayList<Integer> sieve(int N) {
int i, j, flag;
ArrayList<Integer> p = new ArrayList<Integer>();
for (i = 1; i < N; i++) {
if (i == 1 || i == 0)
continue;
flag = 1;
for (j = 2; j <= i / 2; ++j) {
if (i % j == 0) {
flag = 0;
break;
}
}
if (flag == 1) {
p.add(i);
}
}
return p;
}
public static long gcd(long a, long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
//// recursive dfs
public static int dfs(int s, ArrayList<Integer>[] a, boolean[] b, int[] pre) {
b[s] = true;
int p = 1;
int n = pre.length - 1;
int t = a[s].size();
int max = 1;
for (int i = 0; i < t; i++) {
int x = a[s].get(i);
if (!b[x]) {
// dist[x] = dist[s] + 1;
int xz = (dfs(x, a, b, pre));
p += xz;
max = Math.max(xz, max);
}
}
// max = Math.max(max,(n-p));
pre[s] = max;
return p;
}
//// iterative BFS
public static void bfs(int s, ArrayList<Integer>[] a, long[] dist, boolean[] b, PrintWriter w) {
b[s] = true;
// int siz = 0;
// dist--;
Queue<Integer> q = new LinkedList<>();
q.add(s);
while (q.size() != 0) {
int i = q.poll();
Iterator<Integer> it = a[i].listIterator();
int z = 0;
while (it.hasNext()) {
z = it.next();
if (!b[z]) {
b[z] = true;
// dist--;
dist[z] = dist[i] + 1;
// siz++;
q.add(z);
}
}
}
// return siz;
}
public static int lower(int key, int[] a) {
int l = 0;
int r = a.length - 1;
int res = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (a[mid] <= key) {
l = mid + 1;
res = mid + 1;
} else {
r = mid - 1;
}
}
return res;
}
public static long power(long x, long y, long m) {
if (y == 0)
return 1;
long p = power(x, y / 2, m) % m;
p = (p * p) % m;
if (y % 2 == 0)
return p;
else
return (x * p) % m;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
// code here
public void run() {
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int defaultValue = 0;
int mod = 1000000007;
int oo = (int) 1e9;
int t = 1;
t = sc.nextInt();
while (t-- > 0) {
int x = sc.nextInt();
int y = sc.nextInt();
char[] a = sc.next().toCharArray();
int n = a.length;
int xx = 0;
int yy = 0;
int u = 0;
int l = 0;
int r = 0;
int d = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 'L') {
xx--;
l++;
} else if (a[i] == 'R') {
xx++;
r++;
} else if (a[i] == 'U') {
yy++;
u++;
} else {
yy--;
d++;
}
}
int xz = xx - x;
int yz = yy - y;
boolean f1 = true;
boolean f2 = true;
// w.println(xx + " " + yy + " " + xz + " " + yz + " " + l + " " + r + " " + u +
// " " + d);
if (xz > 0) {
if (r < xz)
f1 = false;
} else if (xz < 0) {
if (l < (-1 * xz))
f1 = false;
}
if (yz > 0) {
if (u < yz)
f2 = false;
} else if (yz < 0) {
if (d < (-1 * yz))
f2 = false;
}
if (f1 && f2) {
w.println("YES");
} else {
w.println("NO");
}
}
w.flush();
w.close();
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | f316913db5555d47d44580e242de46e1 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0; i<t; i++){
int px = sc.nextInt();
int py = sc.nextInt();
String s = sc.next();
HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
hm.put('U',0);
hm.put('L',0);
hm.put('R',0);
hm.put('D',0);
int x = 0, y = 0;
for(int j=0; j<s.length(); j++){
char z = s.charAt(j);
if(z=='R'){
x++;
} else if(z=='L'){
x--;
} else if (z=='U'){
y++;
} else {
y--;
}
hm.put(z,hm.get(z)+1);
}
int dfx = x-px;
int dfy = y-py;
String ans = "YES";
if(dfx>0&&hm.get('R')<dfx){
ans = "NO";
}
if(dfx<0&&hm.get('L')<Math.abs(dfx)){
ans = "NO";
}
if(dfy>0&&hm.get('U')<dfy){
ans = "NO";
}
if(dfy<0&&hm.get('D')<Math.abs(dfy)){
ans = "NO";
}
System.out.println(ans);
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 6e11022138ecb386e2bd9ceeaee194ff | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import java.lang.*;
public class Codeforces {
static Scanner sr = new Scanner(System.in);
static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main(String[] args) throws java.lang.Exception {
int T = sr.nextInt();
while (T-- > 0) {
long x=sr.nextLong();
long y=sr.nextLong();
String s=sr.next();
long u=0,d=0,l=0,r=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='R')
++r;
else if(s.charAt(i)=='L')
++l;
else if(s.charAt(i)=='U')
++u;
else if(s.charAt(i)=='D')
++d;
}
int p=0,q=0;
if(y>0)
{
if(u>=y)
p=1;
}
else
{
if(d>=Math.abs(y))
p=1;
}
if(x>0)
{
if(r>=x)
q=1;
}
else
{
if(l>=Math.abs(x))
q=1;
}
if(p==1&&q==1)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | a0aed9db03e112e623d5362c480a7add | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.*;
/**
* 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();
int testNum = in.nextInt();
solver.solve(testNum, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
for (int z = 0; z < testNumber; z++) {
int px = in.nextInt();
int py = in.nextInt();
String s = in.next();
int up = 0;
int right = 0;
int left = 0;
int down = 0;
for (int i= 0; i < s.length(); i++) {
if (s.charAt(i) == 'U') {
up++;
}
if (s.charAt(i) == 'R') {
right++;
}
if (s.charAt(i) == 'L') {
left++;
}
if (s.charAt(i) == 'D') {
down++;
}
}
boolean xWorks = false;
boolean yWorks = false;
if (py >= 0 && up >= py) {
yWorks = true;
}
if (py < 0 && down >= -1 * py) {
yWorks = true;
}
if (px >= 0 && right >= px) {
xWorks = true;
}
if (px < 0 && left >= -1 * px) {
xWorks = true;
}
if (xWorks && yWorks) {
out.println("Yes");
} else {
out.println("No");
}
}
}
}
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 | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 7b77336616d9807a26fee69ed4469cae | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class CodeForce {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int testCases = in.nextInt();
in.nextLine();
int x, y;
String str;
for(int t = 1; t <= testCases; t ++) {
x = in.nextInt();
y = in.nextInt();
in.nextLine();
str = in.nextLine();
int xCount = 0;
int yCount = 0;
boolean xCorrect = false;
boolean yCorrect = false;
if(x > 0) {
for(int i = 0; i < str.length(); i ++) {
if(str.charAt(i) == 'R') {
xCount++;
}
}
} else if(x < 0) {
for(int i = 0; i < str.length(); i ++) {
if(str.charAt(i) == 'L') {
xCount++;
}
}
} else {
xCorrect = true;
}
if(y > 0) {
for(int i = 0; i < str.length(); i ++) {
if(str.charAt(i) == 'U') {
yCount ++;
}
}
} else if(y < 0) {
for(int i = 0; i < str.length(); i ++) {
if(str.charAt(i) == 'D') {
yCount++;
}
}
} else {
yCorrect = true;
}
if(xCount >= Math.abs(x)) {
xCorrect = true;
}
if(yCount >= Math.abs(y)) {
yCorrect = true;
}
if(xCorrect && yCorrect) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 1f71d0cbf2ed6139ec22296ab7af23b6 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.* ;
public class SpaceNavigation{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
int t = sc.nextInt() ;
while(t-- > 0) {
int X = sc.nextInt() ;
int Y = sc.nextInt() ;
String s = sc.next() ;
//finding the parameters required to reach the destination
int R,L,U,D ;
R = L = U = D = 0 ;
for(int i = 0; i < s.length(); ++i) {
if(s.charAt(i) == 'R') ++R ;
if(s.charAt(i) == 'L') ++L ;
if(s.charAt(i) == 'U') ++U ;
if(s.charAt(i) == 'D') ++D ;
}
boolean hFlag,yFlag ;
hFlag = yFlag = false ;
if(X < 0) if(L >= -1 * X) hFlag = true ;
if(X >= 0) if(R >= X) hFlag = true ;
if(Y < 0) if(D >= -1 * Y) yFlag = true ;
if(Y >= 0) if(U >= Y) yFlag = true ;
if(yFlag && hFlag) System.out.println("YES") ;
else System.out.println("NO") ;
}
return ;
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 8f76c7c562eecb4e18c2ee6aa1b35210 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class a1
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int cases = sc.nextInt();
for(int i=0; i<cases; i++)
{
int x = sc.nextInt();
int y = sc.nextInt();
StringBuilder sbl = new StringBuilder(sc.next());
int uu = 0, dd = 0, ll = 0, rr=0;
for(int k=0; k<sbl.length(); k++)
{
if(sbl.charAt(k) == 'U') uu++;
else if(sbl.charAt(k) == 'D') dd++;
else if(sbl.charAt(k) == 'L') ll++;
else rr++;
}
if((x>=0 && y>=0 && rr>=x && uu>=y) || (x>=0 && y<=0 && rr>=x && dd>=Math.abs(y)) ||
(x<=0 && y>=0 && ll>=Math.abs(x) && uu>=y) || (x<=0 && y<=0 && ll>=Math.abs(x) && dd>=Math.abs(y)))
{
System.out.println("YES");
}else
{
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 60f6413386e9662e5ed2bef3eb9ded5a | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main (String[] args){
Scanner input = new Scanner(System.in);
int t = input.nextInt();
while(t-->0)
{
int x = input.nextInt();
int y = input.nextInt();
int l = 0 ,d = 0 , u = 0 , r = 0;
String s = input.next();
for(int i = 0 ; i < s.length() ;i++)
{
if(s.charAt(i)=='R')
r++;
else if(s.charAt(i)=='L')
l--;
else if(s.charAt(i)=='U')
u++;
else
d--;
}
if(l<=x && r>=x && d<=y && u>=y)
System.out.println("YES");
else
System.out.println("NO");
}
// your code goes here
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 88d310708d72d67befc1468a8a49fd3e | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.*;
public class ispcff {
public static void main(String[] args) throws java.lang.Exception {
ispcff.FastReader sc =new FastReader();
int t = sc.nextInt();
for (int i =0;i<t;i++) {
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc .next(); int arr[]= new int [4]; int count=0;
for (int e=0;e<s.length();e++) {
if(s.charAt(e)=='D') {
arr[0]++;
}
else if (s.charAt(e)=='U') {
arr[1]++;
}
else if (s.charAt(e)=='L') {
arr[2]++;
}
else if (s.charAt(e)=='R') {
arr[3]++;
}
}
// System.out.println(arr[0]+" "+arr[1]+" "+arr[2]+" "+arr[3]);
if(x>0) {
if(arr[3]>=x) {
count++;
}
}
else if (x<0) {
if(arr[2]>=Math.abs(x)) {
count++;
}
}
if (y>0) {
if(arr[1]>=y) {
count++;
}
}
else if (y<0) {
if(arr[0]>=Math.abs(y)) {
count++;
}
}
if(x==0||y==0) {
count++;
}
if(count>=2) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
float nextFloat()
{
return Float.parseFloat(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
public static int[] radixSort2(int[] a)
{
int n = a.length;
int[] c0 = new int[0x101];
int[] c1 = new int[0x101];
int[] c2 = new int[0x101];
int[] c3 = new int[0x101];
for(int v : a) {
c0[(v&0xff)+1]++;
c1[(v>>>8&0xff)+1]++;
c2[(v>>>16&0xff)+1]++;
c3[(v>>>24^0x80)+1]++;
}
for(int i = 0;i < 0xff;i++) {
c0[i+1] += c0[i];
c1[i+1] += c1[i];
c2[i+1] += c2[i];
c3[i+1] += c3[i];
}
int[] t = new int[n];
for(int v : a)t[c0[v&0xff]++] = v;
for(int v : t)a[c1[v>>>8&0xff]++] = v;
for(int v : a)t[c2[v>>>16&0xff]++] = v;
for(int v : t)a[c3[v>>>24^0x80]++] = v;
return a;
}
static void reverse_sorted(int[] arr)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<arr.length;i++)
{
list.add(arr[i]);
}
Collections.sort(list , Collections.reverseOrder());
for(int i=0;i<arr.length;i++)
{
arr[i] = list.get(i);
}
}
static int LowerBound(int a[], int x) { // x is the target value or key
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
static int UpperBound(ArrayList<Integer> list, int x) {// x is the key or target value
int l=-1,r=list.size();
while(l+1<r) {
int m=(l+r)>>>1;
if(list.get(m)<=x) l=m;
else r=m;
}
return l+1;
}
public static HashMap<String, Integer> sortByValue(HashMap<String, Integer> hm)
{
// Create a list from elements of HashMap
List<Map.Entry<String, Integer> > list =
new LinkedList<Map.Entry<String, Integer> >(hm.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<String, Integer> >() {
public int compare(Map.Entry<String, Integer> o1,
Map.Entry<String, Integer> o2)
{
return (o1.getValue()).compareTo(o2.getValue());
}
});
// put data from sorted list to hashmap
HashMap<String, Integer> temp = new LinkedHashMap<String, Integer>();
for (Map.Entry<String, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp;
}
static class Queue_Pair implements Comparable<Queue_Pair> {
int first , second;
public Queue_Pair(int first, int second) {
this.first=first;
this.second=second;
}
public int compareTo(Queue_Pair o) {
return Integer.compare(o.first, first);
}
}
static void leftRotate(int arr[], int d, int n)
{
for (int i = 0; i < d; i++)
leftRotatebyOne(arr, n);
}
static void leftRotatebyOne(int arr[], int n)
{
int i, temp;
temp = arr[0];
for (i = 0; i < n - 1; i++)
arr[i] = arr[i + 1];
arr[n-1] = temp;
}
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning
// and the end of the string
int i = 0, j = str.length() - 1;
// While there are characters to compare
while (i < j) {
// If there is a mismatch
if (str.charAt(i) != str.charAt(j))
return false;
// Increment first pointer and
// decrement the other
i++;
j--;
}
// Given string is a palindrome
return true;
}
static boolean palindrome_array(char arr[], int n)
{
// Initialise flag to zero.
int flag = 0;
// Loop till array size n/2.
for (int i = 0; i <= n / 2 && n != 0; i++) {
// Check if first and last element are different
// Then set flag to 1.
if (arr[i] != arr[n - i - 1]) {
flag = 1;
break;
}
}
// If flag is set then print Not Palindrome
// else print Palindrome.
if (flag == 1)
return false;
else
return true;
}
static boolean allElementsEqual(long[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
static boolean allElementsDistinct(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]!=arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
public static void reverse(int[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
int temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
public static void reverse_Long(long[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
long temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
static boolean isSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static boolean isReverseSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] < a[i + 1]) {
return false;
}
}
return true;
}
static int[] rearrangeEvenAndOdd(int arr[], int n)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
int[] array = list.stream().mapToInt(i->i).toArray();
return array;
}
static long[] rearrangeEvenAndOddLong(long arr[], int n)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
long[] array = list.stream().mapToLong(i->i).toArray();
return array;
}
static boolean isPrime(long n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (long i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static long getSum(long n)
{
long sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcdLong(long a, long b)
{
if (b == 0)
return a;
return gcdLong(b, a % b);
}
static void swap(int i, int j)
{
int temp = i;
i = j;
j = temp;
}
static int countDigit(int n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
//Arrays.sort(arr, Comparator.comparingDouble(o -> o[0]));
// q.replace(i, i+1, "4");
// StringBuilder q = new StringBuilder(w);
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 84d6afe9ad38aa021976e8c3fdf15b8d | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class Space_Navigation_699A {
public static void main(String[] args)
{
Scanner Sc = new Scanner(System.in);
int test_cases = Sc.nextInt();
while(test_cases-- != 0)
{
int planetforces_x_position = Sc.nextInt();
int planetforces_y_position = Sc.nextInt();
String s = Sc.next();
int U = 0, D = 0, L = 0,R = 0;
for(char c : s.toCharArray())
{
if(c == 'U') U++;
else if(c == 'D') D++;
else if(c == 'R') R++;
else L++;
}
int flag = 0;
if(planetforces_x_position == 0)
flag++;
else if(planetforces_x_position > 0 && R >= planetforces_x_position)
flag++;
else if(planetforces_x_position < 0 && L >= -planetforces_x_position)
flag++;
if(planetforces_y_position == 0)
flag++;
else if(planetforces_y_position > 0 && U >= planetforces_y_position)
flag++;
else if(planetforces_y_position < 0 && D >= -planetforces_y_position)
flag++;
if(flag == 2)
System.out.println("YES");
else
System.out.println("NO");
}
Sc.close();
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 3ccae7a6cb4d616c99d445bd75631186 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
static FastScanner sc;
static PrintWriter pw;
public static void main(String[] args) throws Exception{
sc = new FastScanner();
pw = new PrintWriter(System.out);
try{
int T = sc.ni();
while(T-->0){
int x = sc.ni();
int y = sc.ni();
String s = sc.nextLine();
int left = 0;
int right = 0;
int up = 0;
int down = 0;
for(int i=0; i<s.length(); i++){
if(s.charAt(i)=='U'){
up++;
}else if(s.charAt(i)=='D'){
down--;
}else if(s.charAt(i)=='L'){
left--;
}else if(s.charAt(i)=='R'){
right++;
}
}
boolean possible = false;
if(x>=0 && y>=0){
if(x<=right && y <=up){
possible = true;
}
}else if(x<=0 && y>=0){
if(x>=left && y<=up){
possible = true;
}
}else if(x<=0 && y<=0){
if(x>=left && y>=down){
possible = true;
}
}else{
if(x<=right && y>=down){
possible = true;
}
}
if(possible){
pw.println("YES");
}else{
pw.println("NO");
}
}
}catch(Exception e){
return;
}
pw.close();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in), 32768);
st = null;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
int[] intArray(int N) {
int[] ret = new int[N];
for (int i = 0; i < N; i++)
ret[i] = ni();
return ret;
}
long nl() {
return Long.parseLong(next());
}
long[] longArray(int N) {
long[] ret = new long[N];
for (int i = 0; i < N; i++)
ret[i] = nl();
return ret;
}
double nd() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 24869da52ee386a1ca75222248b4aa2d | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.*;
public class Codeforces {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
o:while(cases-- > 0) {
String[] str = br.readLine().split(" ");
int x = Integer.parseInt(str[0]);
int y = Integer.parseInt(str[1]);
String s = br.readLine();
int u = 0, d = 0, r = 0, l = 0;
for(int i=0; i<s.length(); i++) {
char ch = s.charAt(i);
if(ch == 'U') {
u++;
}else if(ch == 'D') {
d++;
}else if(ch == 'R') {
r++;
}else {
l++;
}
}
boolean ans = false;
if(x >= 0 && y >= 0) {
ans = u >= y && r >= x;
}
if(x <= 0 && y >= 0) {
ans = u >= y && l >= -1*x;
}
if(x >= 0 && y <= 0) {
ans = d >= -1*y && r >= x;
}
if(x <= 0 && y <= 0) {
ans = d >= -1*y && l >= -1*x;
}
if(ans) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | dc1d7c5e177bfd2befb3de2914e2e0bf | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class A_Space_Navigation
{
public static void main (String[] args) throws java.lang.Exception
{
FastReader sc =new FastReader();
int t=sc.nextInt();
while(t-->0)
{
int a=sc.nextInt();
int b=sc.nextInt();
String s=sc.next();
int sum=a+b;
int l=s.length();
char c[]=s.toCharArray();
int u=0,d=0,r=0,m=0;
if(l<sum){
System.out.println("NO");
}
else{
for(int i=0;i<c.length;i++){
if(c[i]=='U'){
u++;
}
else if(c[i]=='D'){
d++;
}
else if(c[i]=='R'){
r++;
}
else if(c[i]=='L'){
m++;
}
}
//|| m>=a && d>=b || r>=a && u>=b || m>=a && u>=b
//System.out.println(u+" "+d+" "+r+" "+m);
if(a>=0 && b>=0 && r>=Math.abs(a) && u>=Math.abs(b)){
System.out.println("YES");
}
else if(a>=0 && b<=0 && r>=Math.abs(a) && d>=Math.abs(b)){
System.out.println("YES");
}
else if(a<=0 && b<=0 && m>=Math.abs(a) && d>=Math.abs(b)){
System.out.println("YES");
}
else if(a<=0 && b>=0 && m>=Math.abs(a) && u>=Math.abs(b)){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
float nextFloat()
{
return Float.parseFloat(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readArrayLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
}
public static int[] radixSort2(int[] a)
{
int n = a.length;
int[] c0 = new int[0x101];
int[] c1 = new int[0x101];
int[] c2 = new int[0x101];
int[] c3 = new int[0x101];
for(int v : a) {
c0[(v&0xff)+1]++;
c1[(v>>>8&0xff)+1]++;
c2[(v>>>16&0xff)+1]++;
c3[(v>>>24^0x80)+1]++;
}
for(int i = 0;i < 0xff;i++) {
c0[i+1] += c0[i];
c1[i+1] += c1[i];
c2[i+1] += c2[i];
c3[i+1] += c3[i];
}
int[] t = new int[n];
for(int v : a)t[c0[v&0xff]++] = v;
for(int v : t)a[c1[v>>>8&0xff]++] = v;
for(int v : a)t[c2[v>>>16&0xff]++] = v;
for(int v : t)a[c3[v>>>24^0x80]++] = v;
return a;
}
static boolean isPalindrome(String str)
{
// Pointers pointing to the beginning
// and the end of the string
int i = 0, j = str.length() - 1;
// While there are characters to compare
while (i < j) {
// If there is a mismatch
if (str.charAt(i) != str.charAt(j))
return false;
// Increment first pointer and
// decrement the other
i++;
j--;
}
// Given string is a palindrome
return true;
}
static boolean palindrome_array(int arr[], int n)
{
// Initialise flag to zero.
int flag = 0;
// Loop till array size n/2.
for (int i = 0; i <= n / 2 && n != 0; i++) {
// Check if first and last element are different
// Then set flag to 1.
if (arr[i] != arr[n - i - 1]) {
flag = 1;
break;
}
}
// If flag is set then print Not Palindrome
// else print Palindrome.
if (flag == 1)
return false;
else
return true;
}
static boolean allElementsEqual(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
static boolean allElementsDistinct(int[] arr,int n)
{
int z=0;
for(int i=0;i<n-1;i++)
{
if(arr[i]!=arr[i+1])
{
z++;
}
}
if(z==n-1)
{
return true;
}
else
{
return false;
}
}
public static void reverse(int[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
int temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
public static void reverse_Long(long[] array)
{
// Length of the array
int n = array.length;
// Swaping the first half elements with last half
// elements
for (int i = 0; i < n / 2; i++) {
// Storing the first half elements temporarily
long temp = array[i];
// Assigning the first half to the last half
array[i] = array[n - i - 1];
// Assigning the last half to the first half
array[n - i - 1] = temp;
}
}
static boolean isSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] > a[i + 1]) {
return false;
}
}
return true;
}
static boolean isReverseSorted(int[] a)
{
for (int i = 0; i < a.length - 1; i++)
{
if (a[i] < a[i + 1]) {
return false;
}
}
return true;
}
static int[] rearrangeEvenAndOdd(int arr[], int n)
{
ArrayList<Integer> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
int[] array = list.stream().mapToInt(i->i).toArray();
return array;
}
static long[] rearrangeEvenAndOddLong(long arr[], int n)
{
ArrayList<Long> list = new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]%2==0)
{
list.add(arr[i]);
}
}
for(int i=0;i<n;i++)
{
if(arr[i]%2!=0)
{
list.add(arr[i]);
}
}
int len = list.size();
long[] array = list.stream().mapToLong(i->i).toArray();
return array;
}
static boolean isPrime(long n)
{
// Check if number is less than
// equal to 1
if (n <= 1)
return false;
// Check if number is 2
else if (n == 2)
return true;
// Check if n is a multiple of 2
else if (n % 2 == 0)
return false;
// If not, then just check the odds
for (long i = 3; i <= Math.sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
static int getSum(int n)
{
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcdLong(long a, long b)
{
if (b == 0)
return a;
return gcdLong(b, a % b);
}
static void swap(int[] arr, int i, int j)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int countDigit(long n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
static int sumFromString(String s){
int sum = 0;
for(int i = 0; i < s.length() ; i++){
if( Character.isDigit(s.charAt(i)) ){
sum = sum + Character.getNumericValue(s.charAt(i));
}
}
return sum;
}
static int [] freqCounter(int arr[]){
int [] fr = new int [arr.length];
int [] fi=new int [arr.length];
int visited = -1;
for(int i = 0; i < arr.length; i++){
int count = 1;
for(int j = i+1; j < arr.length; j++){
if(arr[i] == arr[j]){
count++;
//To avoid counting same element again
fr[j] = visited;
}
}
if(fr[i] != visited)
fr[i] = count;
}
for(int i = 0; i < fr.length; i++){
if(fr[i] != visited)
fi[i]=fr[i];
}
return fi;
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 6b21de0da2cc84c84dae527cdb83335a | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.*;
public class spaceNavigation {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
public FastReader(String file_name)throws IOException
{
br = new BufferedReader(
new FileReader(file_name));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] nextArray(int n){
int ar[] = new int[n];
for(int i=0;i<n;i++)
ar[i] = this.nextInt();
return (ar);
}
}
static class OutputWriter{
BufferedWriter writer;
public OutputWriter(OutputStream stream){
writer = new BufferedWriter(new OutputStreamWriter(stream));
}
public OutputWriter(String file_name) throws IOException{
writer = new BufferedWriter(new FileWriter("output.txt"));
}
public void print(int i) throws IOException {
writer.write(i);
}
public void print(String s) throws IOException {
writer.write(s);
}
public void print(char []c) throws IOException {
writer.write(c);
}
public void println(int i) throws IOException {
writer.write(i+"\n");
}
public void println(long i) throws IOException {
writer.write(i+"\n");
}
public void println(String s) throws IOException {
writer.write(s+"\n");
}
public void println(char []c) throws IOException {
writer.write(c+"\n");
}
public void close() throws IOException {
writer.close();
}
}
public static long gcd(long a,long b){
return(a==0?b:gcd(b%a,a));
}
public static long lcm(long a,long b){
//return (a*b)/gcd(a,b);
//this is modified to avoid integer overflow by multiplying a*b
return((a/gcd(a,b))*b);
}
public static void initialize_io_redirection()throws IOException{
try{
boolean MP = System.getProperty("MY_PC")!=null;
if(MP){
fs = new FastReader("input.txt");
op = new OutputWriter("output.txt");
System.setOut(new PrintStream(new File("output.txt")));
}
else{
fs = new FastReader();
op = new OutputWriter(System.out);
}
}
catch(Exception e){
fs = new FastReader();
op = new OutputWriter(System.out);
}
}
static FastReader fs;
static OutputWriter op;
public static void main(String[] args)throws IOException{
initialize_io_redirection();
int t = fs.nextInt();
while(t-- > 0)
solve();
op.close();
}
public static void solve()throws IOException{
long x=fs.nextLong(),y=fs.nextLong();
String st = fs.nextLine();
int rc=0,lc=0,uc=0,dc=0;
for(int i=0;i<st.length();i++){
char ch=st.charAt(i);
switch(ch){
case 'R':
rc++;
break;
case 'L':
lc++;
break;
case 'D':
dc++;
break;
case 'U':
uc++;
break;
}
}
boolean done=false;
if(x>0 && y>0)
done = (rc>=Math.abs(x))&&(uc>=Math.abs(y));
if(x<0 && y>0)
done = (lc>=Math.abs(x))&&(uc>=Math.abs(y));
if(x<0 &&y<0)
done = (lc>=Math.abs(x))&&(dc>=Math.abs(y));
if(x>0 && y<0)
done=(rc>=Math.abs(x))&&(dc>=Math.abs(y));
if(x==0){
if(y<0)
done = dc>=Math.abs(y);
else
done=uc>=Math.abs(y);
}
if(y==0){
if(x<0)
done = lc>=Math.abs(x);
else
done=rc>=Math.abs(x);
}
System.out.println(done?"YES":"NO");
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | a05c53af78daeb14ed418bdf72a153e9 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class cordinate_reach {
public static void main(String[] args) {
int testcase ;
Scanner input=new Scanner(System.in) ;
testcase= input.nextInt() ;
for(int j=0;j<testcase;j++)
{
int x,y ;
x=input.nextInt();
y=input.nextInt();
String s=input.next();
int U=0,D=0,R=0,L=0 ;
for(int i=0 ;i<s.length() ;i++)
{
if(s.charAt(i)=='U')
{
U++ ;
}
if(s.charAt(i)=='D')
{
D++ ;
}
if(s.charAt(i)=='R')
{
R++ ;
}
if(s.charAt(i)=='L')
{
L++ ;
}
}
if(x>=-L && x<=R && y>=-D && y<=U)
{
print("YES") ;
}
else
print("NO") ;
}
}
static void print(Object output)
{
System.out.println(output) ;
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | b69a50db870436876b9d9432b28344b3 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
public class Practice {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int x = sc.nextInt(); int y = sc.nextInt();
String s = sc.next();
int rightCount = 0; int leftCount = 0; int upCount = 0; int downCount = 0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='R') rightCount++;
else if(s.charAt(i)=='L') leftCount++;
else if(s.charAt(i)=='U') upCount++;
else if(s.charAt(i)=='D') downCount++;
}
boolean xpos = false; boolean ypos = false;
if((x>=0 && rightCount>=x) || (x<0 && leftCount>=Math.abs(x))) xpos = true;
if((y>=0 && upCount>=y) || (y<0 && downCount>=Math.abs(y))) ypos = true;
if(xpos && ypos) System.out.println("YES");
else System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 34a088d90fd152b1fb9cb6c1816bd054 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class SpaceNavigation {
public static void main(String[] args) throws IOException {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));//new FileReader("cowdance.in")
PrintWriter out = new PrintWriter(System.out);//new FileWriter("cowdance.out")
StringTokenizer st = new StringTokenizer(read.readLine());
int t = Integer.parseInt(st.nextToken());
for (int ie = 0; ie < t; ie++) {
st = new StringTokenizer(read.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
String s = read.readLine();
int u = 0;
int d = 0;
int l = 0;
int r = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'U') {
u++;
}else if (s.charAt(i) == 'D') {
d--;
}else if (s.charAt(i) == 'R') {
r++;
}else {
l--;
}
}
if (x >= l && x <= r && y >= d && y <= u) {
out.println("YES");
}else {
out.println("NO");
}
}
out.close();
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 52ec6e1c2ccdbf736a05653e95f67d28 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class SpaceNavigation_1481A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t-->0){
int x = s.nextInt();
int y = s.nextInt();
s.nextLine();
String a = s.nextLine();
char[] array = a.toCharArray();
int u = 0, d = 0, l = 0, r = 0;
for (int i = 0; i < array.length; i++) {
if(array[i]=='U') u++;
if(array[i]=='D') d++;
if(array[i]=='L') l++;
if(array[i]=='R') r++;
}
boolean possible = false;
if(x<=0 && y<=0){
if(l>=Math.abs(x) && d>=Math.abs(y)) possible = true;
}
else if(x>=0 && y<=0){
if(r>=Math.abs(x) && d>=Math.abs(y)) possible = true;
}
else if(x<=0 && y>=0){
if(l>=Math.abs(x) && u>=Math.abs(y)) possible = true;
}
else {
if(r>=Math.abs(x) && u>=Math.abs(y)) possible = true;
}
if(possible) System.out.println("YES"); else System.out.println("NO");
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 67dace2367e9b55d87b53a141ebdabb7 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.*;
public class SpaceNavigation {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
for (int i = 0; i < num; i++)
{
boolean answer = true;
StringTokenizer st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
String str = br.readLine();
//char[] ch = str.toCharArray();
long UCount = str.chars().filter(ch -> ch == 'U').count();
//System.out.println(UCount);
long DCount = str.codePoints().filter(ch -> ch == 'D').count();
//System.out.println(DCount);
long LCount = str.chars().filter(ch -> ch == 'L').count();
//System.out.println(LCount);
long RCount = str.codePoints().filter(ch -> ch == 'R').count();
//System.out.println(RCount);
if (y <=0 && DCount < Math.abs(y)) answer = false;
if (y > 0 && UCount < y) answer = false;
if (x <= 0 && LCount < Math.abs(x)) answer = false;
if (x > 0 && RCount < x) answer = false;
if (answer) System.out.println("YES");
else if (!answer) System.out.println("NO");
//// System.out.println("-----------------------------");
}
br.close();
}
}
//import java.io.*;
//import java.util.*;
//
//public class SpaceNavigation {
//
// public static void main(String[] args) throws IOException{
// // TODO Auto-generated method stub
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//
// int num = Integer.parseInt(br.readLine());
// for (int i = 0; i < num; i++)
// {
// int UCount = 0; int DCount = 0; int RCount = 0; int LCount = 0;
// boolean answer = true;
// StringTokenizer st = new StringTokenizer(br.readLine());
// int x = Integer.parseInt(st.nextToken());
// int y = Integer.parseInt(st.nextToken());
// String str = br.readLine();
// char[] ch = str.toCharArray();
// for (int j = 0; j < ch.length; j++)
// {
// if (ch[j] == 'U') UCount++;
// if (ch[j] == 'D') DCount++;
// if (ch[j] == 'R') RCount++;
// if (ch[i] == 'L') LCount++;
// }
//// System.out.println("U: " + UCount);
//// System.out.println("D: " + DCount);
//// System.out.println("L: " + LCount);
//// System.out.println("R: " + RCount);
//
// if (y <=0 && DCount < Math.abs(y)) answer = false;
// if (y > 0 && UCount < y) answer = false;
// if (x <= 0 && LCount < Math.abs(x)) answer = false;
// if (x > 0 && RCount < x) answer = false;
// if (answer) System.out.println("YES");
// else if (!answer) System.out.println("NO");
//// System.out.println("-----------------------------");
//
//
// }
// br.close();
//
// }
//
//}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 745b03ac0e30bedb73b1b27b7c4ae1e4 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.* ;
import java.util.* ;
public class App {
public static void main (String[] args) throws java.lang.Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//reader = new BufferedReader(new FileReader(new File("C:\\Users\\Anjali\\Desktop\\projects\\HelloWorld\\src\\input.txt")));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
// writer = new BufferedWriter(new FileWriter(new File("C:\\Users\\Anjali\\Desktop\\projects\\HelloWorld\\src\\output.txt")));
//int tests = Integer.parseInt(reader.readLine());
int tests = 1;
//StringBuilder sb = new StringBuilder(tests);
while (tests-- > 0){
solve(reader, writer);
writer.write("\n");
}
reader.close();
writer.flush();
writer.close();
}
static void solve(BufferedReader reader, BufferedWriter writer) throws IOException {
int tests = Integer.parseInt(reader.readLine());
for (int i = 0; i < tests; i++) {
String[] input = reader.readLine().split(" ");
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
String s = reader.readLine();
char[] a1 = s.toCharArray();
int u, r;
u = r = 0;
for (int j = 0; j < s.length(); j++) {
if (a1[j] == 'U' && b > r) {
r += 1;
}
if (a1[j] == 'D' && b < r) {
r -= 1;
}
if (a1[j] == 'R' && a > u) {
u += 1;
}
if (a1[j] == 'L' && a < u) {
u -= 1;
}
}
if (a == u && b == r) {
writer.write("YES\n");
} else {
writer.write("NO\n");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | 0dd4802974e02de7019d207ac01c9d9b | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.Scanner;
import java.util.*;
import java.lang.*;
import java.io.IOException;
public class Codechef
{
////
public static void main(String[] args) throws IOException
{
try
{
System.setIn(new FileInputStream("input.txt"));
System.setOut(new PrintStream(new FileOutputStream("output.txt")));
}
catch (Exception e)
{
System.err.println("Error");
}
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in))
Scanner sc= new Scanner(System.in);
int t = sc.nextInt();
while(t--!=0)
{
int n = sc.nextInt();
int m = sc.nextInt();
String s = sc.next();
if(n>=0 && m>=0)
{
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='R' && n!=0)
{
n--;
}
if(s.charAt(i)=='U' && m!=0)
{
m--;
}
}
}
else if(n<0 && m>=0)
{
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='L' && n!=0)
{
n++;
}
if(s.charAt(i)=='U' && m!=0)
{
m--;
}
}
}
else if(n<0 && m<0)
{
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='L' && n!=0)
{
n++;
}
if(s.charAt(i)=='D' && m!=0)
{
m++;
}
}
// System.out.println(n + " " + m);
}
else
{
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='R' && n!=0)
{
n--;
}
if(s.charAt(i)=='D' && m!=0)
{
m++;
}
}
}
if(n==m && n==0)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | d9fbb12fe6df462a519c7066a281af8d | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 0;i < t; i++){
long a = sc.nextLong();
long b = sc.nextLong();
String s = sc.next();
long n = s.length();
long u = 0;
long d = 0;
long l = 0;
long r = 0;
for(int j = 0; j < n; j++){
if(s.charAt(j) == 'U' )
u++;
else if(s.charAt(j) == 'D')
d++;
else if(s.charAt(j) == 'R')
r++;
else
l++;
}
if(a > 0 && r >= a )
a = 0;
if(a < 0 && l >= -a )
a = 0;
if(b > 0 && u >= b )
b = 0;
if(b < 0 && d >= -b )
b = 0;
if(a == 0 && b == 0)
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | f738d5e1af0d1a115bb2192f980f2938 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.Scanner;
public class SpaceNavigation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc.next();
int r = 0;
int u = 0;
int d = 0;
int l = 0;
int x1 = Math.abs(x);
int y1 = Math.abs(y);
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j)=='R') {
r++;
}
else if (s.charAt(j)=='U') {
u++;
}
else if (s.charAt(j)=='D') {
d++;
}
else if (s.charAt(j)=='L') {
l++;
}
}
if (x>=0 && y>=0) {
if (r>=x1 && u>=y1) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
else if (x>=0 && y<=0) {
if (r>=x1 && d>=y1) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
else if (x<=0 && y>=0) {
if (l>=x1 && u>=y1) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
else {
if (l>=x1 && d>=y1) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | db36b462303947c14891646519a88d93 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.io.*;
import java.util.*;
import java.util.Collections;
import javax.lang.model.util.ElementScanner6;
import java.math.*;
import java.lang.*;
public class B implements Runnable {
public void run() {
final InputReader sc = new InputReader(System.in);
final PrintWriter out = new PrintWriter(System.out);
int t1=sc.nextInt();
while(t1--!=0)
{
int x=sc.nextInt();
int y=sc.nextInt();
int tmpx=0;
int tmpy=0;
int t=0,z=0;
char c[]=sc.next().toCharArray();
for(int i=0;i<c.length;i++)
{
if(x==0)
{
z=1;
}
else if(x<0 && c[i]=='L')
{
// out.println("tmpx="+tmpx);
tmpx--;
if(tmpx==x)
{
z=1;
}
}
else if(x>0 && c[i]=='R')
{
// out.println("tmpx="+tmpx);
tmpx++;
if(tmpx==x)
{
z=1;
}
}
if(y==0)
{
t=1;
}
else if(y<0 && c[i]=='D')
{
tmpy--;
// out.println("tmpu="+tmpy);
if(tmpy==y)
{
t=1;
}
}
else if(y>0 && c[i]=='U')
{
tmpy++;
// out.println("tmpu="+tmpy);
if(tmpy==y)
{
t=1;
}
}
}
if(t==1 && z==1)
{
out.println("YES");
}
else
{
out.println("NO");
}
}
out.close();
}
//========================================================
static class Pair
{
int a,b;
Pair(final int aa,final int bb)
{
a=aa;
b=bb;
}
}
static void sa(final int a[],final InputReader sc)
{
for(int i=0;i<a.length;i++)
{
a[i]=sc.nextInt();
}
Arrays.sort(a);
}
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(final 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 (final IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
}
catch (final IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
final StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(final int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(final String args[]) throws Exception {
new Thread(null, new B(),"Main",1<<27).start();
}
} | Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output | |
PASSED | d9ad1c805b7fd8f3b24397dfcd1b4172 | train_107.jsonl | 1612535700 | You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $$$XY$$$ plane. You are starting at point $$$(0, 0)$$$, and Planetforces is located in point $$$(p_x, p_y)$$$.The piloting system of your spaceship follows its list of orders which can be represented as a string $$$s$$$. The system reads $$$s$$$ from left to right. Suppose you are at point $$$(x, y)$$$ and current order is $$$s_i$$$: if $$$s_i = \text{U}$$$, you move to $$$(x, y + 1)$$$; if $$$s_i = \text{D}$$$, you move to $$$(x, y - 1)$$$; if $$$s_i = \text{R}$$$, you move to $$$(x + 1, y)$$$; if $$$s_i = \text{L}$$$, you move to $$$(x - 1, y)$$$. Since string $$$s$$$ could be corrupted, there is a possibility that you won't reach Planetforces in the end. Fortunately, you can delete some orders from $$$s$$$ but you can't change their positions.Can you delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces after the system processes all orders? | 256 megabytes | import java.util.*;
import static java.lang.Math.abs;
public class Main {
public static int countChar(String str, char c) {
int count = 0;
for(int i=0; i < str.length(); i++)
{ if(str.charAt(i) == c)
count++;
}
return count;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tests = sc.nextInt();
for(int i=0;i<tests;i++)
{
int x=sc.nextInt();
int y=sc.nextInt();
String directions = sc.next();
if(((x>0 && countChar(directions,'R')>=x) || (x<0 && countChar(directions,'L')>=abs(x)) || x==0) && ((y>0 && countChar(directions,'U')>=y) || (y<0 && countChar(directions,'D')>=abs(y)) || y==0))
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["6\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR"] | 2 seconds | ["YES\nYES\nYES\nNO\nYES\nNO"] | NoteIn the first case, you don't need to modify $$$s$$$, since the given $$$s$$$ will bring you to Planetforces.In the second case, you can delete orders $$$s_2$$$, $$$s_3$$$, $$$s_4$$$, $$$s_6$$$, $$$s_7$$$ and $$$s_8$$$, so $$$s$$$ becomes equal to "UR".In the third test case, you have to delete order $$$s_9$$$, otherwise, you won't finish in the position of Planetforces. | Java 11 | standard input | [
"greedy",
"strings"
] | 65a64ea63153fec4d660bad1287169d3 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. The first line in each test case contains two integers $$$p_x$$$ and $$$p_y$$$ ($$$-10^5 \le p_x, p_y \le 10^5$$$; $$$(p_x, p_y) \neq (0, 0)$$$) — the coordinates of Planetforces $$$(p_x, p_y)$$$. The second line contains the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$: $$$|s|$$$ is the length of string $$$s$$$) — the list of orders. It is guaranteed that the sum of $$$|s|$$$ over all test cases does not exceed $$$10^5$$$. | 800 | For each test case, print "YES" if you can delete several orders (possibly, zero) from $$$s$$$ in such a way, that you'll reach Planetforces. Otherwise, print "NO". You can print each letter in any case (upper or lower). | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.