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 | a638ba00da5789b63691fa636316d5f5 | 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.lang.*;
import java.util.*;
public class Arpit
{
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();
if(px==0 && py==0)
{
System.out.println("YES");
continue;
}
String s = sc.next();
int left = 0,right = 0,up = 0,down = 0;
for(int i=0;i<s.length();i++)
{
char p = s.charAt(i);
if(p=='U')
up++;
else if(p=='R')
right++;
else if(p=='D')
down++;
else
left++;
}
if(px>=0 && py>=0)
{
if(right>=px && up>=py)
System.out.println("YES");
else
System.out.println("NO");
continue;
}
else if(px>=0 && py<=0)
{
if(right>=px && down >=-1*py)
System.out.println("YES");
else
System.out.println("NO");
continue;
}
else if( px<=0 && py>=0)
{
if(left>=-1*px && up >=py)
System.out.println("YES");
else
System.out.println("NO");
continue;
}
else
{
if(left>=-1*px && down >=-1*py)
System.out.println("YES");
else
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 8 | 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 | 9b645b97d3093979ab586bde5c334152 | 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.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testcases = scanner.nextInt();
scanner.nextLine();
for(int i=1; i<=testcases; i++){
//taking inputs from system
String destination = scanner.nextLine();
String[] numbers = destination.split(" ");
int Px = Integer.parseInt(numbers[0]);
int Py = Integer.parseInt(numbers[1]);
String path = scanner.nextLine().toUpperCase();
//counting operations - regex
Pattern r_pattern = Pattern.compile("[^R]*R");
Matcher r_matcher = r_pattern.matcher(path);
Pattern l_pattern = Pattern.compile("[^L]*L");
Matcher l_matcher = l_pattern.matcher(path);
Pattern u_pattern = Pattern.compile("[^U]*U");
Matcher u_matcher = u_pattern.matcher(path);
Pattern d_pattern = Pattern.compile("[^D]*D");
Matcher d_matcher = d_pattern.matcher(path);
int l_count=0;
int u_count=0;
int d_count=0;
int r_count=0;
while(l_matcher.find()){l_count++;}
while(u_matcher.find()){u_count++;}
while(d_matcher.find()){d_count++;}
while(r_matcher.find()){r_count++;}
//deciding which quadrant the destination is
if(Px>=0 && Py>=0){
if(r_count>=Px && u_count>=Py){
System.out.println("YES");
}else
System.out.println("NO");
}else if(Px<=0 && Py>=0){
Px = Px*(-1);
if(l_count>=Px && u_count>=Py){
System.out.println("YES");
}else
System.out.println("NO");
}else if(Px<=0 && Py<=0){
Px *= -1;
Py *= -1;
if(l_count>=Px && d_count>=Py){
System.out.println("YES");
}else
System.out.println("NO");
}else if(Px>=0 && Py<=0){
Py *= -1;
if(r_count>=Px && d_count>=Py){
System.out.println("YES");
}else
System.out.println("NO");
}else{
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 8 | 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 | a0ed8b2fdb95892486fef778b7adc3a9 | 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.IOException;
import java.util.*;
public class Solution{
public static void main(String []args) throws IOException
{
try{
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(bf.readLine());
int x,y;int i=0,len=0;
int countx=0;
int county=0;
int val=1;
char A,B;
while(n!=0){
A='\0';
B='\0';
val=1;
i=0;
countx=0;
county=0;
String str[]=bf.readLine().split(" ");
x=Integer.parseInt(str[0]);
y=Integer.parseInt(str[1]);
String s=bf.readLine();
len=s.length();
if(x>0&&y>0){
// System.out.println("Here 1");
A='U';
B='R';
}
else if(x>0&&y<=0){
//System.out.println("Here 2");
A='D';
B='R';
y=y*-1;
}
else if(x<0&&y<0){
// System.out.println("Here 3");
A='D';
B='L';
x=x*-1;
y=y*-1;
}
else if(x<=0&&y>0){
//System.out.println("Here 4");
A='U';
B='L';
x=x*-1;
}
else{
if(x==0){
y=y*-1;
A='D';
}
else{
B='L';
x=x*-1;
}
}
while(i<len){
if(s.charAt(i)==A){
county=county+1;
}
else if(s.charAt(i)==B){
countx=countx+1;
}
if(x<=countx&&y<=county){
System.out.println("Yes");
val=0;
break;
}
i++;
}
if(val==1){
System.out.println("No");
}
n--;
}
bf.close();
}catch(Exception e){
System.out.println(e);
}
}
} | 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 8 | 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 | 1303f3a39765c892902ef6e40920b9db | 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.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Submit {
public static void main(String[] args) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
InputReader reader = new InputReader()) {
int t = reader.nextInt();
int a, b;
char ac, bc;
while (t-- > 0) {
a = reader.nextInt();
b = reader.nextInt();
ac = a > 0 ? 'R' : 'L';
bc = b > 0 ? 'U' : 'D';
String s = reader.nextLine();
int ca = 0, cb = 0;
for (int i = 0; i < s.length(); i++) {
if (a != 0 && s.charAt(i) == ac) {
ca++;
} else if (b != 0 && s.charAt(i) == bc) {
cb++;
}
}
a = Math.abs(a);
b = Math.abs(b);
if (ca >= a && cb >= b) {
writer.append("YES");
} else {
writer.append("NO");
}
writer.append(System.lineSeparator());
writer.flush();
}
}
}
}
class InputReader implements AutoCloseable {
private BufferedReader bufferedReader;
private StringTokenizer tokenizer;
public InputReader() {
bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(bufferedReader.readLine());
} catch (IOException ex) {
ex.printStackTrace();
}
}
return tokenizer.nextToken();
}
public char nextChar() {
char character = ' ';
try {
character = (char) bufferedReader.read();
} catch (IOException e) {
e.printStackTrace();
}
return character;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String line = "";
try {
line = bufferedReader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return line;
}
@Override
public void close() {
try {
this.bufferedReader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
| 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 8 | 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 | 4cd10f9d2c2d21665163b25dd152afb6 | 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.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Submit {
public static void main(String[] args) throws IOException {
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
InputReader reader = new InputReader()) {
int t = reader.nextInt();
while (t-- > 0) {
int a = reader.nextInt();
int b = reader.nextInt();
char ac = a > 0 ? 'R' : 'L';
char bc = b > 0 ? 'U' : 'D';
String s = reader.nextLine();
int ca = 0, cb = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == ac) {
ca++;
} else if (s.charAt(i) == bc) {
cb++;
}
}
boolean ans1 = true;
if (a != 0 && ca < Math.abs(a)) {
ans1 = false;
}
boolean ans2 = true;
if (b != 0 && cb < Math.abs(b)) {
ans2 = false;
}
if (ans1 && ans2) {
writer.append("YES");
} else {
writer.append("NO");
}
writer.append(System.lineSeparator());
writer.flush();
}
}
}
}
class InputReader implements AutoCloseable {
private BufferedReader bufferedReader;
private StringTokenizer tokenizer;
public InputReader() {
bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(bufferedReader.readLine());
} catch (IOException ex) {
ex.printStackTrace();
}
}
return tokenizer.nextToken();
}
public char nextChar() {
char character = ' ';
try {
character = (char) bufferedReader.read();
} catch (IOException e) {
e.printStackTrace();
}
return character;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
String line = "";
try {
line = bufferedReader.readLine();
} catch (IOException ex) {
ex.printStackTrace();
}
return line;
}
@Override
public void close() {
try {
this.bufferedReader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
| 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 8 | 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 | e6ae512140b86de6f88ff83c765e7674 | 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 sc = new Scanner(System.in);
while (sc.hasNext()) {
int t = sc.nextInt();
while (t-- > 0) {
int targetX = sc.nextInt();
int targetY = sc.nextInt();
sc.nextLine(); //to clear the buffer
String str = sc.nextLine();
solve(targetX, targetY, str);
}
}
}
/**
* method to solve current cp problem
*/
private static void solve(int targetX, int targetY, String str) {
Integer[] freq = new Integer[4];
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'L') {
if (freq[0] != null) freq[0] += 1;
else freq[0] = 1;
} else if (str.charAt(i) == 'R') {
if (freq[1] != null) freq[1] += 1;
else freq[1] = 1;
} else if (str.charAt(i) == 'U') {
if (freq[2] != null) freq[2] += 1;
else freq[2] = 1;
} else if (str.charAt(i) == 'D') {
if (freq[3] != null) freq[3] += 1;
else freq[3] = 1;
}
}
if (targetX < 0 && targetY < 0) {
if (freq[0] != null && Math.abs(freq[0]) >= Math.abs(targetX)
&& freq[3] != null && Math.abs(freq[3]) >= Math.abs(targetY)) System.out.println("YES");
else System.out.println("NO");
} else if (targetX < 0 && targetY > 0) {
if (freq[0] != null && Math.abs(freq[0]) >= Math.abs(targetX)
&& freq[2] != null && freq[2] >= targetY) System.out.println("YES");
else System.out.println("NO");
} else if (targetX > 0 && targetY < 0) {
if (freq[1] != null && freq[1] >= targetX &&
freq[3] != null && Math.abs(freq[3]) >= Math.abs(targetY)) System.out.println("YES");
else System.out.println("NO");
} else if (targetX > 0 && targetY > 0) {
if (freq[1] != null && freq[1] >= targetX &&
freq[2] != null && freq[2] >= targetY) System.out.println("YES");
else System.out.println("NO");
} else if (targetX == 0 && targetY < 0) {
if (freq[3] != null && Math.abs(freq[3]) >= Math.abs(targetY)) System.out.println("YES");
else System.out.println("NO");
} else if (targetX == 0 && targetY > 0) {
if (freq[2] != null && freq[2] >= targetY) System.out.println("YES");
else System.out.println("NO");
} else if (targetX < 0 && targetY == 0) {
if (freq[0] != null && Math.abs(freq[0]) >= Math.abs(targetX)) System.out.println("YES");
else System.out.println("NO");
} else if (targetX > 0 && targetY == 0) {
if (freq[1] != null && freq[1] >= targetX) System.out.println("YES");
else System.out.println("NO");
}
}
/**
* method to check whether the provided string is palindrome or not
*
* @param str - the string to check if it is palindrome or not
* @return - true if the provided string is palindrome else false
*/
private static boolean isPalindrome(String str) {
if (str.length() % 2 == 0) {
for (int i = 0, j = str.length() - 1; i < j && j > i; i++, j--) {
if (str.charAt(i) != str.charAt(j)) return false;
}
} else {
for (int i = 0, j = str.length() - 1; i <= j && j >= i; i++, j--) {
if (str.charAt(i) != str.charAt(j)) return false;
}
}
return true;
}
/**
* method to check whether the provided number is palindrome or not
*
* @param n - the number to check if it is palindrome or not
* @return - true if the provided number is palindrome else false
*/
private static boolean isPalindrome(int n) {
int tempN = n, reverseNumber = 0;
while (tempN > 0) {
reverseNumber = reverseNumber * 10 + (tempN % 10);
tempN /= 10;
}
if (reverseNumber == n) return true;
return false;
}
/**
* method to check whether the provided number is palindrome or not
*
* @param n - the number to check if it is palindrome or not
* @return - true if the provided number is palindrome else false
*/
private static boolean isPalindrome(long n) {
long tempN = n, reverseNumber = 0L;
while (tempN > 0L) {
reverseNumber = reverseNumber * 10L + (tempN % 10L);
tempN /= 10L;
}
if (reverseNumber == n) return true;
return false;
}
/**
* method to get max and second max element returned into
* the form of an array
**/
private static int[] getMaxAndSecondMax(int a, int b, int c, int d) {
int[] arr = new int[2];
if (a > b && a > c && a > d) {
arr[0] = a;
if (b > c && b > d) arr[1] = b;
else if (c > b && c > d) arr[1] = c;
else if (d > b && d > c) arr[1] = d;
} else if (b > a && b > c && b > d) {
arr[0] = b;
if (a > c && a > d) arr[1] = a;
else if (c > a && c > d) arr[1] = c;
else if (d > a && d > c) arr[1] = d;
} else if (c > a && c > b && c > d) {
arr[0] = c;
if (a > b && a > d) arr[1] = a;
else if (b > a && b > d) arr[1] = b;
else if (d > a && d > b) arr[1] = d;
} else if (d > a && d > b && d > c) {
arr[0] = d;
if (a > b && a > c) arr[1] = a;
else if (b > a && b > c) arr[1] = b;
else if (c > a && c > b) arr[1] = c;
}
return arr;
}
/**
* method to compute the total number of digits in a
* given number
*/
private static int countDigits(int n) {
int counter = 1;
while (n > 9) {
n /= 10;
counter += 1;
}
return counter;
}
/**
* method to compute the total number of digits in a
* given number
*/
private static long countDigits(long n) {
long counter = 1L;
while (n > 9L) {
n /= 10L;
counter += 1L;
}
return counter;
}
/**
* method to compute the sum of n natural numbers
*/
private static int getNDigitsSum(int n) {
return (n * (n + 1)) / 2;
}
/**
* method to check whether a number is prime or not
*/
private static boolean isPrime(int n) {
//Base Cases
if (n == 2 || n == 3) return true;
if (n % 2 == 0) return false;
for (int i = 3; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
/**
* method to compute factorial of a given number
*
* @param n
* @return
*/
private static int factorial(int n) {
int ans = 1;
while (n > 1) {
ans *= n;
n -= 1;
}
return ans;
}
/**
* method to compute factorial of a given number
*
* @param n
* @return
*/
private static long factorial(long n) {
long ans = 1L;
while (n > 1L) {
ans *= n;
n -= 1L;
}
return 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 8 | 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 | 2f7e2313dc5ae6da5f51adff1f7803ec | 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 Problem1418A {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int tc = scanner.nextInt();
while (tc-->0) {
int x = scanner.nextInt();
int y = scanner.nextInt();
int xi =0;
int yi=0;
String str = scanner.next();
char[] array = str.toCharArray();
for (int i = 0; i < array.length; i++) {
if (array[i] == 'U' && yi<y) {
yi++;
} else if (array[i] == 'D' && yi>y) {
yi--;
} else if (array[i] == 'R' && xi<x) {
xi++;
} else if (array[i]=='L' && xi>x)xi--;
}
if (xi==x && yi ==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 8 | 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 | df53ed516edcd56f4022e97f48079913 | 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 n=sc.nextInt();
for(int i=0;i<n;i++){
int a=sc.nextInt();
int b=sc.nextInt();
String s=sc.next();
System.out.println(solve(a,b,s.toUpperCase())?"YES":"NO");
}
}
static boolean solve(int px, int py, String s) {
return (px == 0
|| (px < 0 && s.chars().filter(ch -> ch == 'L').count() >= -px)
|| (px > 0 && s.chars().filter(ch -> ch == 'R').count() >= px))
&& (py == 0
|| (py < 0 && s.chars().filter(ch -> ch == 'D').count() >= -py)
|| (py > 0 && s.chars().filter(ch -> ch == 'U').count() >= py));
}
} | 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 8 | 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 | 11066a5ef7c494ae3b8b65898e8d7d74 | 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.Arrays;
import java.util.Scanner;
public class JavaApplication2 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
outer:
for(int i=0;i<t;i++)
{
int x=sc.nextInt();
int y=sc.nextInt();
int p=0;
String s=sc.next();
boolean a= true;
if (x>0)
{
for (int j=0; j<s.length(); j++)
{
if (s.charAt(j)=='R')
p++;
}
if (p<x)
a=false;
}
else if (x<0)
{
for (int k=0; k<s.length(); k++)
{
if (s.charAt(k)=='L')
p--;
}
if (p>x)
a=false;
}
p=0;
if (y>0)
{
for (int d=0; d<s.length(); d++)
{
if (s.charAt(d)=='U')
p++;
}
if (p<y)
a=false;
}
else if (y<0)
{
for (int o=0; o<s.length(); o++)
{
if (s.charAt(o)=='D')
p--;
}
if (p>y)
a=false;
}
System.out.println(a?"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 8 | 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 | 39a7ac7eee72bed5a0dbe81da44352c1 | 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 final class Solution {
static PrintWriter out = new PrintWriter(System.out);
static FastReader in = new FastReader();
static long mod = (long) 1e9 + 7;
static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(1, 0), new Pair(0, -1), new Pair(0, 1)};
// 6
//10 5
//RRRRRRRRRRUUUUU
//1 1
//UDDDRLLL
//-3 -5
//LDLDLDDDR
//1 2
//LLLLUU
//3 -2
//RDULRLLDR
//-1 6
//RUDURUUUUR
public static void main(String[] args) {
int tt = i();
out:
while (tt-- > 0) {
int x = i();
int y = i();
String s = s();
int u = 0;
int d = 0;
int l = 0;
int r = 0;
for (char c : s.toCharArray()) {
if (c == 'U') {
u++;
}
if (c == 'D') {
d++;
}
if (c == 'L') {
l++;
}
if (c == 'R') {
r++;
}
}
if (-l <= x && x <= r && -d <= y && y <= u) {
printYes();
} else {
printNo();
}
}
out.flush();
}
static boolean isPS(double number) {
double sqrt = Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static int sd(long i) {
int d = 0;
while (i > 0) {
d += i % 10;
i = i / 10;
}
return d;
}
static int[] leastPrime;
static void sieveLinear(int N) {
int[] primes = new int[N];
int idx = 0;
leastPrime = new int[N + 1];
for (int i = 2; i <= N; i++) {
if (leastPrime[i] == 0) {
primes[idx++] = i;
leastPrime[i] = i;
}
int curLP = leastPrime[i];
for (int j = 0; j < idx; j++) {
int p = primes[j];
if (p > curLP || (long) p * i > N) {
break;
} else {
leastPrime[p * i] = p;
}
}
}
}
static int lower(long A[], long x) {
int l = -1, r = A.length;
while (r - l > 1) {
int m = (l + r) / 2;
if (A[m] >= x) {
r = m;
} else {
l = m;
}
}
return r;
}
static int upper(long A[], long x) {
int l = -1, r = A.length;
while (r - l > 1) {
int m = (l + r) / 2;
if (A[m] <= x) {
l = m;
} else {
r = m;
}
}
return l;
}
static void swap(int A[], int a, int b) {
int t = A[a];
A[a] = A[b];
A[b] = t;
}
static int lowerBound(int A[], int low, int high, int x) {
if (low > high) {
if (x >= A[high]) {
return A[high];
}
}
int mid = (low + high) / 2;
if (A[mid] == x) {
return A[mid];
}
if (mid > 0 && A[mid - 1] <= x && x < A[mid]) {
return A[mid - 1];
}
if (x < A[mid]) {
return lowerBound(A, low, mid - 1, x);
}
return lowerBound(A, mid + 1, high, x);
}
static long pow(long a, long b) {
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0) {
pow = (pow * x) % mod;
}
x = (x * x) % mod;
b /= 2;
}
return pow;
}
static boolean isPrime(long N) {
if (N <= 1) {
return false;
}
if (N <= 3) {
return true;
}
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;
}
static void print(char A[]) {
for (char c : A) {
out.print(c);
}
out.println();
}
static void print(boolean A[]) {
for (boolean c : A) {
out.print(c + " ");
}
out.println();
}
static void print(int A[]) {
for (int c : A) {
out.print(c + " ");
}
out.println();
}
static void print(long A[]) {
for (long i : A) {
out.print(i + " ");
}
out.println();
}
static void print(List<Integer> A) {
for (int a : A) {
out.print(a + " ");
}
}
static void printYes() {
out.println("YES");
}
static void printNo() {
out.println("NO");
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static String s() {
return in.nextLine();
}
static int[] input(int N) {
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[] = new long[N];
for (int i = 0; i < A.length; i++) {
A[i] = in.nextLong();
}
return A;
}
static int GCD(int a, int b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long GCD(long a, long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
}
class BIT {
int n;
int[] tree;
public BIT(int n) {
this.n = n;
this.tree = new int[n + 1];
}
public static int lowbit(int x) {
return x & (-x);
}
public void update(int x) {
while (x <= n) {
++tree[x];
x += lowbit(x);
}
}
public int query(int x) {
int ans = 0;
while (x > 0) {
ans += tree[x];
x -= lowbit(x);
}
return ans;
}
public int query(int x, int y) {
return query(y) - query(x - 1);
}
}
class SegmentTree {
long[] t;
public SegmentTree(int n) {
t = new long[n + n];
Arrays.fill(t, Long.MIN_VALUE);
}
public long get(int i) {
return t[i + t.length / 2];
}
public void add(int i, long value) {
i += t.length / 2;
t[i] = value;
for (; i > 1; i >>= 1) {
t[i >> 1] = Math.max(t[i], t[i ^ 1]);
}
}
// max[a, b]
public long max(int a, int b) {
long res = Long.MIN_VALUE;
for (a += t.length / 2, b += t.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
if ((a & 1) != 0) {
res = Math.max(res, t[a]);
}
if ((b & 1) == 0) {
res = Math.max(res, t[b]);
}
}
return res;
}
}
class Pair {
int i, j;
Pair(int i, int j) {
this.i = i;
this.j = j;
}
}
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 8 | 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 | 1aca98b6059b2b224cd40e66ea2c22e9 | 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 final class Solution {
static PrintWriter out = new PrintWriter(System.out);
static FastReader in = new FastReader();
static long mod = (long) 1e9 + 7;
static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(1, 0), new Pair(0, -1), new Pair(0, 1)};
// 6
//10 5
//RRRRRRRRRRUUUUU
//1 1
//UDDDRLLL
//-3 -5
//LDLDLDDDR
//1 2
//LLLLUU
//3 -2
//RDULRLLDR
//-1 6
//RUDURUUUUR
public static void main(String[] args) {
int tt = i();
out:
while (tt-- > 0) {
int x = i();
int y = i();
String s = s();
int u = 0;
int d = 0;
int l = 0;
int r = 0;
for (char c : s.toCharArray()) {
if (c == 'U') {
u++;
}
if (c == 'D') {
d++;
}
if (c == 'L') {
l++;
}
if (c == 'R') {
r++;
}
}
boolean xx = false;
boolean yy = false;
if (x > 0 && r >= x) {
xx = true;
}
if (x < 0 && -l <= x) {
xx = true;
}
if (x == 0) {
xx = true;
}
if (y > 0 && u >= y) {
yy = true;
}
if (y < 0 && -d <= y) {
yy = true;
}
if (y == 0) {
yy = true;
}
if (xx && yy) {
printYes();
} else {
printNo();
}
}
out.flush();
}
static boolean isPS(double number) {
double sqrt = Math.sqrt(number);
return ((sqrt - Math.floor(sqrt)) == 0);
}
static int sd(long i) {
int d = 0;
while (i > 0) {
d += i % 10;
i = i / 10;
}
return d;
}
static int[] leastPrime;
static void sieveLinear(int N) {
int[] primes = new int[N];
int idx = 0;
leastPrime = new int[N + 1];
for (int i = 2; i <= N; i++) {
if (leastPrime[i] == 0) {
primes[idx++] = i;
leastPrime[i] = i;
}
int curLP = leastPrime[i];
for (int j = 0; j < idx; j++) {
int p = primes[j];
if (p > curLP || (long) p * i > N) {
break;
} else {
leastPrime[p * i] = p;
}
}
}
}
static int lower(long A[], long x) {
int l = -1, r = A.length;
while (r - l > 1) {
int m = (l + r) / 2;
if (A[m] >= x) {
r = m;
} else {
l = m;
}
}
return r;
}
static int upper(long A[], long x) {
int l = -1, r = A.length;
while (r - l > 1) {
int m = (l + r) / 2;
if (A[m] <= x) {
l = m;
} else {
r = m;
}
}
return l;
}
static void swap(int A[], int a, int b) {
int t = A[a];
A[a] = A[b];
A[b] = t;
}
static int lowerBound(int A[], int low, int high, int x) {
if (low > high) {
if (x >= A[high]) {
return A[high];
}
}
int mid = (low + high) / 2;
if (A[mid] == x) {
return A[mid];
}
if (mid > 0 && A[mid - 1] <= x && x < A[mid]) {
return A[mid - 1];
}
if (x < A[mid]) {
return lowerBound(A, low, mid - 1, x);
}
return lowerBound(A, mid + 1, high, x);
}
static long pow(long a, long b) {
long pow = 1;
long x = a;
while (b != 0) {
if ((b & 1) != 0) {
pow = (pow * x) % mod;
}
x = (x * x) % mod;
b /= 2;
}
return pow;
}
static boolean isPrime(long N) {
if (N <= 1) {
return false;
}
if (N <= 3) {
return true;
}
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;
}
static void print(char A[]) {
for (char c : A) {
out.print(c);
}
out.println();
}
static void print(boolean A[]) {
for (boolean c : A) {
out.print(c + " ");
}
out.println();
}
static void print(int A[]) {
for (int c : A) {
out.print(c + " ");
}
out.println();
}
static void print(long A[]) {
for (long i : A) {
out.print(i + " ");
}
out.println();
}
static void print(List<Integer> A) {
for (int a : A) {
out.print(a + " ");
}
}
static void printYes() {
out.println("YES");
}
static void printNo() {
out.println("NO");
}
static int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static String s() {
return in.nextLine();
}
static int[] input(int N) {
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[] = new long[N];
for (int i = 0; i < A.length; i++) {
A[i] = in.nextLong();
}
return A;
}
static int GCD(int a, int b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long GCD(long a, long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
}
class BIT {
int n;
int[] tree;
public BIT(int n) {
this.n = n;
this.tree = new int[n + 1];
}
public static int lowbit(int x) {
return x & (-x);
}
public void update(int x) {
while (x <= n) {
++tree[x];
x += lowbit(x);
}
}
public int query(int x) {
int ans = 0;
while (x > 0) {
ans += tree[x];
x -= lowbit(x);
}
return ans;
}
public int query(int x, int y) {
return query(y) - query(x - 1);
}
}
class SegmentTree {
long[] t;
public SegmentTree(int n) {
t = new long[n + n];
Arrays.fill(t, Long.MIN_VALUE);
}
public long get(int i) {
return t[i + t.length / 2];
}
public void add(int i, long value) {
i += t.length / 2;
t[i] = value;
for (; i > 1; i >>= 1) {
t[i >> 1] = Math.max(t[i], t[i ^ 1]);
}
}
// max[a, b]
public long max(int a, int b) {
long res = Long.MIN_VALUE;
for (a += t.length / 2, b += t.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
if ((a & 1) != 0) {
res = Math.max(res, t[a]);
}
if ((b & 1) == 0) {
res = Math.max(res, t[b]);
}
}
return res;
}
}
class Pair {
int i, j;
Pair(int i, int j) {
this.i = i;
this.j = j;
}
}
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 8 | 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 | d64cb4d41ee592ad0104b9e214664f34 | 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 scan = new Scanner(System.in);
int t = Integer.parseInt(scan.nextLine());
for(int i = 0; i<t; i++){
int x = scan.nextInt();
int y = scan.nextInt();
scan.nextLine();
String directions = scan.nextLine();
Character toX = null;
Character toY = null;
if(x>=0)toX = 'R';
else if(x<0)toX = 'L';
if(y>=0)toY = 'U';
else if(y<0)toY = 'D';
int reachedx = Math.abs(x);
int reachedy = Math.abs(y);
for(int j = 0; j<directions.length(); j++){
if(directions.charAt(j)==toX)reachedx--;
if(directions.charAt(j)==toY)reachedy--;
}
if(reachedx<=0 && reachedy<=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 8 | 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 | 3861d1945b2eca25239b6377c4727c77 | 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) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int x=sc.nextInt();
int y=sc.nextInt();
sc.nextLine();
String s=sc.next();
int u=0,d=0,r=0,l=0;
for(int i=0;i<s.length();i++) {
switch(s.charAt(i)) {
case 'U':
u++;
break;
case 'D':
d++;
break;
case 'R':
r++;
break;
case 'L':
l++;
break;
}
}
if(x>0&&y>0)
System.out.println(x>r||y>u?"NO":"YES");
else if(x>0&&y<0)
System.out.println(x>r||Math.abs(y)>d?"NO":"YES");
else if(x<0&&y>0)
System.out.println(y>u||Math.abs(x)>l?"NO":"YES");
else if(x<0&&y<0)
System.out.println(Math.abs(x)>l||Math.abs(y)>d?"NO":"YES");
else {
if(x==0&&y<0)
System.out.println(Math.abs(y)>d?"NO":"YES");
else if(x==0&&y>0)
System.out.println(Math.abs(y)>u?"NO":"YES");
else if(y==0&&x>0)
System.out.println(x>r?"NO":"YES");
else if(y==0&&x<0)
System.out.println(Math.abs(x)>l?"NO":"YES");
else if(x==0&&y==0)
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 8 | 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 | d00f68961114138e90889c4f275bc9ff | 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{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int t = Integer.parseInt(bf.readLine());
for(int i = 0; i < t; i++) {
st = new StringTokenizer(bf.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
char[] pilot = bf.readLine().toCharArray();
HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
hm.put('U', 0);
hm.put('D', 0);
hm.put('L', 0);
hm.put('R', 0);
for(int j = 0; j < pilot.length; j++) {
hm.put(pilot[j], hm.get(pilot[j]) + 1);
}
int x2 = -1;
int y2 = -1;
if(x >= 0) {
x2 = hm.get('R');
}else {
x2 = hm.get('L');
}
if(y >= 0){
y2 = hm.get('U');
}else {
y2 = hm.get('D');
}
if(y2 >= Math.abs(y) && x2 >= 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 8 | 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 | 256f913a7edcbf666d8107bfcdc2482c | 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.math.*;
public class Testt
{ static StringBuilder out;
static void solve() throws IOException{
int px = fs.nextInt();
int py = fs.nextInt();
char[] str = fs.nextLine().toCharArray();
int[]arr = {0,0,0,0}; //u,d,r,l;
for(char ch : str){ //0,1,2,3
if(ch == 'U') arr[0]++;
else if(ch == 'D') arr[1]++;
else if(ch == 'R') arr[2]++;
else arr[3]++;
}
/**
* if 𝑠𝑖=U, you move to (𝑥,𝑦+1);
if 𝑠𝑖=D, you move to (𝑥,𝑦−1);
if 𝑠𝑖=R, you move to (𝑥+1,𝑦);
if 𝑠𝑖=L, you move to (𝑥−1,𝑦).
*/
String s = "No";
if(px>=0 && py >= 0){
//r,u
px = Math.abs(px);
py = Math.abs(py);
if(arr[2] >= px && arr[0] >= py) s = "Yes";
}
else if(px >= 0 && py < 0){
px = Math.abs(px);
py = Math.abs(py);
if(arr[2] >= px && arr[1] >= py) s = "Yes";
//r, d
}
else if(px < 0 && py >= 0){
px = Math.abs(px);
py = Math.abs(py);
if(arr[3] >= px && arr[0] >= py) s = "Yes";
//l,u
}
else {
px = Math.abs(px);
py = Math.abs(py);
if(arr[3] >= px && arr[1] >= py) s = "Yes";
//l,d
}
pw.println(s);
}
public static void main (String[] args) throws java.lang.Exception
{
fs = new FastReader();
out = new StringBuilder();
int t = fs.nextInt();
while (t-- > 0)
{
solve();
}
pw.flush();
pw.close();
}
//-------------------------------------------------
static long[] arrayInput(int n) throws IOException{
long[] arr = new long[n];
for(int i=0;i<n;i++) arr[i] = fs.nextLong();
return arr;
}
static final int MOD = (int) 1e9+7;
static final int INT_MAX = Integer.MAX_VALUE;
static final int INT_MIN = Integer.MIN_VALUE;
static FastReader fs;
static PrintWriter pw = new PrintWriter(System.out);
static void swap(long[]arr, int a, int b){
long temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
static void ruffleSort(long arr[]){
for(int i = 0; i<arr.length; i++){
int t = (int) Math.random() * arr.length;
long x = arr[t];
arr[t] = arr[i];
arr[i] = x;
}
Arrays.sort(arr);
}
static boolean isPrimeProbable(BigInteger bi){
return bi.isProbablePrime(10);
}
static BigInteger nextProbablePrime(BigInteger bi){
return bi.nextProbablePrime();
}
//--------reader section-----------------
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 8 | 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 | 3e1b8c7737ce4388ee8cce261d20b0d4 | 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 {
private static boolean canReachPlanet(int x, int y, String s) {
boolean isReachable = false;
int countX = 0;
int countY = 0;
int valX = Math.abs(x);
int valY = Math.abs(y);
char expectedX = x < 0 ? 'L' : 'R';
char expectedY = y < 0 ? 'D' : 'U';
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == expectedX) {
countX++;
}
if (s.charAt(i) == expectedY) {
countY++;
}
if (countX >= valX && countY >= valY) {
isReachable = true;
break;
}
}
return isReachable;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int ti = 0; ti < t; ti++) {
int x = in.nextInt();
int y = in.nextInt();
String s = in.next();
boolean isReachable = canReachPlanet(x, y, s);
System.out.println(isReachable ? "YES" : "NO");
}
in.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 8 | 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 | 1d84e60e3c8d69ce93f5d052197b1b6c | 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 {
private static boolean canReachPlanet(int x, int y, String s) {
boolean isReachable = false;
int countX = 0;
int countY = 0;
int valX = Math.abs(x);
int valY = Math.abs(y);
char expectedX = x < 0 ? 'L' : 'R';
char expectedY = y < 0 ? 'D' : 'U';
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == expectedX) {
countX++;
}
if (s.charAt(i) == expectedY) {
countY++;
}
if (countX >= valX && countY >= valY) {
isReachable = true;
break;
}
}
return isReachable;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int ti = 0; ti < t; ti++) {
int x = in.nextInt();
int y = in.nextInt();
String s = in.next();
boolean isReachable = canReachPlanet(x, y, s);
System.out.println(isReachable ? "YES" : "NO");
}
in.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 8 | 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 | 206aba85168df2317c3a4696e7ccc5b8 | 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.Arrays;
import java.util.Scanner;
import java.util.Vector;
public class NewClass {
static int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public static void main(String[] args) {
Scanner fs = new Scanner(System.in);
int t = fs.nextInt();
out:
while (t-- > 0) {
int x = fs.nextInt();
int y = fs.nextInt();
String s = fs.next();
if (x >= 0 && y >= 0) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'R' && x > 0) {
x--;
} else if (s.charAt(i) == 'U' && y > 0) {
y--;
}
// System.out.println(x+" "+y);
if (x == 0 && y == 0) {
System.out.println("YES");
continue out;
}
}
System.out.println("NO");
} else if (x >= 0 && y <= 0) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'R' && x > 0) {
x--;
} else if (s.charAt(i) == 'D' && y < 0) {
y++;
}
//System.out.println(x+" "+y);
if (x == 0 && y == 0) {
System.out.println("YES");
continue out;
}
}
System.out.println("NO");
} else if (x <= 0 && y >= 0) {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'L' && x < 0) {
x++;
} else if (s.charAt(i) == 'U' && y > 0) {
y--;
}
//System.out.println(x+" "+y);
if (x == 0 && y == 0) {
System.out.println("YES");
continue out;
}
}
System.out.println("NO");
} else {
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'L' && x < 0) {
x++;
} else if (s.charAt(i) == 'D' && y < 0) {
y++;
}
//System.out.println(x+ " "+y);
if (x == 0 && y == 0) {
System.out.println("YES");
continue out;
}
}
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 8 | 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 | 0a80eb0e18cb17552605bc85a5a58b2e | 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.lang.Math;
public class Main{
static BufferedReader reader;
static StringTokenizer tokenizer;
static PrintWriter writer;
static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
static double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
static String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static String nexts() throws IOException {
tokenizer = new StringTokenizer(reader.readLine());
String s="";
while (tokenizer.hasMoreTokens()) {
s+=tokenizer.nextElement()+" ";
}
return s;
}
public static int gcd(int x, int y){
if (y == 0) return x; else return gcd(y, x % y);
}
public static boolean isPrime(int nn)
{
if(nn<=1){
return false; }
if(nn<=3){
return true; }
if (nn%2==0||nn%3==0){
return false; }
for (int i=5;i*i<=nn;i=i+6){
if(nn%i==0||nn%(i+2)==0){
return false; }
}
return true;
}
public static void shuffle(int[] A) {
for (int i = 0; i < A.length; i++) {
int j = (int)(i * Math.random());
int tmp = A[i];
A[i] = A[j];
A[j] = tmp;
}
}
public static void shufflel(Long[] A) {
for (int i = 0; i < A.length; i++) {
int j = (int)(i * Math.random());
long tmp = A[i];
A[i] = A[j];
A[j] = tmp;
}
}
public static String reverse(String input)
{
StringBuilder input2=new StringBuilder();
input2.append(input);
input2 = input2.reverse();
return input2.toString();
}
public static long power(int x, long n)
{
// long mod = 1000000007;
if (n == 0) {
return 1;
}
long pow = power(x, n / 2);
if ((n & 1) == 1) {
return (x * pow * pow);
}
return (pow * pow);
}
public static long power(long x, long y, long p) //x^y%p
{
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % p;
}
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static long ncr(int n, int k)
{
long res = 1;
// Since C(n, k) = C(n, n-k)
if (k > n - k) {
k = n - k;
}
// Calculate value of [n*(n-1)*---*(n-k+1)] / [k*(k-1)*---*1]
for (int i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
public static int inv(int a, int m) //Returns modulo inverse of a with respect to m using extended euclid algorithm
{
int m0=m,t,q;
int x0=0,x1=1;
if(m==1){
return 0; }
while(a>1)
{
q=a/m;
t=m;
m=a%m;a=t;
t=x0;
x0=x1-q*x0;
x1=t; }
if(x1<0){
x1+=m0; }
return x1;
}
static int modInverse(int n, int p)
{
return (int)power((long)n, (long)(p - 2),(long)p);
}
static int ncrmod(int n, int r, int p)
{
if (r == 0) // Base case
return 1;
int[] fac = new int[n + 1]; // Fill factorial array so that we can find all factorial of r, n and n-r
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; //IMPORTANT
}
static int lower(int a[], int x) //Returns rightest index of x in sorted arr else -1
{ //If not present returns index of just smaller element
int n=a.length;
int l=0;
int r=n-1;
int ans=-1;
while(l<=r){
int m=(r-l)/2+l;
if(a[m]<=x){
ans=m;
l=m+1;
}
else{
r=m-1;
}
}
return ans;
}
static int upper(int a[], int x) //Returns leftest index of x in sorted arr else n
{ //If not present returns index of just greater element
int n=a.length;
int l=0;
int r=n-1;
int ans=n;
while(l<=r){
int m=(r-l)/2+l;
if(a[m]>=x){
ans=m;
r=m-1;
}
else{
l=m+1;
}
}
return ans;
}
public static long stringtoint(String s){ // Convert bit string to number
long a = 1;
long ans = 0;
StringBuilder sb = new StringBuilder();
sb.append(s);
sb.reverse();
s=sb.toString();
for(int i=0;i<s.length();i++){
ans = ans + a*(s.charAt(i)-'0');
a = a*2;
}
return ans;
}
String inttostring(long a,long m){ // a is number and m is length of string required
String res = ""; // Convert a number in bit string representation
for(int i=0;i<(int)m;i++){
if((a&(1<<i))==1){
res+='1';
}else
res+='0';
}
StringBuilder sb = new StringBuilder();
sb.append(res);
sb.reverse();
res=sb.toString();
return res;
}
static class R implements Comparable<R>{
int x, y;
public R(int x, int y) { //a[i]=new R(x,y);
this.x = x;
this.y = y;
}
public int compareTo(R o) {
return x-o.x; //Increasing order(Which is usually required)
}
}
/* FUNCTION TO SORT HASHMAP ACCORDING TO VALUE
//USE IT AS FOLLOW
//Make a new list
List<Map.Entry<Integer, Integer> > list =
new LinkedList<Map.Entry<Integer, Integer> >(h.entrySet());
// Sort the list
Collections.sort(list, new Comparator<Map.Entry<Integer, Integer> >() {
public int compare(Map.Entry<Integer, Integer> o1,
Map.Entry<Integer, Integer> o2)
{
return (o1.getValue()).compareTo(o2.getValue()); //This is used to sort string stored as VALUE, use below function here accordingly
}
});
// put data from sorted list to new hashmap
HashMap<String, Integer> temp = new LinkedHashMap<String, Integer>();
for (Map.Entry<String, Integer> aa : list) {
temp.put(aa.getKey(), aa.getValue());
}
return temp; //Now temp is our new sorted hashmap
OR
for(int i = 0;i<h.size();i++) //accessing elements from the list made
{
int count = list.get(i).getValue(); //Value
while(count >= 0)
{
int key=list.get(i).getKey(); //key
count -- ;
}
}
////////////////////////////////////////////////////////////////////////////////////////
public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2)
{
if(o1.getValue() != o2.getValue())
return o1.getValue() > o2.getValue()?1:-1; //Sorts Value in increasing order
else if(o1.getValue() == o2.getValue()){
return o1.getKey() > o2.getKey() ? 1:-1; //If value equal, then sorts key in increasing order
}
return Integer.MIN_VALUE;
}
*/
//Check if palindrome string - System.out.print(A.equals(new StringBuilder(A).reverse().toString())?"Yes":"No");
public static void main(String[] args) throws IOException {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
writer = new PrintWriter(System.out);
solve();
reader.close();
writer.close();
}
private static void solve() throws IOException {
int t = nextInt();
while(t-->0){
//String[] s = str.split("\\s+");
//ArrayList<Integer> ar=new ArrayList<Integer>();
//HashSet<Integer> set=new HashSet<Integer>();
//HashMap<Integer,String> h=new HashMap<Integer,String>();
//R[] a1=new R[n];
//char[] c=nextToken().toCharArray();
int p = nextInt();
int q = nextInt();
//long n = nextLong();
String s= nextToken();
//int[] a=new int[n];
//long[] a=new long[n];
//shuffle(a);
//shufflel(a);
//Arrays.sort(a);
int x=0,y=0;
int c=0;
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(p==0&&q==0){
writer.println("YES");
continue;
}
if(p>0){
if(q>0){
if(r>=p&&u>=q){
writer.println("YES");
}
else{
writer.println("NO");
}
}
else if(q<=0){
if(r>=p&&d>=Math.abs(q)){
writer.println("YES");
}
else{
writer.println("NO");
}
}
}
else{
if(q>0){
if(l>=Math.abs(p)&&u>=q){
writer.println("YES");
}
else{
writer.println("NO");
}
}
else if(q<=0){
if(l>=Math.abs(p)&&d>=Math.abs(q)){
writer.println("YES");
}
else{
writer.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 8 | 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 | 1ab508415487fc63d4cae317e7c51024 | 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.*;
public class test {
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int len=Integer.parseInt(br.readLine());
for(int i=0;i<len;i++){
String pos=br.readLine();
String dir=br.readLine();
String[] sp=pos.split(" ");
int x=Integer.parseInt(sp[0]);
int y=Integer.parseInt(sp[1]);
int[] dd=new int[4];
int[] da=new int[4];
Arrays.fill(da,0);
Arrays.fill(dd,0);
if(x>0){
dd[3]=x;
}else {
dd[2]=x;
}
if(y>0){
dd[0]=y;
}else {
dd[1]=y;
}
for(int j=0;j<dir.length();j++){
switch (dir.charAt(j)){
case 'U':
da[0]++;
continue;
case 'D':
da[1]--;
continue;
case 'L':
da[2]--;
continue;
case 'R':
da[3]++;
continue;
default:
}
}
if(da[0]>=dd[0] && da[1]<=dd[1] && da[2]<=dd[2] && da[3]>=dd[3]){
System.out.println("YES");
continue;
}
System.out.println("NO");
}
}
}
//class customItr<E> implements Iterator<E> {
//
// public customItr(Iterator<E> itr) {
// this.itr = itr;
// this.skipEle = new HashMap<>();
// }
//
// Iterator<E> itr;
// Map<E,Integer> skipEle;
//
// public void addSkipEle(E ele){
// if(skipEle.containsKey(ele)){
// skipEle.put(ele,skipEle.get(ele)+1);
// return;
// }
// skipEle.put(ele,1);
// }
//
// @Override
// public boolean hasNext() {
//
// return itr.hasNext();
// }
//
// @Override
// public E next() {
// return itr.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 8 | 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 | ad0424505c0c8bc11cf3ae72faac8f71 | 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 Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder("");
while(test-->0){
String ans = "NO";
String l[] = br.readLine().split(" ");
int n = Integer.parseInt(l[0]);
int m = Integer.parseInt(l[1]);
char c[] = br.readLine().toCharArray();
int count[] = new int [4];
for(int i=0;i<c.length;i++){
if(c[i] == 'U')count[0]++;
else if(c[i] == 'D')count[1]++;
else if(c[i]=='R')count[2]++;
else count[3]++;
}
boolean ok = false;
if(n == 0){
if(m<0){
m = Math.abs(m);
if(count[1]>=m)ok = true;
}else {
m = Math.abs(m);
if(count[0]>=m)ok = true;
}
}else if(m == 0){
if(n<0){
n = Math.abs(n);
if(count[3]>=n)ok = true;
}else{
n = Math.abs(n);
if(count[2]>=n)ok = true;
}
}
else if(n>0 && m>0){
n = Math.abs(n);
m = Math.abs(m);
if(count[2]>0 && count[0]>0 && count[2]>=n && count[0]>=m)ok = true;
}else if(n<0 && m>0){
n = Math.abs(n);
m = Math.abs(m);
if(count[3]>0 && count[0]>0 && count[3]>=n && count[0]>=m)ok = true;
}else if(n<0 && m<0){
n = Math.abs(n);
m = Math.abs(m);
if(count[3]>0 && count[1]>0 && count[3]>=n && count[1]>=m) ok = true;
}else {
n = Math.abs(n);
m = Math.abs(m);
if(count[2]>0 && count[1]>0 && count[2]>=n && count[1]>=m) ok =true;
}
if(ok)ans = "YES";
sb.append(ans);
sb.append("\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 8 | 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 | abbea9c1437ee5ee51686be76573dd2d | 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.lang.*;
import java.util.*;
import java.io.*;
public class Codeforces {
public void solve()throws IOException {
FastScanner fs = new FastScanner();
StringBuilder print = new StringBuilder();
int t = fs.nextInt();
while (t-- > 0 ){
int px = fs.nextInt(), py = fs.nextInt();
char[]str = fs.nextLine().toCharArray();
int u=0,d=0,r=0,l=0;
for(int i=0;i<str.length;i++){
if(str[i] == 'U')u++;
if(str[i] == 'D')d--;
if(str[i] == 'R')r++;
if(str[i] == 'L')l--;
}
if( px <= r && px >= l && py >= d && py <= u ){
print.append("YES\n");
}else{
print.append("NO\n");
}
}
System.out.println(print);
}
public static void main(String[]args)throws IOException{
try {
new Codeforces().solve();
}catch (Exception e){
// return;
e.printStackTrace();
}
}
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();
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
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());
}
}
}
| 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 8 | 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 | ccd4439adf8d90d1743df92a3357d27e | 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;
public class SpaceNavigation {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
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 long nextLong() throws IOException {
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 double nextDouble() throws IOException {
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() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
static Reader sc = new Reader();
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String args[]) throws IOException {
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 count_r = 0;
int count_l = 0;
int count_u = 0;
int count_d = 0;
for (char ch:str.toCharArray()){
if(ch == 'R')
count_r++;
if(ch == 'D')
count_d--;
if(ch == 'U')
count_u++;
if(ch == 'L')
count_l--;
}
if(x <= 0 && y <= 0){
if(count_l <= x && count_d <= y)
println("YES");
else
println("NO");
}
else if(x >= 0 && y <= 0){
if(count_r >= x && count_d <= y)
println("YES");
else
println("NO");
}
else if(x >= 0 && y >= 0){
if(count_r >= x && count_u >= y)
println("YES");
else
println("NO");
}
else if(x <= 0 && y >= 0){
if(count_l <= x && count_u >= y)
println("YES");
else
println("NO");
}
else if(x == 0 && y == 0)
println("YES");
}
bw.flush();
bw.close();
}
public static int inputInt() throws IOException {
return sc.nextInt();
}
public static long inputLong() throws IOException {
return sc.nextLong();
}
public static double inputDouble() throws IOException {
return sc.nextDouble();
}
public static String inputString() throws IOException {
return sc.readLine();
}
public static void print(String a) throws IOException {
bw.write(a);
}
public static void printSp(String a) throws IOException {
bw.write(a + " ");
}
public static void println(String a) throws IOException {
bw.write(a + "\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 8 | 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 | ebd22b5cff3327fae7a37529a559b32f | 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.lang.*;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws java.lang.Exception {
Scanner scn = new Scanner(System.in);
int t = Integer.parseInt(scn.next());
for(int i=0;i<t;i++){
int x = Integer.parseInt(scn.next()), y = Integer.parseInt(scn.next());
String str = scn.next();
int[] arr = new int[4];
for(int j=0;j<str.length();j++){
char ch = str.charAt(j);
if (ch == 'U') arr[0]++;
else if (ch == 'D') arr[1]++;
else if (ch == 'L') arr[2]++;
else if (ch == 'R') arr[3]++;
}
if(x>=0 && y>=0){
if(arr[3]>=x && arr[0]>=y){
System.out.println("YES");
continue;
}
} else if(x>=0 && y<=0){
if(arr[3]>=x && arr[1]>=-y){
System.out.println("YES");
continue;
}
} else if(x<=0 && y>=0){
if(arr[2]>=-x && arr[0]>=y){
System.out.println("YES");
continue;
}
} else if(x<=0 && y<=0){
if(arr[2]>=-x && arr[1]>=-y){
System.out.println("YES");
continue;
}
}
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 8 | 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 | 0c8284e544d3dea3689387fd9f927402 | 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 {
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 str=br.readLine();
String[] parts = str.split(" ");
int p =Integer.parseInt(parts[0]);
int q =Integer.parseInt(parts[1]);
String s = br.readLine();
int u=0,d=0,l=0,r=0;
for(int i=0;i<s.length();i++)
{ if(s.charAt(i)=='U')
u++;
if(s.charAt(i)=='L')
l++;
if(s.charAt(i)=='R')
r++;
if(s.charAt(i)=='D')
d++;
}
if(p==0)
{ if((q>0&&u>=q)||(q<0&&d>=-q))
System.out.println("YES");
else System.out.println("NO");
continue;
}
if(q==0)
{if((p>0&&r>=p)||(p<0&&l>=-p))
System.out.println("YES");
else System.out.println("NO");
continue;
}
if((p>0&&r>=p)||(p<0&&l>=-p))
if((q>0&&u>=q)||(q<0&&d>=-q))
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 8 | 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 | a197273281e80c8e0f37f56b2974ba50 | 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) {
long px, py;
px = sc.nextLong();
py = sc.nextLong();
int l=0,r=0,u=0,d=0;
String s;
s=sc.next();
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='L')
l++;
if(s.charAt(i)=='R')
r++;
if(s.charAt(i)=='U')
u++;
if(s.charAt(i)=='D')
d++;
}
if(px>=0&&py>=0)
{
if(r>=px&&u>=py)
System.out.println("YES");
else
System.out.println("NO");
}
else if(px<=0&&py<=0)
{
if(l>=-1*px&&d>=-1*py)
System.out.println("YES");
else
System.out.println("NO");
}
else if(px>=0&&py<=0)
{
if(r>=px&&d>=-1*py)
System.out.println("YES");
else
System.out.println("NO");
}
else if(px<=0&&py>=0)
{
if(l>=-1*px&&u>=py)
System.out.println("YES");
else
System.out.println("NO");
}
}
// String s = sc.next();
// char ch[] = s.toCharArray();
// int x = 0, y = 0;
// if (px > 0 && py > 0) {
// for (long i = 0; i < s.length(); i++) {
// if (ch[(int) i] == 'R') {
// x++;
// } else if (ch[(int) i] == 'U') {
// y++;
// }
// }
//
// } else if (px > 0 && py <0) {
// for (long i = 0; i < s.length(); i++) {
// if (ch[(int) i] == 'R') {
// x++;
// } else if (ch[(int) i] == 'D') {
// y--;
// }
// }
// } else if (px < 0 && py < 0) {
// for (long i = 0; i < s.length(); i++) {
// if (ch[(int) i] == 'L') {
// x--;
// } else if (ch[(int) i] == 'D') {
// y--;
// }
// }
// } else if (px < 0 && py > 0) {
// for (long i = 0; i < s.length(); i++) {
// if (ch[(int) i] == 'L') {
// x--;
// } else if (ch[(int) i] == 'U') {
// y++;
// }
// }
// }else if (px==0&&py>0){
// for (int i=0;i<s.length();i++){
// if (ch[i]=='U'){
// y++;
// }
// }
// }else if (px>0&&py==0){
// for (int i=0;i<s.length();i++){
// if (ch[i]=='R'){
// x++;
// }
// }
// }else if (px==0&&py<0){
// for (int i=0;i<s.length();i++){
// if (ch[i]=='D'){
// y--;
// }
// }
// }else if (px<0&&py==0){
// for (int i=0;i<s.length();i++){
// if (ch[i]=='L'){
// x--;
// }
// }
// }
// if (x==px&&y==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 8 | 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 | e48cf67ca876390e8afdfb227debe40b | 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 px = sc.nextInt();
int py = sc.nextInt();
String s = sc.next();
System.out.println(func(s, px, py));
}
}
static String func(String s, int px, int py){
int[] val = new int[4];
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='R')
val[0]++;
else if(s.charAt(i)=='L')
val[1]++;
else if(s.charAt(i)=='D')
val[2]++;
else if(s.charAt(i)=='U')
val[3]++;
}
int x = px;
int y = py;
int a = Math.abs(x);
int b = Math.abs(y);
if(px>=0 && py>=0){
if(val[0]>=a && val[3]>=b)
return "YES";
}
else if(px>=0 && py<=0){
if(val[0]>=a && val[2]>=b)
return "YES";
}
else if(px<=0 && py>=0){
if(val[1]>=a && val[3]>=b)
return "YES";
}
else if(px<=0 && py<=0){
if(val[1]>=a && val[2]>=b)
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 8 | 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 | 8920f783a123f64de9e52017ba8ac3b9 | 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 A1481 {
static FastScanner sc = new FastScanner();
public static void main(String[] args) {
int T = sc.nextInt();
while (T-- > 0) {
solve();
}
}
public static void solve() {
int[] p = sc.readArray(2);
String s = sc.next();
char b = '\u0000';
int[] a = new int[2];
int c = 0; //p[0] == x // p[1] == y
for (int k = 0; k < 2; k++) {
if (p[k] >= 0) {
if (k == 0)
b = 'R';
else
b = 'U';
} else {
if (k == 0)
b = 'L';
else
b = 'D';
}
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == b) {
a[k]++;
}
}
}
System.out.println(a[0] >= Math.abs(p[0]) && a[1] >= Math.abs(p[1]) ? "YES" : "NO");
}
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());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
return a;
}
}
} | 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 8 | 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 | e2ef2c16b0aa1ba51fd14d07ab7f31cd | 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 | /*----->Hope Can Set You Free<-----*/
import java.util.*;
public class SpaceNavigatiin{
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(),cntx=0,cnty=0;
StringBuilder sb=new StringBuilder(sc.next());
if(x>=0 && y>=0){
for(int i=0;i<sb.length();i++){
if(sb.charAt(i)=='R'){
cntx++;
}else if(sb.charAt(i)=='U'){
cnty++;
}
}
}else if(x<=0 && y<=0){
for(int i=0;i<sb.length();i++){
if(sb.charAt(i)=='L'){
cntx++;
}else if(sb.charAt(i)=='D'){
cnty++;
}
}
}else if(x<=0 && y>=0){
for(int i=0;i<sb.length();i++){
if(sb.charAt(i)=='L'){
cntx++;
}else if(sb.charAt(i)=='U'){
cnty++;
}
}
}else if(x>=0 && y<=0){
for(int i=0;i<sb.length();i++){
if(sb.charAt(i)=='R'){
cntx++;
}else if(sb.charAt(i)=='D'){
cnty++;
}
}
}if(x==0 && cnty>=Math.abs(y)){
System.out.println("YES");
}else if(y==0 && cntx>=Math.abs(x)){
System.out.println("YES");
}
else if(Math.abs(x)<=cntx && Math.abs(y)<=cnty && 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 8 | 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 | ad9e791ed410064d71b2f8d50ae3df9a | 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.ArrayList;
import java.util.List;
public class P1481A {
public static void main(String[] args) throws IOException{
BufferedReader io = new BufferedReader(new InputStreamReader(System.in));
Integer cnt = Integer.valueOf(io.readLine());
List<String> rs = new ArrayList<String>();
while (cnt > 0) {
cnt--;
String[] xy = io.readLine().split(" ");
Integer x = Integer.valueOf(xy[0]);
Integer y = Integer.valueOf(xy[1]);
String input = io.readLine();
int[] direction = new int[4];
for(int i = 0; i<input.length(); i++) {
if (input.charAt(i) == 'U') {
direction[0] = direction[0] + 1;
}else if (input.charAt(i) == 'D') {
direction[1] = direction[1] + 1;
}else if (input.charAt(i) == 'R') {
direction[2] = direction[2] + 1;
}else if (input.charAt(i) == 'L') {
direction[3] = direction[3] + 1;
}
}
if (x.compareTo(0) > 0 && y.compareTo(0) >= 0) {
if (direction[0] >= y && direction[2] >= x) {
rs.add("YES");
} else {
rs.add("NO");
}
} else if (x.compareTo(0) >= 0 && y.compareTo(0) < 0) {
if (direction[1] >= -y && direction[2] >= x) {
rs.add("YES");
} else {
rs.add("NO");
}
} else if (x.compareTo(0) < 0 && y.compareTo(0) <= 0) {
if (direction[1] >= -y && direction[3] >= -x) {
rs.add("YES");
} else {
rs.add("NO");
}
} else if (x.compareTo(0) <= 0 && y.compareTo(0) > 0) {
if (direction[0] >= y && direction[3] >= -x) {
rs.add("YES");
} else {
rs.add("NO");
}
}
}
for (String string : rs) {
System.out.println(string);
}
}
}
| 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 8 | 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 | 909491a613a61c17d6c1029c9ed49220 | 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.math.*;
//import java.io.*;
public class Experiment {
static Scanner in=new Scanner(System.in);
// static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
public static void sort(int ar[],int l,int r) {
if(l<r) {
int m=l+(r-l)/2;
sort(ar,l,m);
sort(ar,m+1,r);
merge(ar,l,m,r);
}
}
public static void merge(int ar[],int l,int m,int r) {
int n1=m-l+1;int n2=r-m;
int L[]=new int[n1];
int R[]=new int[n2];
for(int i=0;i<n1;i++)
L[i]=ar[l+i];
for(int i=0;i<n2;i++)
R[i]=ar[m+i+1];
int i=0;int j=0;int k=l;
while(i<n1 && j<n2) {
if(L[i]<=R[j]) {
ar[k++]=L[i++];
}else {
ar[k++]=R[j++];
}
}
while(i<n1)
ar[k++]=L[i++];
while(j<n2)
ar[k++]=R[j++];
}
public static int[] sort(int ar[]) {
sort(ar,0,ar.length-1);
//Array.sort uses O(n^2) in its worst case ,so better use merge sort
return ar;
}
public static void func(String s,int px,int py) {
int U=0,D=0,L=0,R=0;int ans=0;
for(int i=0;i<s.length();i++) {
char ch=s.charAt(i);
if(ch=='L') L++;
if(ch=='U') U++;
if(ch=='R') R++;
if(ch=='D') D++;
}
// System.out.println(R+" "+U);
// System.out.println(px+" "+py);
if((px>=0 && py>=0) ) {
if(R>=px && U>=py)
ans=1;
}
if(px<=0 && py<=0) {
if(L>=Math.abs(px) && D>=Math.abs(py))
ans=1;
}
if(px>=0 && py<=0) {
if(R>=px && D>=Math.abs(py))
ans=1;
}
if(px<=0 && py>=0) {
if(L>=Math.abs(px) && U>=py)
ans=1;
}
// System.out.println(ans);
if(ans==1)
System.out.println("YES");
else
System.out.println("NO");
}
public static void main(String[] args) {
int t=in.nextInt();
while(t!=0) {
int px=in.nextInt();
int py=in.nextInt();
String s=in.next();
func(s,px,py);
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 8 | 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 | 0edd884159a2f8dae68d848fd4049b07 | 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.math.*;
public class codeforces
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int tc=sc.nextInt();
while(tc-- > 0)
{
int px=sc.nextInt();
int py=sc.nextInt();
String s=sc.next();
int r1=0,l1=0,d1=0,u1=0;
for(int i=0;i<s.length();i++)
{
char ch=s.charAt(i);
if(ch=='R')
{
r1++;
}
if(ch=='L')
{
l1++;
}
if(ch=='U')
{
u1++;
}
if(ch=='D')
{
d1++;
}
}
int right=0,left=0,up=0,down=0;
if(px<0 && py<0)
{
left = 0-(px);
down = 0-(py);
if(left<=l1 && down<=d1)
System.out.println("YES");
else
System.out.println("NO");
}
else if(px>=0 && py<0)
{
right = px-0;
down = 0-py;
if(right<=r1 && down<=d1)
System.out.println("YES");
else
System.out.println("NO");
}
if(px<0 && py>=0)
{
up = py-0;
left = 0-px;
if(up<=u1 && left<=l1)
System.out.println("YES");
else
System.out.println("NO");
}
else if(px>=0 && py>=0)
{
up = py-0;
right=px-0;
if(right<=r1 && up<=u1)
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 8 | 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 | 4c64feabddc9a80e1388304cc4c6105d | 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
{
// your code goes here
FastReader s = new FastReader();
int t = s.nextInt();
while(t-- != 0){
int x = s.nextInt();
int y = s.nextInt();
int u,d,l,r;
u=d=l=r=0;
boolean xcor,ycor;
String st = s.next();
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) == 'L'){
l++;
}
else{
r++;
}
}
if(x>=0){
if(r>=x){
xcor = true;
}
else{
xcor = false;
}
}
else{
if(l>=Math.abs(x)){
xcor = true;
}
else{
xcor = false;
}
}
if(y>=0){
if(u>=y){
ycor = true;
}
else{
ycor = false;
}
}
else{
if(d>=Math.abs(y)){
ycor = true;
}
else{
ycor = false;
}
}
if(xcor && ycor){
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());
}
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 8 | 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 | 68bf1b5687058836f1401f0e144f8a4d | 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 A1481 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int px = scanner.nextInt(), u = 0, d = 0, r = 0, l = 0, py = scanner.nextInt();
String word = scanner.next();
boolean flagX = false, flagY = false;
for (int j = 0; j < word.length(); j++) {
if (word.charAt(j) == 'U') {
u++;
}
if (word.charAt(j) == 'D') {
d++;
}
if (word.charAt(j) == 'R') {
r++;
}
if (word.charAt(j) == 'L') {
l++;
}
}
if (px >= 0 && r >= px) {
flagX = true;
}
if (px < 0 && l >= -1 * px && l!=0) {
flagX = true;
}
if (py >= 0 && u >= py) {
flagY = true;
}
if (py < 0 && d >= -1 * py && d!=0) {
flagY = true;
}
if (flagX && flagY) {
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 8 | 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 | 741e4b564874de8b91d8f28074b6ae84 | 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 MainNetworking {
public static void main(String[] args) {
int testCases, r, l, u, d, px, py;
String sequence, answer="yes";
Scanner scanner = new Scanner(System.in);
testCases = scanner.nextInt();
for(int i=0; i<testCases; i++) {
px = scanner.nextInt();
py = scanner.nextInt();
scanner.nextLine();
sequence = scanner.nextLine();
r=l=u=d=0;
answer="yes";
for(int j=0; j<sequence.length(); j++) {
if (sequence.charAt(j) == 'R'){
r++;
} else if (sequence.charAt(j) == 'L'){
l--;
} else if (sequence.charAt(j) == 'U'){
u++;
} else if (sequence.charAt(j) == 'D'){
d--;
}
}
if (px >= 0) {
if (!(r >= px)) {
answer = "no";
}
} else if (px < 0) {
if (!(l <= px)) {
answer = "no";
}
}
if (py >= 0){
if (!(u >= py)) {
answer = "no";
}
} else if (py < 0) {
if (!(d <= py)) {
answer = "no";
}
}
System.out.println(answer);
}
}
} | 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 8 | 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 | 1df61f6f5c15462417c5ca013f29b631 | 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 in = new Scanner(System.in);
int t = in.nextInt(); // number of test cases
while (t-- > 0) {
int Px = in.nextInt(), Py = in.nextInt();
String s = in.next();
char x = '!', y = '!';
if (Px > 0) {
x = 'R';
} else if (Px < 0) {
x = 'L';
}
if (Py > 0) {
y = 'U';
} else if (Py < 0) {
y = 'D';
}
Px = Math.abs(Px);
Py = Math.abs(Py);
System.out.println(check(s, Px, Py, x, y));
}
}
private static String check(String s, int Px, int Py, char x, char y) {
for (int i = 0; i < s.length(); i++) {
if(Px == 0 && Py == 0){
return "YES";
}
if (s.charAt(i) == x && x !='!') {
Px--;
} else if (s.charAt(i) == y && y !='!') {
Py--;
}
}
if (x == '!') {
Px = 0;
}
if (y == '!') {
Py = 0;
}
return (Px <= 0 && Py <= 0) ? "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 8 | 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 | e29e49273afac44ecc3ab5ad820e7a30 | 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 question {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int l=0; l<t; l++) {
int x = sc.nextInt();
int y = sc.nextInt();
String s = sc.next();
int R=0, L=0, U=0, D=0, count=0;
for(int i=0; i<s.length(); i++) {
char ch = s.charAt(i);
if(ch=='R') R++;
else if(ch=='L') L++;
else if(ch=='U') U++;
else if(ch=='D') D++;
}
if(x>0) {
if(R>=x) count++; }
else
if(L>= Math.abs(x)) count++;
if(y>0) {
if(U>=y) 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 8 | 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 | e8af181002b5f417b3430503298f995a | 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 javax.tools.DocumentationTool.Location;
// import jdk.internal.net.http.common.Pair;
import java.lang.*;
// import org.graalvm.compiler.graph.spi.Canonicalizable.Binary;
import java.io.*;
public class sol {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String giveMeFile) throws IOException {
File file = new File("input.txt");
br = new BufferedReader(new FileReader(file));
}
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 boolean[] SES() {
int n = 1000001;
// SES Stands for SieveOfEratoSthenes
boolean isPrime[] = new boolean[n + 1];
Arrays.fill(isPrime, true);
isPrime[0] = false;
isPrime[1] = false;
for (int i = 2; i * i <= n; i++) {
for (int j = 2 * i; j <= n; j += i) {
isPrime[j] = false;
}
}
return isPrime;
}
public static int gcd(int a, int b) {
return a % b == 0 ? b : gcd(b, a % b);
}
public static long fastPower(int a, int b, int n) {
int res = 1;
while (b > 0) {
if ((b & 1) != 0) {
res = (res % n * a % n) % n;
}
a = (a % n * a % n) % n;
b = b >> 1; // dividing by 2
}
return res;
}
public static int first(int arr[], int low, int high, int x, int n) {
if (high >= low) {
int mid = low + (high - low) / 2;
if ((mid == 0 || x > arr[mid - 1]) && arr[mid] == x)
return mid;
else if (x > arr[mid])
return first(arr, (mid + 1), high, x, n);
else
return first(arr, low, (mid - 1), x, n);
}
return -1;
}
public static int last(int arr[], int low, int high, int x, int n) {
if (high >= low) {
int mid = low + (high - low) / 2;
if ((mid == n - 1 || x < arr[mid + 1]) && arr[mid] == x)
return mid;
else if (x < arr[mid])
return last(arr, low, (mid - 1), x, n);
else
return last(arr, (mid + 1), high, x, n);
}
return -1;
}
public static long sumPair(int arr[], int n) {
long sum = 0;
for (int i = n - 1; i >= 0; i--)
sum += i * arr[i] - (n - 1 - i) * arr[i];
return sum;
}
static int SE(int N) {
// Sieve of eratosthenes method
int[] arr = new int[N + 1];
for (int i = 2; i * i <= N; i++) {
if (arr[i] == 0)
for (int j = 2 * i; j <= N; j += i)
arr[j]++;
arr[i] = 1;
}
int max = arr[0];
for (int i = 1; i < arr.length; i++)
if (arr[i] > max)
max = arr[i];
return max;
// Return maximum element in arr[]
// return getMax(arr);
}
public static void main(String[] args) throws IOException {
// ************** Providing input File
// File file = new File("input.txt");
// BufferedReader br = new BufferedReader(new FileReader(file));
// *************** Input for Online Judges with Buffered Reader
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// ************* Input for Online Judges with Scanner class
// Reading with Scanner class
// Scanner sc = new Scanner(file);
// sc.useDelimiter("\\Z");
// ***************** Printing Outout to output file.
// PrintWriter printWriter = new PrintWriter(new BufferedWriter(new
// FileWriter("output.txt")));
// printWriter.println("something here");
// printWriter.close(); --->> // only this close method will flush the output
// from the buffer to the output file.
FastReader read = new FastReader();
int t = read.nextInt();
while (t-- != 0) {
int x = read.nextInt();
int y = read.nextInt();
String s = read.next();
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
if (map.containsKey(s.charAt(i))) {
map.put(s.charAt(i), map.get(s.charAt(i)) + 1);
} else {
map.put(s.charAt(i), 1);
}
}
// System.out.println(map);
int r = 0;
int u = 0;
int l = 0;
int d = 0;
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
if ((char) entry.getKey() == 'R') {
r = (int) entry.getValue();
} else if ((char) entry.getKey() == 'U') {
u = (int) entry.getValue();
} else if ((char) entry.getKey() == 'L') {
l = (int) entry.getValue();
} else {
d = (int) entry.getValue();
}
}
if (x >= 0 && y >= 0) {
// R and U
if (r >= x && u >= y) {
System.out.println("YES");
} else {
System.out.println("NO");
}
} else if (x < 0 && y < 0) {
// L and D
if (l >= Math.abs(x) && d >= Math.abs(y)) {
System.out.println("YES");
} else
System.out.println("NO");
} else if (x >= 0 && y < 0) {
// R and D
if (r >= x && d >= Math.abs(y)) {
System.out.println("YES");
} else
System.out.println("NO");
} else {
// L and U
if (l >= Math.abs(x) && u >= 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 8 | 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 | bdca346e605517a95f826ccf16d3fd08 | 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 P1481B {
static FastReaderP1481B in=new FastReaderP1481B();
public static void main(String...x){
// System.out.println("OK");
int test=i();
while(test-->0){
int px=i();
int py=i();
String s=string();
if(px==0 && py==0){
System.out.println("YES"); continue;
}
int i;
int l=0,r=0,u=0,d=0;
for(i=0;i<s.length();i++){
if(s.charAt(i)=='L') l+=1;
else if(s.charAt(i)=='R') r+=1;
else if(s.charAt(i)=='U') u+=1;
else d+=1;
}
//System.out.println(l+" "+r+" "+u+" "+d);
if(px<=0 && py<=0){
//System.out.println("1");
if(l>=Math.abs(px) && d>=Math.abs(py)){
System.out.println("YES");
}
else System.out.println("NO");
}
else if(px>=0 && py>=0){
//System.out.println("2");
if(r>=px && u>=py) System.out.println("YES");
else System.out.println("NO");
}
else if(px>= 0 && py<=0){
//System.out.println("3");
if(r>=px && d>=Math.abs(py)) System.out.println("YES");
else System.out.println("NO");
}
else {
//System.out.println("4");
if(l>=Math.abs(px)&& u>=py) System.out.println("YES");
else System.out.println("NO");
}
}
}
static int i(){return in.nextInt();}
static long l(){return in.nextLong();}
static String string(){return in.nextLine();}
static int[] inputIntgerArray(int N){
int A[]=new int[N];
for(int i=0; i<N; i++)A[i]=in.nextInt();
return A;
}
static long[] inputLongArray(int N) {
long A[]=new long[N];
for(int i=0; i<A.length; i++)A[i]=in.nextLong();
return A;
}
}
class FastReaderP1481B{
BufferedReader br;
StringTokenizer st;
public FastReaderP1481B()
{
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 8 | 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 | 3b146dd842921c3e6599e6c8f9013e8a | 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();
sc.nextLine();
String ans[]=new String[t];
for (int i = 0; i < t ; i++) {
int px=sc.nextInt(); int py=sc.nextInt();
sc.nextLine();
String s=sc.nextLine();
int countu=0;
int countd=0;
int countr=0;
int countl=0;
for (int j = 0; j < s.length() ; j++) {
if (s.charAt(j)=='U'){
countu++;
} else if (s.charAt(j)=='D'){
countd++;
} else if (s.charAt(j)=='R'){
countr++;
} else{
countl++;
}
}
boolean x=false;
boolean y=false;
if (px<0){
if (Math.abs(px)<=countl){
x=true;
}
} else if (px>=0){
if (px<=countr){
x=true;
}
}
if (py<0){
if (Math.abs(py)<=countd){
y=true;
}
} else if (py>=0){
if (py<=countu){
y=true;
}
}
if (x == true && y==true){
ans[i]="YES";
} else{
ans[i]="NO";
}
}
for (int i = 0; i < t ; i++) {
System.out.println(ans[i]);
}
}
} | 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 8 | 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 | 4a47527c4a88a7eb3d87761c01bf5185 | 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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
// import java.math.BigInteger;
import java.util.*;
public class A {
public static void main(String[] args) {
int T = in.nextInt();
TEST:
while (T-- > 0) {
int x = in.nextInt(), y = in.nextInt();
int xmin = 0, xmax = 0, ymin = 0, ymax = 0;
char[] order = in.next().toCharArray();
for (char dir : order) {
if (dir == 'U') {
ymax++;
} else if (dir == 'D') {
ymin--;
} else if (dir == 'R') {
xmax++;
} else {
xmin--;
}
}
out.println((xmin <= x && x <= xmax && ymin <= y && y <= ymax) ? "YES" : "NO");
}
out.flush();
out.close();
}
// Handle I/O
static int MOD = (int) (1e9 + 7);
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
st = null;
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
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 8 | 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 | 9d12c98144f0708f1b121863dd99a6e4 | 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 : dante1
* created : 05/02/2021 20:06
*******************************************************************************/
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
// import java.math.BigInteger;
import java.util.*;
public class a {
public static void main(String[] args) {
int T = in.nextInt();
TEST:
while (T-- > 0) {
int px = in.nextInt(), py = in.nextInt();
String s = in.next();
int l = 0, r = 0, d = 0, u = 0;
for (char c : s.toCharArray()) {
if (c == 'U') {
u++;
} else if (c == 'D') {
d++;
} else if (c == 'R') {
r++;
} else if (c == 'L') {
l++;
}
}
if (px < 0 && l < Math.abs(px)) {
out.println("NO");
continue TEST;
}
if (px > 0 && r < px) {
out.println("NO");
continue TEST;
}
if (py > 0 && u < py) {
out.println("NO");
continue TEST;
}
if (py < 0 && d < Math.abs(py)) {
out.println("NO");
continue TEST;
}
out.println("YES");
}
out.flush();
}
// Handle I/O
static int MOD = (int) (1e9 + 7);
static FastScanner in = new FastScanner();
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
st = null;
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readIntArray(int size) {
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = nextInt();
}
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
long[] readLongArray(int size) {
long[] arr = new long[size];
for (int i = 0; i < size; i++) {
arr[i] = nextLong();
}
return arr;
}
double nextDouble() {
return Double.parseDouble(next());
}
double[] readDoubleArray(int size) {
double[] arr = new double[size];
for (int i = 0; i < size; i++) {
arr[i] = nextDouble();
}
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 8 | 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 | ac72e5d2c1283f026d0be43bfe4a9db8 | 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 SpaceNavigation {
String yes = "YES", no = "NO";
MyScanner scanner = new MyScanner();
private String canReach(String path, int x, int y) {
int LCnt = 0, RCnt = 0, UCnt = 0, DCnt = 0;
for (char c : path.toCharArray()) {
if (c == 'L') LCnt++;
else if (c == 'R') RCnt++;
else if (c == 'U') UCnt++;
else DCnt++;
}
boolean xReach = x == 0 || x > 0 && RCnt >= x || x < 0 && LCnt >= -x;
boolean yReach = y == 0 || y > 0 && UCnt >= y || y < 0 && DCnt >= -y;
return xReach && yReach ? yes : no;
}
public static void main(String[] args) {
SpaceNavigation test = new SpaceNavigation();
int n = test.scanner.nextInt();
for (int i = 0; i < n; i++) {
int x = test.scanner.nextInt(), y = test.scanner.nextInt();
String path =test.scanner.nextLine();
String ans = test.canReach(path, x, y);
if (i != n - 1) {
System.out.println(ans);
}
else {
System.out.print(ans);
}
}
}
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
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 8 | 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 | 8fa4a518f572fab64daf71684118db78 | 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 SpaceNavigation {
public static final int SIZE = 26;
public static void main(String[] args) {
FastReader fastReader = new FastReader();
int t = fastReader.nextInt();
while (t-- > 0) {
int px = fastReader.nextInt();
int py = fastReader.nextInt();
String s = fastReader.nextLine();
char[] strArray = s.toCharArray();
int n = strArray.length;
int freq[] = new int[SIZE];
for (int i = 0; i < n; i++) {
freq[strArray[i] - 'A']++;
}
int freqD = freq[3];
int freqL = freq[11];
int freqR = freq[17];
int freqU = freq[20];
if (((px >= 0 && freqR >= px) || (px <= 0 && -freqL <= px)) &&
((py >= 0 && freqU >= py) || (py <= 0 && -freqD <= py)))
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());
}
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 8 | 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 | 2fa466f808861e1fdfaab4673036bc6d | 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 Check2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// long modulo=10;
long t = sc.nextInt();
for (int i = 1; i <= t; i++) {
int px = sc.nextInt();
int py = sc.nextInt();
String s = sc.next();
Map<Character,Integer> map=new HashMap<>();
map.put('U',0);
map.put('D',0);
map.put('R',0);
map.put('L',0);
for (int j = 0; j < s.length(); j++) {
char ch = s.charAt(j);
// map.putIfAbsent(ch, 0);
map.put(ch,map.get(ch)+1);
}
if(px>=0 && py<=0){
if(map.get('R')>=px && map.get('D')>=Math.abs(py)){
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(px>=0 && py>=0){
if(map.get('R')>=px && map.get('U')>=Math.abs(py)){
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(px<=0 && py>=0){
if(map.get('L')>=Math.abs(px) && map.get('U')>=Math.abs(py)){
System.out.println("YES");
}else {
System.out.println("NO");
}
}else if(px<=0 && py<=0){
if(map.get('L')>=Math.abs(px) && map.get('D')>=Math.abs(py)){
System.out.println("YES");
}else {
System.out.println("NO");
}
}else {
System.out.println("YES");
}
}
}
public static long sweetness(long a) {
long c = 0;
for (long i = 1; i <= a; i++) {
if (gcd(i, a) == 1) {
c++;
}
}
return c;
}
public static long power(long a, long b, long c) {
long ans = 1;
while (b != 0) {
if (b % 2 == 1) {
ans = ans * a;
ans %= c;
}
a = a * a;
a %= c;
b /= 2;
}
return ans;
}
public static long power1(long a, long b, long c) {
long ans = 1;
while (b != 0) {
if (b % 2 == 1) {
ans = multiply(ans, a, c);
}
a = multiply(a, a, c);
b /= 2;
}
return ans;
}
public static long multiply(long a, long b, long c) {
long res = 0;
a %= c;
while (b > 0) {
if (b % 2 == 1) {
res = (res + a) % c;
}
a = (a + a) % c;
b /= 2;
}
return res % c;
}
public static long totient(long n) {
long result = n;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0) {
//sum=sum+2*i;
while (n % i == 0) {
n /= i;
// sum=sum+n;
}
result -= result / i;
}
}
if (n > 1) {
result -= result / n;
}
return result;
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
public static boolean[] primes(int n) {
boolean[] p = new boolean[n + 1];
p[0] = false;
p[1] = false;
for (int i = 2; i <= n; i++) {
p[i] = true;
}
for (int i = 2; i * i <= n; i++) {
if (p[i]) {
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
return p;
}
}
| 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 8 | 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 | f98220ef67450856a0a798334088eb1e | 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 in = new Scanner(System.in);
int t = in.nextInt();
while (t-- > 0) {
int x = in.nextInt();
int y = in.nextInt();
String str = in.next();
int xCounter = 0;
int yCounter = 0;
if (x == 0 && y == 0)
System.out.println("YES");
else if (x > 0 && y > 0) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'R')
xCounter++;
else if (str.charAt(i) == 'U')
yCounter++;
}
if (xCounter >= x && yCounter >= y)
System.out.println("YES");
else
System.out.println("NO");
} else if (x > 0 && y < 0) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'R')
xCounter++;
else if (str.charAt(i) == 'D')
yCounter--;
}
if (xCounter >= x && yCounter <= y)
System.out.println("YES");
else
System.out.println("NO");
} else if (x < 0 && y > 0) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'L')
xCounter--;
else if (str.charAt(i) == 'U')
yCounter++;
}
if (xCounter <= x && yCounter >= y)
System.out.println("YES");
else
System.out.println("NO");
} else if (x < 0 && y < 0) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'L')
xCounter--;
else if (str.charAt(i) == 'D')
yCounter--;
}
if (xCounter <= x && yCounter <= y)
System.out.println("YES");
else
System.out.println("NO");
} else if (x > 0 && y == 0) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'R')
xCounter++;
}
if (xCounter >= x)
System.out.println("YES");
else
System.out.println("NO");
} else if (x < 0 && y == 0) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'L')
xCounter--;
}
if (xCounter <= x)
System.out.println("YES");
else
System.out.println("NO");
} else if (y > 0 && x == 0) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'U')
yCounter++;
}
if (yCounter >= y)
System.out.println("YES");
else
System.out.println("NO");
} else if (y < 0 && x == 0) {
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'D')
yCounter--;
}
if (yCounter <= 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 8 | 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 | 351e44c5d51f53ed47370c1de190f899 | 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 HelloWorld{
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
int T = Integer.parseInt(br.readLine());
while(T-- > 0) {
StringTokenizer st = new StringTokenizer(br.readLine());
int px = Integer.parseInt(st.nextToken());
int py = Integer.parseInt(st.nextToken());
String s = br.readLine();
int[] a = new int[4];
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i) == 'R') a[0]++;
else if(s.charAt(i) == 'D') a[1]++;
else if(s.charAt(i) == 'L') a[2]++;
else a[3]++;
}
boolean check = true;
if(px > 0 && py == 0) {
px = Math.abs(px);
if(px > a[0]) check = false;
}
else if(px < 0 && py == 0) {
px = Math.abs(px);
if(px > a[2]) check = false;
}
else if(px == 0 && py > 0) {
py = Math.abs(py);
if(py > a[3]) check = false;
}
else if(px == 0 && py < 0) {
py = Math.abs(py);
if(py > a[1]) check = false;
}
else if(px > 0 && py > 0) {
px = Math.abs(px);
py = Math.abs(py);
if(px > a[0] || py > a[3]) check = false;
}
else if(px > 0 && py < 0) {
px = Math.abs(px);
py = Math.abs(py);
if(px > a[0] || py > a[1]) check = false;
}
else if(px < 0 && py > 0) {
px = Math.abs(px);
py = Math.abs(py);
if(px > a[2] || py > a[3]) check = false;
}
else {
px = Math.abs(px);
py = Math.abs(py);
if(px > a[2] || py > a[1]) check = false;
}
if(check) writer.println("YES");
else writer.println("NO");
}
writer.close();
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 8 | 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 | 178b22a0f55eaafb9cf6dbe987847e04 | 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 javax.print.attribute.standard.Finishings;
import java.math.*;
public class SpaceNavigation {
static final Random random = new Random();
static PrintWriter out = new PrintWriter((System.out));
static Reader sc = new Reader();
public static void main(String args[]) throws IOException {
int t = sc.nextInt();
while (t-- > 0) {
int px = sc.nextInt();
int py = sc.nextInt();
String s = sc.next();
int cr = 0; // x+1;
int cl = 0;// x-1;
int cu = 0;// y+1
int cd = 0;// y-1
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'R')
cr++;
if (s.charAt(i) == 'L')
cl++;
if (s.charAt(i) == 'U')
cu++;
if (s.charAt(i) == 'D')
cd++;
}
if ((px >= 0 && cr >= Math.abs(px)) && (py >= 0 && cu >= Math.abs(py))) {
System.out.println("yes");
} else if ((px <= 0 && cl >= Math.abs(px)) && (py >= 0 && cu >= Math.abs(py))) {
System.out.println("yes");
} else if ((px >= 0 && cr >= Math.abs(px)) && (py <= 0 && cd >= Math.abs(py))) {
System.out.println("yes");
} else if ((px <= 0 && cl >= Math.abs(px)) && (py <= 0 && cd >= Math.abs(py))) {
System.out.println("yes");
} else
System.out.println("No");
}
}
// Fast Input Output
static class Reader {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public boolean hasNext() {
String next = null;
try {
next = br.readLine();
} catch (Exception e) {
}
if (next == null) {
return false;
}
st = new StringTokenizer(next);
return true;
}
}
// EFFICIENT SORTING Ascending
static void ruffleSortAsc(Integer[] 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);
}
// EFFICIENT SORTING Descending
static void ruffleSortDesc(Integer[] 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, Collections.reverseOrder());
}
// Array Sum
static long sum(Integer[] arr) {
long sum = 0;
for (int i : arr)
sum += i;
return sum;
}
// swap array elements
static void swap(int arr1[], int arr2[], int i, int j) {
int temp = arr1[i];
arr1[i] = arr2[j];
arr2[j] = temp;
}
// reading array value;
static void read(Integer[] arr) {
for (int i = 0; i < arr.length; i++)
arr[i] = sc.nextInt();
return;
}
// reading arraylistValue
// check for even odd
static boolean isEven(int n) {
return ((n & 1) != 1);
}
// max in a array
static int max(Integer[] arr) {
int max = Integer.MIN_VALUE;
for (int i = 0; i < arr.length; i++)
if (max < arr[i])
max = arr[i];
return max;
}
// print array
static void printarr(Integer arr[]) {
for (int i : arr)
System.out.println(i);
}
// ceil of two elements
static long ceil(int a, int b) {
return (long) Math.ceil(((double) a / (double) b));
}
// floor of two elements
static long floor(int a, int b) {
return (long) Math.floor(((double) a / (double) b));
}
static boolean checkPrimeFactor(int n) {
for (int i = 2; i < n; i++) {
while (n % i == 0) {
return true;
}
}
return 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 8 | 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 | 37e0a29c01dfe5836a0d9a7183f1d800 | 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 codeForces {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
while(T-- > 0){
int x = scan.nextInt();
int y = scan.nextInt();
int l = 0, r = 0 , u = 0 , d = 0;
String str = scan.next();
for(int i = 0; i < str.length(); i++){
if(str.charAt(i) == 'L'){
l++;
}else if(str.charAt(i) == 'R'){
r++;
}else if(str.charAt(i) == 'U'){
u++;
}else{
d++;
}
}
boolean ans1 = false, ans2 = false;
if(x >= 0){
if(r >= x){
ans1 = true;
}
}else{
if(l >= -1 * x)
ans1 = true;
}
if(y >= 0){
if(u >= y){
ans2 = true;
}
}else{
if(d >= -1 * y)
ans2 = true;
}
if(ans1 && ans2)
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 8 | 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 | 6b5bbb31b98f59f0f63cbc3ddc14c394 | 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();
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=u+1;
}
else if(s.charAt(i)=='D'){
d=d+1;
}
else if(s.charAt(i)=='R'){
r=r+1;
}
else{
l=l+1;
}
}
if(px>=0 && py>=0){
if(r>=px && u>=py){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
else if(px>=0 && py<=0){
if(r>=px && d>=Math.abs(py)){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
else if(px<=0 && py<=0){
if(l>=Math.abs(px) && d>=Math.abs(py)){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
else if(px<=0 && py>=0){
if(l>=Math.abs(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 8 | 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 | e52b12bdf8676afeae7316a99e291a90 | 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[]){
FScanner in = new FScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
while(t-->0) {
int x=in.nextInt();
int y=in.nextInt();
char ch[]=in.next().toCharArray();
int u=0,d=0,r=0,l=0;
for(int i=0;i<ch.length;i++)
{
if(ch[i]=='U')
u++;
else if(ch[i]=='D')
d++;
else if(ch[i]=='R')
r++;
else
l++;
}
if((x>=0 &&r>=x) && (y>=0 && u>=y))
out.println("Yes");
else if( (x<0 && l>=Math.abs(x)) &&(y<0 && d>=Math.abs(y)))
out.println("Yes");
else if((x<0 && l>=Math.abs(x)) && (y>=0 && u>=y))
out.println("Yes");
else if((x>=0 && r>=x) && (y<0 && d>=Math.abs(y)))
out.println("Yes");
else
out.println("No");
}
out.close();
}
static class FScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer sb = new StringTokenizer("");
String next(){
while(!sb.hasMoreTokens()){
try{
sb = new StringTokenizer(br.readLine());
} catch(IOException e){ }
}
return sb.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
float nextFloat(){
return Float.parseFloat(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 8 | 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 | ef8a3e2c050e65646159214209c9ebbb | 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.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
String[] s = br.readLine().split(" ");
int x = Integer.parseInt(s[0]);
int y = Integer.parseInt(s[1]);
String str = br.readLine();
int u = 0, d = 0, l = 0, r = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'U')
u++;
else if (str.charAt(i) == 'D')
d--;
else if (str.charAt(i) == 'L')
l--;
else
r++;
}
if ((x == l || x == r) && (y == u || y == d))
log.write("YES\n");
else
log.write(check(x, y, u, d, l, r) == true ? "YES\n" : "NO\n");
}
log.flush();
}
static boolean check(int x, int y, int u, int d, int l, int r) {
boolean flag = false;
if (x < 0) {
flag = l <= x;
} else if (x >= 0) {
flag = r >= x;
}
if (!flag)
return false;
if (y < 0) {
flag = d <= y;
} else if (y >= 0) {
flag = u >= y;
}
return flag;
}
}
| 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 8 | 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 | 7db3a3333126fa476a3af0718df286d9 | 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 codeforces;
import java.util.Scanner;
public class ProblemA {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int x=0,y=0;
int px=sc.nextInt();
int py=sc.nextInt();
String s=sc.next().toUpperCase();
char c[]=s.toCharArray();
//if()
int r=0,l=0,u=0,d=0;
for(int i=0;i<c.length;i++) {
if(c[i]=='U') {
u++;
}
if(c[i]=='D') {
d--;
}
if(c[i]=='R') {
r++;
}
if(c[i]=='L') {
l--;
}
}
//System.out.println(x+" "+y);
// if(px>0) {
// if(py>0) {
// if()
// }
// }
if(r>=px&&l<=px && u>=py&&d<=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 8 | 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 | 2a81e29dff606a7a184b99c1f19ffa23 | 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 Scanner in =new Scanner(System.in);
static final Random random=new Random();
static Set<Integer>set=new HashSet<>();
static List<Integer>list=new ArrayList<>();
static Map<Integer,Integer>map=new HashMap<>();
static int mod=1000_000_007;
public static void main(String[] args) {
int tt=in.nextInt();//in.nextLine();
outer:while(tt-->0) {
int px=in.nextInt();int py=in.nextInt();in.nextLine();
char s[]=in.nextLine().toCharArray();
int l=0,r=0,u=0,d=0;
for(char c:s){
if(c=='U')u++;
else if(c=='R')r++;
else if(c=='L')l++;
else if(c=='D')d++;
}
if(px>=0 && py>=0){
if(u<py || r<px)System.out.println("NO");
else System.out.println("YES");
}
else if(px>=0 && py<=0){
if(d<Math.abs(py) || r<px)System.out.println("NO");
else System.out.println("YES");
}
else if(px<=0 && py>=0){
if(u<py || l<Math.abs(px))System.out.println("NO");
else System.out.println("YES");
}
else if(px<=0 && py<=0){
if(d<Math.abs(py) || l<Math.abs(px))System.out.println("NO");
else System.out.println("YES");
}
}
}
static int lb(int ind,int[] a,int k){
int l=ind;
int h=a.length-1;
int r=ind;
while(l<=h){
int mid=(l+h)/2;
if(a[ind]+a[mid]>=k){
r=mid;l=mid+1;
}
else h=mid-1;
}
return r;
}
static int nCr(int n,int r,int p){
if (r == 0) return 1;
if(r==1)return n;
return ((int)fact(n)*modInverse((int)fact(r),p)%p * modInverse((int)fact(n-r),p) % p)%p;
}
static int modInverse(int n, int p){
return power(n, p-2, p);
}
static int power(int x,int y,int p){
int res = 1;
x= x % p;
while (y>0){
if (y%2==1)
res= (res*x)% p;
y= y >> 1;
x= (x*x)% p;
}
return res;
}
static int[]readAr(long n) {
int[] a=new int[(int)n];
for (int i=0; i<n; i++) {a[i]=in.nextInt();}
return a;
}
static int fact(int k){
long[]f=new long[10001];f[1]=1;
for(int i=2;i<10001;i++){
f[i]=(i*f[i-1]% mod);
}
return (int)f[k];
}
static void ruffleSort(int[] a) {
int n=a.length;
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 void reverse(int []a){
int n= a.length;
for(int i=0;i<n/2;i++){
int temp=a[i];
a[i]=a[n-i-1];
a[n-i-1]=temp;
a[i]=a[i];
}
//debug(a);
}
static void debug(int []a) {
for (int i=0; i<a.length;i++) System.out.print(a[i]+" ");
System.out.println();
}
static void print(List<Integer>s) {
for(int x:s) System.out.print(x+",");
System.out.println();
}
static int gcd(int a, int b) {
return b==0 ? a : gcd(b, a % b);
}
static int find_max(int []a){
int m=Integer.MIN_VALUE;
for(int x:a)m=Math.max(x,m);
return m;
}
static int find_min(int []a){
int m=Integer.MAX_VALUE;
for(int x:a)m=Math.min(x,m);
return m;
}
} | 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 8 | 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 | 22b0aaf9f3dc0bc22e945852d3c43e27 | 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.StringTokenizer;
import static java.lang.Double.parseDouble;
import static java.lang.Integer.compare;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.System.in;
public class Main {
private static final int MOD = (int) (1E9 + 7);
static FastScanner scanner = new FastScanner(in);
public static void main(String[] args) throws IOException {
// Write your solution here
int t = 1;
t = parseInt(scanner.nextLine());
while (t-- > 0) {
solve();
}
}
private static void solve() throws IOException {
int x = scanner.nextInt();
int y = scanner.nextInt();
String s = scanner.nextLine();
int u = 0, d = 0, r = 0, l = 0;
for (char c : s.toCharArray()) {
if (c == 'U') u++;
if (c == 'D') d++;
if (c == 'R') r++;
if (c == 'L') l++;
}
boolean xAxis = false, yAxis = false;
if (x >= 0 && r >= x) xAxis = true;
if (x <= 0 && l >= Math.abs(x)) xAxis = true;
if (y >= 0 && u >= y) yAxis = true;
if (y <= 0 && d >= Math.abs(y)) yAxis = true;
if (xAxis && yAxis) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
private static int add(int a, int b) {
long res = ((long) (a + MOD) % MOD + (b + MOD)) % MOD;
return (int) res;
}
private static int mul(int a, int b) {
long res = ((long) a % MOD * b % MOD) % MOD;
return (int) res;
}
private static int pow(int a, int b) {
a %= MOD;
int res = 1;
while (b > 0) {
if ((b & 1) != 0)
res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
private static int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
private static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
private static class Pair implements Comparable<Pair> {
int index, value;
public Pair(int index, int value) {
this.index = index;
this.value = value;
}
public int compareTo(Pair o) {
if (value != o.value) return compare(value, o.value);
return compare(index, o.index);
}
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
return null;
}
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return parseInt(next());
}
long nextLong() {
return parseLong(next());
}
double nextDouble() {
return 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 8 | 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 | c59dc7c54e32dd30c0855e6b74cc2baf | 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 Solution {
public static void main(String[] args) throws Exception
{
FastReader fr=new FastReader();
int t=fr.nextInt();
while(t-->0) {
int x=fr.nextInt();
int y=fr.nextInt();
String s=fr.next();
int r=0;
int u=0;
int d=0;
int l=0;
for(int i=0;i<s.length();i++) {
char c=s.charAt(i);
if(c=='U')
u++;
else if(c=='R')
r++;
else if(c=='D')
d++;
else
l++;
}
if(x>=0&&y>=0) {
if(u>=y&&r>=x)
System.out.println("YES");
else
System.out.println("NO");
}
else if(x<=0&&y<=0) {
if(d>=Math.abs(y)&&l>=Math.abs(x))
System.out.println("YES");
else
System.out.println("NO");
}
else if(x>=0&&y<=0) {
if(d>=Math.abs(y)&&r>=x)
System.out.println("YES");
else
System.out.println("NO");
}
else if(x<=0&&y>=0) {
if(u>=y&&l>=Math.abs(x))
System.out.println("YES");
else
System.out.println("NO");
}
}
}
public static boolean pos(String s,int idx,int x,int y,int curx,int cury,Boolean dp[][]) {
if(idx>=s.length())
{
if(curx==x&&cury==y)
return true;
else
return false;
}
if(dp[Math.abs(curx)][Math.abs(cury)]!=null)
return dp[Math.abs(curx)][Math.abs(cury)];
boolean ch1=pos(s,idx+1,x,y,curx,cury,dp);
char c=s.charAt(idx);
if(c=='R')
curx++;
else if(c=='L')
curx--;
else if(c=='U')
cury++;
else
cury--;
boolean ch2=pos(s,idx+1,x,y,curx,cury,dp);
return dp[Math.abs(curx)][Math.abs(cury)]=ch1||ch2;
}
}
class Pair{
int x;
int y;
Pair(int x,int y){
this.x=x;
this.y=y;
}
}
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 8 | 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 | b25f1430fb446a090322ba3e306655c6 | 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();
sc.nextLine();
while (t-- > 0) {
int x = sc.nextInt();
int y = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
int l = 0;
int r = 0;
int u = 0;
int d = 0;
for (char c : s.toCharArray()) {
if (c == 'R') {
r++;
} else if (c == 'L') {
l++;
} else if (c == 'U') {
u++;
} else {
d++;
}
}
boolean can = true;
if (x < 0) {
if (Math.abs(x) > l) {
can = false;
}
} else {
if (x > r) {
can = false;
}
}
if (y < 0) {
if (Math.abs(y) > d) {
can = false;
}
} else {
if (y > u) {
can = false;
}
}
if (can) {
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 8 | 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 | e6ee317c2032d4352b699fa84a446544 | 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 Main {
public static void main(String[] args) throws IOException {
int n=nextInt();
for (int i = 0; i < n; i++) {
int x=nextInt();
int y=nextInt();
String s=nextToken();
int[]b=new int[4];
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j)=='U')b[0]++;
else if (s.charAt(j)=='D')b[1]++;
else if (s.charAt(j)=='R')b[2]++;
else if (s.charAt(j)=='L')b[3]++;
}
if (x>=0&&y>=0){
if (b[2]>=x&&b[0]>=y)out.println("YES");
else out.println("NO");
}
else if (x>=0){
if (b[2]>=x&&b[1]>=-y)out.println("YES");
else out.println("NO");
}
else if (y>=0){
if (b[3]>=-x&&b[0]>=y)out.println("YES");
else out.println("NO");
}
else{
if (b[3]>=-x&&b[1]>=-y)out.println("YES");
else out.println("NO");
}
}
out.close();
}
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
static StringTokenizer in = new StringTokenizer("");
public static boolean hasNext() throws IOException {
if (in.hasMoreTokens()) return true;
String s;
while ((s = br.readLine()) != null) {
in = new StringTokenizer(s);
if (in.hasMoreTokens()) return true;
}
return false;
}
public static String nextToken() throws IOException {
while (!in.hasMoreTokens()) {
in = new StringTokenizer(br.readLine());
}
return in.nextToken();
}
public static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public static double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
public static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
} | 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 8 | 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 | 47f0b4c6b8a890f18af8b22a8b5f083d | 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.*;
import java.util.LinkedList;
import java.util.Queue;
import static java.lang.Math.*;
public class Cf294 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[] nextArray(int n)
{
int arr[] = new int[n];
int i;
for(i=0;i<n;i++)
{
arr[i] = nextInt();
}
return arr;
}
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 int[] nextIntArray(int n)
{
int i;
int arr[] = new int[n];
for(i=0;i<n;i++)
{
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int n)
{
int i;
long arr[] = new long[n];
for(i=0;i<n;i++)
{
arr[i] = nextLong();
}
return arr;
}
public double[] nextDoubleArray(int n)
{
int i;
double arr[] = new double[n];
for(i=0;i<n;i++)
{
arr[i] = nextDouble();
}
return arr;
}
public Integer[] IntegerArray(int n)
{
int i;
Integer arr[] = new Integer[n];
for(i=0;i<n;i++)
{
arr[i] = nextInt();
}
return arr;
}
public Long[] LongArray(int n)
{
int i;
Long arr[] = new Long[n];
for(i=0;i<n;i++)
{
arr[i] = nextLong();
}
return arr;
}
public Double[] DoubleArray(int n)
{
int i;
Double arr[] = new Double[n];
for(i=0;i<n;i++)
{
arr[i] = nextDouble();
}
return arr;
}
public ArrayList<ArrayList<Integer>> getGraph(int n,int m)
{
ArrayList<ArrayList<Integer>> g =new ArrayList<>();
int i;
for(i=0;i<=n;i++)
{
g.add(new ArrayList<>());
}
for(i=0;i<m;i++)
{
int x = nextInt();
int y = nextInt();
g.get(x).add(y);
g.get(y).add(x);
}
return g;
}
public ArrayList<ArrayList<Integer>> getTree(int n)
{
ArrayList<ArrayList<Integer>> g =new ArrayList<>();
int i;
for(i=0;i<=n;i++)
{
g.add(new ArrayList<>());
}
for(i=0;i<n-1;i++)
{
int x = nextInt();
int y = nextInt();
g.get(x).add(y);
g.get(y).add(x);
}
return g;
}
}
public static int maxInt(int arr[])
{
int max = Integer.MIN_VALUE;
for(int i : arr)
{
max = Math.max(i,max);
}
return max;
}
public static int minInt(int arr[])
{
int min = Integer.MAX_VALUE;
for(int i : arr)
{
min = Math.min(i,min);
}
return min;
}
public static long maxLong(long arr[])
{
long max = Long.MIN_VALUE;
for(long i : arr)
{
max = Math.max(i,max);
}
return max;
}
public static long minLong(long arr[])
{
long min = Long.MAX_VALUE;
for(long i : arr)
{
min = Math.min(i,min);
}
return min;
}
public static double maxDouble(double arr[])
{
double max = Double.MIN_VALUE;
for(double i : arr)
{
max = Math.max(i,max);
}
return max;
}
public static double minDouble(double arr[])
{
double min = Double.MAX_VALUE;
for(double i : arr)
{
min = Math.min(i,min);
}
return min;
}
void merge(int arr[], int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int [n1];
int R[] = new int [n2];
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
int i = 0, j = 0;
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
void sort(int arr[], int l, int r)
{
if (l < r)
{
int m = (l+r)/2;
sort(arr, l, m);
sort(arr , m+1, r);
merge(arr, l, m, r);
}
}
static class Pair
{
int x,y;
public Pair(int x,int y)
{
this.x = x;
this.y = y;
}
public static Comparator<Pair> sortX = new Comparator<Pair>(){
public int compare(Pair p1,Pair p2)
{
if(p1.x==p2.x)
{
return (int)(p1.y-p2.y);
}
return (int)(p1.x-p2.x);
}
};
public static Comparator<Pair> sortY = new Comparator<Pair>(){
public int compare(Pair p1,Pair p2)
{
if(p1.y==p2.y)
{
return (int)(p1.x-p2.x);
}
return (int)(p1.y-p2.y);
}
};
public static Comparator<Pair> custom = new Comparator<Pair>(){
public int compare(Pair p1,Pair p2)
{
if(p1.x-p2.x==0)
{
return -1*(p1.y-p2.y);
}
return -1*(p1.x-p2.x);
}
};
public boolean equals(Object obj)
{
if (obj == null) return false;
if (!(obj instanceof Pair))
return false;
return (this.x == ((Pair) obj).x && this.y == ((Pair)obj).y);
}
public int hashCode()
{
if(x<0 || y<0)
{
return (int)(-5*x+-32*y);
}
return (int)(5*(x+y));
}
}
static class DPair
{
Pair s,d;
public DPair(Pair s,Pair d)
{
this.s = s;
this.d = d;
}
public boolean equals(Object obj)
{
if (obj == null) return false;
if (!(obj instanceof DPair))
return false;
return (this.s.x == ((DPair) obj).s.x && this.s.y == ((DPair) obj).s.y && this.d.x == ((DPair)obj).d.x && this.d.y == ((DPair) obj).d.y);
}
public int hashCode()
{
return 5*(s.x+s.y+d.x+d.y);
}
}
static class DSU
{
public static int rank[],parent[];
int n;
HashMap<Integer,Integer> map = new HashMap<>();
public DSU(int n)
{
rank = new int[n+1];
parent = new int[n+1];
this.n = n;
makeSet(n);
}
public void makeSet(int n)
{
for(int i=1;i<=n;i++)
{
parent[i] = i;
map.put(i,1);
}
}
public static int find(int x)
{
if(parent[x]!=x)
{
parent[x] = find(parent[x]);
}
return parent[x];
}
public void union(int x,int y)
{
int xRoot = find(x);
int yRoot = find(y);
if(xRoot==yRoot)
{
return;
}
if(rank[xRoot] < rank[yRoot])
{
parent[xRoot] = yRoot;
rank[yRoot] = rank[xRoot] + 1;
map.put(yRoot,map.getOrDefault(yRoot,1)+map.getOrDefault(xRoot,1));
if(map.getOrDefault(xRoot,0)!=0)
{
map.remove(xRoot);
}
}
else if(rank[yRoot] < rank[xRoot])
{
parent[yRoot] = xRoot;
rank[xRoot] = rank[yRoot] + 1;
map.put(xRoot,map.getOrDefault(xRoot,1) + map.getOrDefault(yRoot,1));
if(map.getOrDefault(yRoot,0)!=0)
{
map.remove(yRoot);
}
}
else
{
parent[yRoot] = xRoot;
rank[xRoot] = rank[yRoot] + 1;
map.put(xRoot,map.getOrDefault(xRoot,1)+map.getOrDefault(yRoot,1));
if(map.getOrDefault(yRoot,0)!=0)
{
map.remove(yRoot);
}
}
}
}
static class SegmentTree
{
public static int tree[];
public SegmentTree(int arr[], int n)
{
int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
int size = 2 * (int) Math.pow(2, x) - 1;
tree = new int[size];
constructTree(arr, 0, n - 1, 0);
}
public int getMid(int s, int e)
{
return s + (e - s) / 2;
}
public int minVal(int x, int y)
{
return (x < y) ? x : y;
}
public int constructTree(int arr[], int s, int e, int ind)
{
if (s == e)
{
tree[ind] = arr[s];
return arr[s];
}
int mid = getMid(s, e);
tree[ind] = constructTree(arr, s, mid, ind * 2 + 1) + constructTree(arr, mid + 1, e, ind * 2 + 2);
return tree[ind];
}
public long getSum(int n, int l, int r)
{
if (l < 0 || r > n - 1 || l > r)
{
return -1;
}
return getSumR(0, n - 1, l, r, 0);
}
public long getSumR(int s, int e, int l, int r, int ind)
{
if (l <= s && r >= e)
{
return tree[ind];
}
if (e < l || s > r)
{
return 0;
}
int mid = getMid(s, e);
return getSumR(s, mid, l, r, 2 * ind + 1) + getSumR(mid + 1, e, l, r, 2 * ind + 2);
}
public void updateValue(int arr[], int n, int i, int val)
{
if (i < 0 || i > n - 1)
{
return;
}
int diff = val - arr[i];
arr[i] = val;
updateValueR(0, n - 1, i, diff, 0);
}
public void updateValueR(int s, int e, int i, int diff, int ind)
{
if (i < s || i > e)
{
return;
}
tree[ind] = tree[ind] + diff;
if (e != s)
{
int mid = getMid(s, e);
updateValueR(s, mid, i, diff, 2 * ind + 1);
updateValueR(mid + 1, e, i, diff, 2 * ind + 2);
}
}
////FOR MIN APLLICATION
public int constructMinTree(int arr[], int s, int e, int ind)
{
if (s == e)
{
tree[ind] = arr[s];
return arr[s];
}
int mid = getMid(s, e);
tree[ind] = minVal(constructMinTree(arr, s, mid, ind * 2 + 1), constructMinTree(arr, mid + 1, e, ind * 2 + 2));
return tree[ind];
}
public int getMin(int n,int l,int r)
{
if (l < 0 || r > n - 1 || l > r)
{
return -1;
}
return getMinR(0, n - 1, l, r, 0);
}
public void updateValueMin(int arr[],int s, int e, int index, int value, int node)
{
if (index < s || index > e)
{
return;
}
if (s == e)
{
arr[index] = value;
tree[node] = value;
}
else
{
int mid = getMid(s, e);
if (index >= s && index <= mid)
{
updateValueMin(arr,s, mid, index, value, 2 * node + 1);
}
else
{
updateValueMin(arr,mid + 1, e, index, value, 2 * node + 2);
}
tree[node] = Math.min(tree[2 * node + 1], tree[2 * node + 2]);
}
return;
}
public int getMinR(int s, int e, int l, int r, int index)
{
if (l <= s && r >= e)
{
return tree[index];
}
if (e < l || s > r)
{
return Integer.MAX_VALUE;
}
int mid = getMid(s, e);
return minVal(getMinR(s, mid, l, r, 2 * index + 1) , getMinR(mid + 1, e, l, r, 2 * index + 2));
}
}
public static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
public static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
public static void main(String args[]) throws Exception
{
new Thread(null, new Cf294(),"Main",1<<27).start();
}
public void run()
{
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int TESTCASES = in.nextInt();
while(TESTCASES-->0)
{
int x = in.nextInt();
int y = in.nextInt();
String s = new String();
s = in.next();
int l = 0;
int r = 0;
int u = 0;
int d = 0;
int cl = 0;
int cr = 0;
int cu = 0;
int cd = 0;
int i,j,k;
for(i=0;i<s.length();i++)
{
if(s.charAt(i)=='R')
{
cr++;
}
if(s.charAt(i)=='U')
{
cu++;
}
if(s.charAt(i)=='D')
{
cd++;
}
if(s.charAt(i)=='L')
{
cl++;
}
}
if(x<0 && y<0)
{
l+=Math.abs(x);
d+=Math.abs(y);
if(l<=cl && d<=cd)
{
w.println("YES");
}
else
{
w.println("NO");
}
}
if(x<0 && y>0)
{
l+=Math.abs(x);
u+=y;
if(l<=cl && u<=cu)
{
w.println("YES");
}
else
{
w.println("NO");
}
}
if(x>0 && y<0)
{
r+=x;
d+=Math.abs(y);
if(r<=cr && d<=cd)
{
w.println("YES");
}
else
{
w.println("NO");
}
}
if(x>0 && y>0)
{
r+=x;
u+=y;
if(r<=cr && u<=cu)
{
w.println("YES");
}
else
{
w.println("NO");
}
}
if(x==0 && y==0)
{
w.println("YES");
}
if(x==0 && y>0)
{
u+=y;
if(u<=cu)
{
w.println("YES");
}
else
{
w.println("NO");
}
}
if(x==0 && y<0)
{
d+=Math.abs(y);
if(d<=cd)
{
w.println("YES");
}
else
{
w.println("NO");
}
}
if(x>0 && y==0)
{
r+=x;
if(r<=cr)
{
w.println("YES");
}
else
{
w.println("NO");
}
}
if(x<0 && y==0)
{
l+=Math.abs(x);
if(l<=cl)
{
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 8 | 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 | 740cab66e8f5748b0814a1e151fc872b | 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 | /*
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀⢠⠞⠉⠙⠲⡀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀⡏⠀⠀Y⠀⠀⢷
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀⢸⠀⠀A⠀⠀ ⡇
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀⣸⠀⠀S⠀ ⡇
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀⢹⠀⠀H⠀⠀ ⡇
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀⡇⠀⠀⠀⠀⡼
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀⠘⠤⣄⣠⠞⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿………⣀⣰⣏⣘⣆⣀⠀⠀
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter; // System.out is a PrintWriter
// import java.util.Arrays;
// import java.util.ArrayList;
// import java.util.Collections; // for ArrayList sorting mainly
// import java.util.HashMap;
// import java.util.HashSet;
// import java.util.Random;
import java.util.StringTokenizer;
public class A {
// class Codechef {
public static void main(String[] args) throws IOException {
FastScanner scn = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
for (int tc = scn.nextInt(); tc > 0; tc--) {
int x = scn.nextInt(), y = scn.nextInt();
char[] str = scn.next().toCharArray();
int N = str.length, U = 0, D = 0, L = 0, R = 0;
for (int i = 0; i < N; i++) {
char a = str[i];
if (a == 'U') U++;
else if (a == 'D') D++;
else if (a == 'L') L++;
else R++;
}
// System.out.println(L + " " + U + " : " + x + " " + y);
if (x >= 0 && R >= x) {
if (y >= 0 && U >= y) {
out.println("YES");
} else if (y <= 0 && D >= -y) {
out.println("YES");
} else {
out.println("NO");
}
} else if (x <= 0 && L >= -x) {
// System.out.println("hit");
if (y >= 0 && U >= y) {
out.println("YES");
} else if (y <= 0 && D >= -y) {
out.println("YES");
} else {
out.println("NO");
}
} else {
out.println("NO");
}
}
out.close();
}
private static int gcd(int num1, int num2) {
int temp = 0;
while (num2 != 0) {
temp = num1;
num1 = num2;
num2 = temp % num2;
}
return num1;
}
private static int lcm(int num1, int num2) {
return (int)((1L * num1 * num2) / gcd(num1, num2));
}
private static class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() {
this.br = new BufferedReader(new InputStreamReader(System.in));
this.st = new StringTokenizer("");
}
String next() {
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException err) {
err.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
if (st.hasMoreTokens()) {
return st.nextToken("").trim();
}
try {
return br.readLine().trim();
} catch (IOException err) {
err.printStackTrace();
}
return "";
}
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 8 | 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 | a3acb96f16df1bc9aea186036ac82b57 | 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 codeforces2 {
public static int abs(int x) {
if(x<0)return -x;
return x;
}
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 r=0;
int l=0;
for(int j=0;j<s.length();j++) {
switch(s.charAt(j)) {
case 'U':u++;break;
case 'D':d++;break;
case 'R':r++;break;
case 'L':l++;break;
}
}
boolean rx;
boolean ry;
if(x>=0) {
if(r<x)rx=false;
else rx=true;
}
else {
if(l<abs(x))rx=false;
else rx=true;
}
if(y>=0) {
if(u<y)ry=false;
else ry=true;
}
else {
if(d<abs(y))ry=false;
else ry=true;
}
if(rx&ry)System.out.println("YES");
else System.out.println("NO");
}
//System.out.println(abs(3));
}
}
| 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 8 | 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 | cdcc4a3a2e68f4da153cba87ae0aa572 | 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.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import org.omg.CORBA.MARSHAL;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int len = s.nextInt();
long a = 0;
long b = 0;
long c = 0;
long res = 0;
long odd = 0;
long even = 0;
long floor = 0;
long max = 0;
long min = 0;
long d = 0;
long e = 0;
long f = 0;
long g = 0;
long n = 0;
StringBuilder sb = new StringBuilder();
String str;
boolean placeFound = true;
d = 0;
String result = "";
for (int k = 0; k <len; k++) {
a = s.nextLong();
b = s.nextLong();
int[] orders = new int[4];
str = s.next();
result="no";
for(char ch : str.toCharArray()){
if(ch == 'R')
orders[0]++;
if(ch=='L')
orders[1]++;
if(ch=='U')
orders[2]++;
if(ch=='D')
orders[3]++;
}
if((a >= 0 && a<=orders[0]) || (a <= 0 && Math.abs(a)<= orders[1]) ){
if((b>=0 && b<=orders[2]) || (b<=0 && Math.abs(b)<= orders[3])){
result="yes";
}
}
System.out.println(result);
}
/*
str = s.next();
for(char ch : str.toCharArray()){
if(ch == 'L')
a--;
else
b++;
}
System.out.println((b-a) + 1);
*/
s.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 8 | 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 | a90cc43607de58bd5353322bb7f31deb | 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.*;
public class A {
final static int MAXN = 100_005;
final static long MOD = (long) 1e9 + 7;
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t = sc.nextInt();
for(int tt =0 ;tt < t ; tt++) {
int x = sc.nextInt() , y = sc.nextInt();
String s = sc.next();
int u = 0 ; int l = 0 ; int r = 0 ; int d = 0;
for(int i = 0 ; i< s.length() ; i++) {
char c = s.charAt(i);
if(c == 'U')u++;
if(c == 'L')l++;
if(c == 'D')d++;
if(c == 'R')r++;
}
boolean xt = false ; boolean yt = false;
if(x >= 0) {
if(r >= x) xt = true;
}if(x <= 0) {
if(l >= Math.abs(x))xt = true;
}
if(y >= 0) {
if(u >= y) yt = true;
}if(y <= 0) {
if(d >= Math.abs(y))yt = true;
}
if(xt && yt)System.out.println("YES");
else System.out.println("NO");
}
}
public static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
public static long[] factorial;
public static void setFactorial() {
factorial = new long[MAXN];
factorial[0] = 1;
for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
}
public static long getFactorial(int n) {
if (factorial == null) setFactorial();
return factorial[n];
}
public static long ncr(int n, int r) {
if (r > n) return 0;
if (factorial == null) setFactorial();
long numerator = factorial[n];
long denominator = factorial[r] * factorial[n - r] % MOD;
return numerator * pow(denominator, MOD - 2, MOD) % MOD;
}
public static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
public static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public static long pow(long base, long exp, long MOD) {
base %= MOD;
long ret = 1;
while (exp > 0) {
if ((exp & 1) == 1) ret = ret * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return ret;
}
public static long max(long... ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.max(ret, itr);
return ret;
}
public static int max(int... ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.max(ret, itr);
return ret;
}
public static long min(long... ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.min(ret, itr);
return ret;
}
public static int min(int... ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.min(ret, itr);
return ret;
}
public static long sum(long... ar) {
long sum = 0;
for (long itr : ar) sum += itr;
return sum;
}
public static long sum(int... ar) {
long sum = 0;
for (int itr : ar) sum += itr;
return sum;
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!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());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
}
}
| 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 8 | 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 | 18b653a0925cdc07e30ee6daf00da3b2 | 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 whatever; // don't place package name! */
import java.util.*;
import java.math.BigInteger;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.Math;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
public static int result;
public static ArrayList<Integer> [] graph;
public static int[]cats;
public static String[]vector;
public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;
public static void main (String[] args) throws IOException {
Scanner input = new Scanner(System.in);
HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<String, Integer> litere= new HashMap<String, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();
litere.put("a",1);
litere.put("b",2);
litere.put("c",3);
litere.put("d",4);
litere.put("e",5);
litere.put("f",6);
litere.put("g",7);
litere.put("h",8);
litere.put("i",9);
litere.put("j",10);
litere.put("k",11);
litere.put("l",12);
litere.put("m",13);
litere.put("n",14);
litere.put("o",15);
litere.put("p",16);
litere.put("q",17);
litere.put("r",18);
litere.put("s",19);
litere.put("t",20);
litere.put("u",21);
litere.put("v",22);
litere.put("w",23);
litere.put("x",24);
litere.put("y",25);
litere.put("z",26);
BigInteger numar_initial;
BigInteger primul;
BigInteger doilea;
BigInteger produs;
BigInteger unitatea;
int teste=input.nextInt();
for (int t=1; t<=teste;t++)
{
//Scanner scan = new Scanner(System.in);
// int n=input.nextInt();
//Scanner scan = new Scanner(System.in);
//String str=input.next();
// StringBuilder stro = new StringBuilder(scan.nextLine());
// stro = new StringBuilder(scan.nextLine());
// String str=String.valueOf(stro);
// StringBuilder raspunsul = new StringBuilder();
//System.out.println(i+" " + str.substring(i,i+1));
// System.out.println(i+" " + litere.get(str.substring(i,i+1)));
// System.out.println(min);
//System.out.println(max);
//}
//}
int x=input.nextInt();
int y=input.nextInt();
String s=input.next();
int r=s.length()-s.replace("R", "").length();
int u=s.length()-s.replace("U", "").length();
int d=s.length()-s.replace("D", "").length();
int l=s.length()-s.replace("L", "").length();
int distantax=r-l;
int distantay=u-d;
int adevx=1;
int adevy=1;
// int distantax=dx-x;
// int distantay=u-d;
// System.out.println(distantax+" "+distantay);
if (distantax > x && distantax-r>x) adevx=0;
if (distantax < x && distantax+l<x) adevx=0;
if (distantay > y && distantay-u>y) adevy=0;
if (distantay < y && distantay+d<y) adevy=0;
if(adevx==1 && adevy==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 8 | 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 | 17421d24189ed203721c3c2ee2e18030 | 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 Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
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();
sc.nextLine();
String s=sc.nextLine();
int a[]={0,0,0,0};
for(int j=0;j<s.length();j++)
{
char ch=s.charAt(j);
if(ch=='R')
a[0]++;
if(ch=='L')
a[1]++;
if(ch=='U')
a[2]++;
if(ch=='D')
a[3]++;
}
if(px>=0 && py>=0)
{
if(a[0]>=px && a[2]>=py)
System.out.println("YES");
else
System.out.println("NO");
}
else if(px>=0 && py<0)
{
if(a[0]>=px && a[3]>=Math.abs(py))
System.out.println("YES");
else
System.out.println("NO");
}
else if(px<0 && py>=0)
{
if(a[1]>=Math.abs(px) && a[2]>=py)
System.out.println("YES");
else
System.out.println("NO");
}
else
{
if(a[1]>=Math.abs(px) && a[3]>=Math.abs(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 8 | 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 | 6f0f18f433bc64027e62f9cf1aeb0d38 | 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 PlanetForces{
public static void main(String[] args) {
FastReader fr = new FastReader();
PrintWriter out = new PrintWriter(System.out);
Scanner sc= new Scanner (System.in);
//Code From Here----
int t =fr.nextInt();
while (t-->0) {
int x=fr.nextInt();
int y=fr.nextInt();
String str=fr.next();
int cx=x>=0?1:0;
int cy=y>=0?1:0;
for (int i = 0; i < str.length(); i++) {
char c=str.charAt(i);
if(cy==1 && y>0 && c=='U')
y--;
if(cy==0 && y<0 && c=='D')
y++;
if(cx==1 && x>0 && c=='R')
x--;
if(cx==0 && x<0 && c=='L')
x++;
}
if(x==0&&y==0)
out.println("YES");
else
out.println("NO");
}
out.flush();
sc.close();
}
//This RadixSort() is for long method
public static long[] radixSort(long[] f){ return radixSort(f, f.length); }
public static long[] radixSort(long[] f, int n)
{
long[] to = new long[n];
{
int[] b = new int[65537];
for(int i = 0;i < n;i++)b[1+(int)(f[i]&0xffff)]++;
for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
for(int i = 0;i < n;i++)to[b[(int)(f[i]&0xffff)]++] = f[i];
long[] d = f; f = to;to = d;
}
{
int[] b = new int[65537];
for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>16&0xffff)]++;
for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>16&0xffff)]++] = f[i];
long[] d = f; f = to;to = d;
}
{
int[] b = new int[65537];
for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>32&0xffff)]++;
for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>32&0xffff)]++] = f[i];
long[] d = f; f = to;to = d;
}
{
int[] b = new int[65537];
for(int i = 0;i < n;i++)b[1+(int)(f[i]>>>48&0xffff)]++;
for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
for(int i = 0;i < n;i++)to[b[(int)(f[i]>>>48&0xffff)]++] = f[i];
long[] d = f; f = to;to = d;
}
return f;
}
// For Fast Input ----
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 8 | 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 | 779647126f87e38ad4bb7f7b192fde2d | 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 Solution{
public static void main(String arg[]){
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while (t > 0)
{
int i, p = 0, q = 0, r = 0, s = 0, x = scan.nextInt(), y = scan.nextInt();
String a = scan.next();
for (i = 0; i < a.length(); ++i)
{
if (a.charAt(i) == 'R')
{
p++;
}
else if (a.charAt(i) == 'L')
{
q++;
}
else if (a.charAt(i) == 'U')
{
r++;
}
else
{
s++;
}
}
i = 0;
if (x >= 0)
{
if (p >= x)
{
i++;
}
}
else
{
if (q >= Math.abs(x))
{
i++;
}
}
if (y >= 0)
{
if (r >= y)
{
i++;
}
}
else
{
if (s >= Math.abs(y))
{
i++;
}
}
if (i == 2)
{
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 8 | 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 | 94a4f0eca4f0f4da2c76a4dd76721ed4 | 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_Navi
{
public static void main(String[]A)
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();
int count1=0,count2=0,count3=0,count4=0;
for(int i=0;i<t;i++)
{
int x=s.nextInt();
int y=s.nextInt();
s.nextLine();
String str=s.nextLine();
for(int j=0;j<str.length();j++)
{
char ch=str.charAt(j);
if(ch=='U'||ch=='u') count1++;
if(ch=='D'||ch=='d') count2++;
if(ch=='L'||ch=='l') count3++;
if(ch=='R'||ch=='r') count4++;
}
if(x>0&&y>=0)
{
if(count4>=x&&count1>=y)
System.out.println("YES");
else
System.out.println("NO");
}
if(x<=0&&y>0)
{
if(count3>=Math.abs(x)&&count1>=y)
System.out.println("YES");
else
System.out.println("NO");
}
if(x<0&&y<=0)
{
if(count3>=Math.abs(x)&&count2>=Math.abs(y))
System.out.println("YES");
else
System.out.println("NO");
}
if(x>=0&&y<0)
{
if(count4>=x&&count2>=Math.abs(y))
System.out.println("YES");
else
System.out.println("NO");
}
count1=0;
count2=0;
count3=0;
count4=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 8 | 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 | 6dd9cede4f0b6af59b141d716b31eb76 | 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 | //Keshav Agarwal
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class spacenavigation{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t=scn.nextInt();
while(t-->0){
int x=scn.nextInt();
int y=scn.nextInt();
String s=scn.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++;
}
else if(ch=='D'){
d++;
}
else if(ch=='L'){
l++;
}
else if(ch=='R'){
r++;
}
}
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 8 | 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 | db8b0638f67db4dc2b790be814f3d79c | 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 n = input.nextInt();
for (int i = 0 ; i < n; i++){
int a = input.nextInt();
int b = input.nextInt();
String s = input.next();
int U = 0,R = 0,L = 0,D = 0;
for (int j = 0; j < s.length();j++ ){
if (s.charAt(j) == 'L')
L++;
else if (s.charAt(j) == 'D')
D++;
else if (s.charAt(j) == 'R')
R++;
else if (s.charAt(j) == 'U')
U++;
}
if (a >= 0 && R >= a)
{
if (b >= 0 && U >= b)
System.out.println("YES");
else if (b < 0 && (-1 *D) <= b && D !=0 )
System.out.println("YES");
else System.out.println("NO");
}
else if (a < 0 && (L * -1) <= a )
{
if (b >= 0 && U >= b)
System.out.println("YES");
else if (b < 0 && (D * - 1) <= b )
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 8 | 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 | de97f22cd9946ec0871effb7fa2509cf | 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 scanner = new Scanner(System.in) ;
int t = scanner.nextInt() ;
for (int i=0; i< t; i++) {
int u=0, d=0, l=0,r=0 ;
boolean xConf=false, yConf =false ;
int x = scanner.nextInt() ;
int y = scanner.nextInt() ;
String line = scanner.next() ;
for (char letter : line.toCharArray()) {
if (letter=='U') u++ ;
if (letter=='D') d++ ;
if (letter=='L') l++ ;
if (letter=='R') r++ ;
}
//System.out.println(u+" "+d+" "+l+" "+r) ;
if (x>0) {
if (r>=x) xConf = true ;
} else {
if (l>=(x*(-1))) xConf = true ;
}
if (y>0) {
if (u>=y) yConf = true ;
} else {
if (d>=(y*(-1))) yConf = true ;
}
if (xConf && yConf) 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 8 | 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 | 020ad50f61420ee345a92d1ec94a81e8 | 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.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
public class sol{
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();
char xc=(x>0)?'R':'L';
char yc=(y>0)?'U':'D';
int i=0;
x=java.lang.Math.abs(x);
y=java.lang.Math.abs(y);
while(i<s.length()&&((x!=0)||(y!=0))){
if(x==0&&y==0)
break;
if(x!=0&&s.charAt(i)==xc){
x--;
}
if(y!=0&&s.charAt(i)==yc){
y--;
}
i++;
}
// (x==0&&y==0)?System.out.println("YES"):System.out.println("NO");
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 8 | 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 | 1315627b83ecdf1c690c6afc73f813fd | 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 contest;
import java.io.*;
import java.util.*;
public class A_Space_Navigation {
// static int mod=1000000007;
public static void main(String[] args) throws Exception {
try {
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int test = in.nextInt();
while(test-->0){
int x = in.nextInt();
int y = in.nextInt();
HashMap<Character,Integer> map = new HashMap<>();
for(char ch : in.nextLine().toCharArray()){
map.put(ch, map.getOrDefault(ch, 0)+1);
}
if(x>=0 && y>=0){
int val1 = map.containsKey('R') ? map.get('R') : 0;
int val2 =map.containsKey('U') ? map.get('U') : 0;
if(val1>= x && val2>=y){
out.println("YES");
}else{
out.println("NO");
}
}else if(x>=0 && y<0){
int val1 = map.containsKey('R') ?map.get('R') : 0;
int val2 = map.containsKey('D') ?map.get('D') : 0;
if(val1 >= x && val2>=Math.abs(y)){
out.println("YES");
}else{
out.println("NO");
}
}else if(x<0 && y>=0){
int val1 = map.containsKey('L') ?map.get('L'): 0;
int val2 = map.containsKey('U') ?map.get('U') : 0;
if(val1>=Math.abs(x) && val2>=y){
out.println("YES");
}else{
out.println("NO");
}
}else{
int val1 = map.containsKey('L') ?map.get('L'): 0;
int val2 = map.containsKey('D') ?map.get('D') : 0;
if(val1>=Math.abs(x) && val2>= Math.abs(y)){
out.println("YES");
}else{
out.println("NO");
}
}
}
out.close();
} catch (Exception e) {
System.out.println(e);
return;
}
}
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;
}
String[] strArray() {
String str[] = nextLine().split(" ");
return str;
}
int[] intArray(int n) {
String[] str = strArray();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(str[i]);
}
return arr;
}
long[] longArray(int n) {
String[] str = strArray();
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = Long.parseLong(str[i]);
}
return arr;
}
int[][] two_d_Array(int n, int m){
int arr[][] = new int[n][m];
for(int i=0;i<n;i++){
String[] str = strArray();
for(int j=0;j<m;j++){
arr[i][j] = Integer.parseInt(str[j]);
}
}
return arr;
}
Integer[] IntArray(int n) {
String[] str = strArray();
Integer[] arr = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(str[i]);
}
return arr;
}
private static void swap (int arr[], int a, int b){
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
}
static class SparseMatrix {
private int[] arr;
private int m;
private int[][] minSparse;
private int[][] minIndex;
private int[][] maxSparse;
private int[][] maxIndex;
private int n;
public SparseMatrix(int[] arr) {
this.arr = arr;
this.m=arr.length;
this.n=Integer.toBinaryString(m).length();
minSparse=new int[n][m];
minIndex=new int[n][m];
maxSparse=new int[n][m];
maxIndex=new int[n][m];
// for(int i=0;i<n;i++)
// {
// Arrays.fill(minSparse[i],-1);
// }
// for(int i=0;i<n;i++)
// {
// Arrays.fill(minIndex[i],-1);
// }
createMinSparse();
createMaxSparse();
}
private void createMaxSparse()
{
for(int j=0;j<m;j++)
{
maxSparse[0][j]=arr[j];
maxIndex[0][j]=j;
}
for(int i=1;i<n;i++)
{
for(int j=0;j+(1<<(i-1))<m;j++)
{
int left=maxSparse[i-1][j];
int right=maxSparse[i-1][j+(1<<(i-1))];
maxSparse[i][j]=Math.max(left,right);
if(left>=right)
{
maxIndex[i][j]=maxIndex[i-1][j];
}
else
{
maxIndex[i][j]=maxIndex[i-1][j+(1<<(i-1))];
}
}
}
}
private void createMinSparse()
{
//filling the first row of sparse matrix with the values of the input array
for(int j=0;j<m;j++)
{
minSparse[0][j]=arr[j];
minIndex[0][j]=j;
}
//filling other rows of the sparse matrix
for(int i=1;i<n;i++)
{
for(int j=0;j+(1<<(i-1))<m;j++)
{
int left=minSparse[i-1][j];
int right=minSparse[i-1][j+(1<<(i-1))];
//change to min-> max to create MaxSparseMatrix
minSparse[i][j]=Math.min(left,right);
//filling index
if(left<=right)
{
minIndex[i][j]=minIndex[i-1][j];
}
else {
minIndex[i][j]=minIndex[i-1][j+(1<<(i-1))];
}
}
}
}
//get minimum value in range l->r inclusive
/*
for any range [l, r] we can find the two values and
find their minimum. These values are defined below:
len: length of the required range, i.e., r-l+1
p: maximum power of 2 that can fit in len. E.g, [1,11] , len=11, thus p=3
k: 2^p
find the minimum between sparse[p][l] and sparse[p][r-k+1]
*/
public int getMin(int l,int r)
{
int len=r-l+1;
int p=Integer.toBinaryString(len).length()-1;
int k=1<<p;
int left=minSparse[p][l];
int right=minSparse[p][r-k+1];
return Math.min(right,left);
}
public int getMinIndex(int l,int r)
{
int len=r-l+1;
int p=Integer.toBinaryString(len).length()-1;
int k=1<<p;
int left=minSparse[p][l];
int right=minSparse[p][r-k+1];
if (left <= right) {
return minIndex[p][l];
} else {
return minIndex[p][r - k + 1];
}
}
public int getMax(int l,int r)
{
int len=r-l+1;
int p=Integer.toBinaryString(len).length()-1;
int k=1<<p;
int left=maxSparse[p][l];
int right=maxSparse[p][r-k+1];
return Math.max(right,left);
}
public int getMaxIndex(int l,int r)
{
int len=r-l+1;
int p=Integer.toBinaryString(len).length()-1;
int k=1<<p;
int left=maxSparse[p][l];
int right=maxSparse[p][r-k+1];
if(left>=right)
{
return maxIndex[p][l];
}
return maxIndex[p][r-k+1];
}
void print()
{
for(int i=0;i<minSparse.length;i++)
{
for(int j=0;j<minSparse[i].length;j++)
{
System.out.print(minSparse[i][j]+" ");
}
System.out.println();
}
System.out.println();
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(minIndex[i][j]+" ");
}
System.out.println();
}
}
}
}
| 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 8 | 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 | 695234d31e9a711485ac08c6c04c5c58 | 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 SpaceShip {
public static String solve(int x,int y,String path){
char[] c = path.toCharArray();
int[] directions = new int[4];
for(int i=0; i<c.length; i++){
if(c[i] == 'U') directions[0]++;
else if(c[i] == 'D') directions[1]++;
else if(c[i] == 'R') directions[2]++;
else if(c[i] == 'L') directions[3]++;
else continue;
}
if(x>0 && x>directions[2]) return "NO";
else if(x<0 && Math.abs(x)>directions[3]) return "NO";
else if(y>0 && y>directions[0]) return "NO";
else if(y<0 && Math.abs(y)>directions[1]) return "NO";
else return "YES";
}
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 path = sc.next();
System.out.println(solve(x,y,path));
}
}
}
| 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 8 | 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 | 2994110e1d9e23c1b3566aa507cb232d | 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 z100 {
public static void solve(InputReader in, PrintWriter out) throws Exception {
int t = in.nextInt();
while(t--!=0){
int x = in.nextInt();
int y = in.nextInt();
String s = in.nextLine();
int u=0,d=0,r=0,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 && y>=0)
{
if(r>=x && u>=y)
out.println("YES");
else
out.println("NO");
}
else if(x<=0 && y>=0)
{
if(l>=Math.abs(x) && u>=y)
out.println("YES");
else
out.println("NO");
}
else if(x<=0 && y<=0)
{
if(l>=Math.abs(x) && d>=Math.abs(y))
out.println("YES");
else
out.println("NO");
}
else{
if(r>=x && d>=Math.abs(y))
out.println("YES");
else
out.println("NO");
}
}
}
/////////////////////////////////////////////////////////
private final static long hash(long x, long y) {
x += offset;
y += offset;
return x << 32 | y;
}
private final static int offset = (int) 3e5;
public static void main(String[] args) throws Exception {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
solve(in, out);
out.close();
}
static class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
private String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
public String nextLine() throws IOException {
return reader.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
} | 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 8 | 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 | 24549c17af19e97aad8fe39b8d10b6d1 | 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.Arrays;
import java.util.Scanner;
public class Testing {
public enum Direction {
L, R, U, D
}
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();
sc.nextLine();
String drn = sc.nextLine();
int[] arr = new int[4];
Arrays.fill(arr, 0);
if((x - 0) >= 0)
arr[Direction.R.ordinal()] = x;
else
arr[Direction.L.ordinal()] = 0 - x;
if((y - 0) >= 0)
arr[Direction.U.ordinal()] = y;
else
arr[Direction.D.ordinal()] = 0 - y;
for(int i = 0; i < drn.length(); i++) {
if (drn.charAt(i) == 'L' && arr[Direction.L.ordinal()] > 0)
arr[Direction.L.ordinal()]--;
else if (drn.charAt(i) == 'R' && arr[Direction.R.ordinal()] > 0)
arr[Direction.R.ordinal()]--;
else if (drn.charAt(i) == 'U' && arr[Direction.U.ordinal()] > 0)
arr[Direction.U.ordinal()]--;
else if (drn.charAt(i) == 'D' && arr[Direction.D.ordinal()] > 0)
arr[Direction.D.ordinal()]--;
}
if(arr[Direction.L.ordinal()] == 0 && arr[Direction.R.ordinal()] == 0 &&
arr[Direction.U.ordinal()] == 0 && arr[Direction.D.ordinal()] == 0)
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 8 | 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 | bfc294bcd642a3b0d0039f40b3d879b3 | 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 Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
StringBuilder sb=new StringBuilder();
for(int t=0;t<T;t++){
int px=sc.nextInt();
int py=sc.nextInt();
String s=sc.next();
int R=0,L=0,U=0,D=0;
if(px<0){
L=-px;
}
else if(px>0){
R=px;
}
if(py<0){
D=-py;
}
else if(py>0){
U=py;
}
for(int i=0;i<s.length();i++){
char c=s.charAt(i);
if(c=='U'){
U--;
}
else if(c=='D'){
D--;
}
else if(c=='R'){
R--;
}
else{
L--;
}
}
if(U<=0 && D<=0 && R<=0 && L<=0){
sb.append("YES\n");
}
else{
sb.append("NO\n");
}
}
System.out.print(sb.toString());
}
} | 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 8 | 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 | 8d5997917d53ddc9c7abc130f75a0da6 | 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 test;
import java.io.IOException;
//import java.util.Arrays;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int t, p_x, p_y;
String s;
char c [];
char w;
int [] l;
boolean b;
t = sc.nextInt();
while(t>0) {
l = new int[4];
b = true;
p_x = sc.nextInt();
p_y = sc.nextInt();
s = sc.next();
c = s.toCharArray();
for(int i=0; i<c.length; i++) {
w = c[i];
switch (w) {
case 'R':
l[0]++;
break;
case 'U':
l[1]++;
break;
case 'L':
l[2]++;
break;
default:
l[3]++;
break;
}
}
if(p_x>0) {
if(l[0]>=p_x) {}
else b = false;
}
else {
if(l[2]>=-p_x) {}
else b = false;
}
if(p_y>0) {
if(l[1]>=p_y) {}
else b = false;
}
else {
if(l[3]>=-p_y) {}
else b = false;
}
if(b) 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 8 | 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 | 149fd6615ac086482cfe5d95ed1c7095 | 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 test;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static boolean watermelo(int x) {
if(x<3)return false;
if(x%2==0) {
return true;
}else {
return false;
}
}
public static int recurs(int x, int y,int total) {
if(x==1&&y==1) {
return total+0;
}
if(y==1) {
total=total+(int)x/2;
return total;
}
if(y==0) {
return total;
}
return recurs(x,y-2,total+x);
}
public static void resp(String[] r) {
String fin="";
for (int i = 0; i < r.length; i++) {
fin=fin+r[i];
}
for (int i = 0; i < r.length-1; i++) {
if(fin.substring(i, i+1).equals("B")) {
r[i]=r[i+1];
r[i+1]="B";
}
}
}
public static String retString(char []x) {
String temp="";
for (int i = 0; i < x.length; i++) {
temp=temp+x[i];
}
return temp;
}
public static int containss(String [] arr,String x) {
int count=0;
for (int i = 0; i < arr.length; i++) {
if(x.equals(arr[i])){
count++;
}
}
return count;
}
public static String printStringnaw(String [] arr) {
String temp="";
for (int i = 0; i < arr.length; i++) {
temp=temp+arr[i]+",";
}
System.out.println("method");
return temp;
}
public static String sortString(String inputString)
{
// convert input string to char array
char tempArray[] = inputString.toCharArray();
// sort tempArray
Arrays.sort(tempArray);
// return new sorted string
return new String(tempArray);
}
public static void main(String[] args) {
Scanner s =new Scanner(System.in);
int n=s.nextInt();
for (int i = 0; i < n; i++) {
//System.out.println(s.hasNext()+" "+i);
int x=s.nextInt();
int y=s.nextInt();
String []temp=s.next().split("");
int countx=0;
int county=0;
if(x>0) {
for (int j = 0; j < temp.length; j++) {
if(temp[j].equals("R"))countx++;
}
}else {
for (int j = 0; j < temp.length; j++) {
if(temp[j].equals("L"))countx++;
}
}
if(y>0) {
for (int j = 0; j < temp.length; j++) {
if(temp[j].equals("U"))county++;
}
}else {
for (int j = 0; j < temp.length; j++) {
if(temp[j].equals("D"))county++;
}
}
if(countx>=Math.abs(x)&&county>=Math.abs(y)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
//long end=s.nextInt();
//s.nextLine();
//long [] arr=new long[x];
//for (int i = 0; i < x; i++) {
// arr[i]=s.nextInt();
//}
//Arrays.sort(arr);
//double temp=arr[0];
//double r=0;
//
//for (int i = 0; i < arr.length-1; i++) {
// r=arr[i]-arr[i+1];
// r=r*-1;
//
// r=r/2;
//
// if(r>temp) {
// temp=r;
// }
//}
//
//r=end-(arr[arr.length-1]);
//r=r/2;
//if(r>temp) {
// temp=r;
//}
////temp=temp-0.00000000001;
//temp=temp+0.00000000001;
//String y=""+temp;
//System.out.println(y.substring(0, y.length()-1));
//
//BigInteger n = BigInteger.ZERO;
//n=n.add(BigInteger.valueOf(s.nextInt()));
//BigInteger m = BigInteger.ZERO;
//m=m.add(BigInteger.valueOf(s.nextInt()));
//BigInteger a = BigInteger.ZERO;
//a=a.add(BigInteger.valueOf(s.nextInt()));
//BigInteger x=BigInteger.ZERO;
//x=n.divide(a);
//
//BigInteger y=BigInteger.ZERO;
//BigInteger o=BigInteger.ZERO;
//
//y=m.divide(a);
//if(n.mod(a)!=o) {x=x.add(BigInteger.valueOf(1));}
//if(m.mod(a)!=o) {y=y.add(BigInteger.valueOf(1));}
//
//System.out.println(x.multiply(y));
//s.nextLine();
//
//String [] x = s.nextLine().split("");
//for (int j = 0; j < x.length; j++) {
// int i = Integer. parseInt(x[j]);
//}
//if(i>o){
// System.out.println("Anton");
//}else{
// if(o==i){
// System.out.println("Friendship");
// }else{
// System.out.println("Danik");
// }
//}\
//
}
private static boolean istprime(long arr) {
long temp=arr;
for (long j = 2; j < (temp/2)+1; j++) {
if(arr%j==0) {
if((long)j*j==arr)return true;
else return false;
}
}
return 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 8 | 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 | 64083bf26a47df614d8bfd28bee0aadf | 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 Codeforces;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Round699Div2_1 {
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 px= Integer.parseInt(st.nextToken());
int py=Integer.parseInt(st.nextToken());
String s= br.readLine();
char sarray[]= s.toCharArray();
int pxcount=0;
int pycount=0;
if (px>0){
for (int i=0;i<sarray.length;i++){
if (sarray[i]=='R'){
pxcount++;
if (pxcount==px){
break;
}
}
}
}else if (px<0){
for (int i=0;i<sarray.length;i++){
if (sarray[i]=='L'){
pxcount++;
if (pxcount==Math.abs(px)){
break;
}
}
}
}
if(py>0){
for (int i=0;i<sarray.length;i++){
if (sarray[i]=='U'){
pycount++;
if (pycount==py){
break;
}
}
}
}else if (py<0){
for (int i=0;i<sarray.length;i++){
if (sarray[i]=='D'){
pycount++;
if (pycount==Math.abs(py)){
break;
}
}
}
}
if (Math.abs(px)==pxcount && Math.abs(py)==pycount){
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 8 | 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 | ab6180172486b881fc75534f0895620b | 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 input = new Scanner(System.in);
int tests = input.nextInt();
for(int i = 0; i < tests; i++){
int x = input.nextInt();
int y = input.nextInt();
String str = input.next();
System.out.println(solve(x, y, str));
}
}
public static String solve(int x, int y, String str){
int u = 0;
int d = 0;
int r = 0;
int l = 0;
boolean g = false;
boolean f = false;
str += "p";
for(int i = 0; i < str.length()-1; i++){
if(str.substring(i, i+1).equals("U")){
u++;
}
if(str.substring(i, i+1).equals("D")){
d++;
}
if(str.substring(i, i+1).equals("R")){
r++;
}
if(str.substring(i, i+1).equals("L")){
l++;
}
}
if(x >= 0 && r >= x){
g = true;
}else if(x < 0 && l >= Math.abs(x)){
g = true;
}else{
g = false;
}
if(y >= 0 && u >= y){
f = true;
}else if(y < 0 && d >= Math.abs(y)){
f = true;
}else{
f = false;
}
if(g && f){
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 8 | 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 | f11ffaa3e9d599b1665d6c0779a8a3c0 | 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 x=sc.nextInt();
int y=sc.nextInt();
String s=sc.next();
int l=0,r=0,u=0,d=0;
int ans=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++;
}
}
if(x>=0 && r>=x){
ans++;
}
else if(x<=0 && l>=Math.abs(x)){
ans++;
}
if(y>=0 && u>=y){
ans++;
}
else if(y<=0 && d>=Math.abs(y)){
ans++;
}
if(ans==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 8 | 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 | abff9f36cbae4df95deee57a7a43f66c | 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 {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
FastOutput fo = new FastOutput();
int testcases = fs.nextInt();
for (int tt = 0; tt < testcases; tt++) {
//main code
int x=fs.nextInt(),y=fs.nextInt();
String s=fs.next();
int up=0,down=0,left=0,right=0;
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='L')
left++;
else if(s.charAt(i)=='R')
right++;
else if(s.charAt(i)=='U')
up++;
else
down++;
}
//1ts quad
if(x>=0 && y>=0) {
if(right>=x && up>=y) {
fo.println("YES");
}
else {
fo.println("NO");
}
}
//2nd quad
if(x<0 && y>=0) {
if(left>=-x && up>=y) {
fo.println("YES");
}
else {
fo.println("NO");
}
}
//3rd quad
if(x<0 && y<0) {
if(left>=-x && down>=-y) {
fo.println("YES");
}
else {
fo.println("NO");
}
}
//4th quad
if(x>=0 && y<0) {
if(right>=x && down>=-y) {
fo.println("YES");
}
else {
fo.println("NO");
}
}
}
}
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());
}
}
static class FastOutput {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
void print(String str) {
try {
bw.write(str);
bw.flush();
} catch (IOException e) {
}
}
void print(int num) {
try {
bw.write((num + ""));
bw.flush();
} catch (IOException e) {
}
}
void println(String str) {
try {
bw.write(str + '\n');
bw.flush();
} catch (IOException e) {
}
}
void println(int num) {
try {
bw.write(num + "" + '\n');
bw.flush();
} catch (IOException e) {
}
}
}
}
| 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 8 | 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 | 5c0b1d175fd293b34785f5d53de6282c | 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 sol {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t;
t = sc.nextInt();
while(t>0) {
int x, y;
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++){
switch(s.charAt(i)){
case 'L':
l++;
break;
case 'R':
r++;
break;
case 'U':
u++;
break;
case 'D':
d++;
break;
}
}
int dx=r-l-x, dy=u-d-y;
if((dx<0 && -1*dx<=l) || (dx>0 && dx<=r) || dx==0){
if((dy<0 && -1*dy<=d) || (dy>0 && dy<=u) || dy == 0){
System.out.println("YES");
} else {
System.out.println("NO");
}
}
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 8 | 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 | 65854164227f457eece99c817b8a34f4 | 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 ProbA {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cases = sc.nextInt();
for(int c=0; c<cases; c++) {
int x1 = sc.nextInt();
int y1 = sc.nextInt();
sc.nextLine();
String dir = sc.nextLine();
int[] dirCount = new int[4];
int i = 0;
for(; i<dir.length(); i++) {
switch(dir.charAt(i)) {
case 'U':
dirCount[0]++;
break;
case 'D':
dirCount[1]++;
break;
case 'L':
dirCount[2]++;
break;
case 'R':
dirCount[3]++;
break;
default:
}
}
if(x1 >= 0 && y1 >= 0 && dirCount[3] >= x1 && dirCount[0] >= y1) {
System.out.println("YES");
} else if(x1 <= 0 && y1 <= 0 && dirCount[2] >= Math.abs(x1) && dirCount[1] >= Math.abs(y1)) {
System.out.println("YES");
} else if(x1 <= 0 && y1 >= 0 && dirCount[2] >= Math.abs(x1) && dirCount[0] >= y1){
System.out.println("YES");
} else if(x1 >= 0 && y1 <= 0 && dirCount[3] >= x1 && dirCount[1] >= Math.abs(y1)) {
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 8 | 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 | 1ea4dcd74e6ae3011888a379f04f4514 | 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.*;
public class B {
static int BinarySearch(int a[], int l, int r, int key)
{
if(l<=r)
{
int mid = l + (r-l)/2;
if(a[mid]==key)
return mid;
if(a[mid]<key)
return BinarySearch(a, mid+1, r, key);
if(a[mid]>key)
return BinarySearch(a, l, mid-1,key);
}
return -1;
}
static int gcd(int a, int b)
{
if(a==0)
return b;
if(b==0)
return a;
if(a>=b)
{
return gcd(a%b,b);
}
return gcd(a,b%a);
}
static List<Integer> primeFactor(int n)
{
List<Integer> list = new ArrayList<>();
for(int i=2;i*i<=n;i++)
{
while(n%i==0)
{
list.add(i);
n/=i;
}
}
if(n!=1)
{
list.add(n);
}
return list;
}
public static void main (String[] args) throws java.lang.Exception {
try {
FastScanner fs = new FastScanner();
int t = fs.nextInt();
while(t-->0)
{
int X = fs.nextInt(), Y =fs.nextInt();
String s = fs.next();
boolean test1=false,test2=false;
int l=0,r=0,u=0,d=0;
int n = s.length();
for(int i=0;i<n;i++)
{
if(s.charAt(i)=='U')
u++;
if(s.charAt(i)=='R')
r++;
if(s.charAt(i)=='L')
l--;
if(s.charAt(i)=='D')
d--;
}
if(X>=l && X<=r)
test1=true;
if(Y>=d && Y<=u)
test2=true;
if(test1 && test2)
System.out.println("YES");
else
System.out.println("NO");
}
}
catch (Exception e)
{
return;
}
}
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;
}
}
} | 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 8 | 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 | 83245d00ca286d1c86bee3d5c568abe5 | 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 pack;
import java.util.*;
import java.io.*;
public class template
{
public static void main(String[] args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
int t = Integer.parseInt(reader.readLine());
while(t-- >0)
{
String [] st = reader.readLine().split(" ");
int x = Integer.parseInt(st[0]);
int y = Integer.parseInt(st[1]);
String str = reader.readLine();
int l=0,r=0,u=0,d=0;
for(int i=0 ; i<str.length();i++)
{
if(str.charAt(i) == 'L') l++;
else if(str.charAt(i) == 'R') r++;
else if(str.charAt(i) == 'U') u++;
else d++;
}
boolean flag = true;
if(x >=0 && y>=0)
{
if(r >= x && u>=y) flag = true;
else flag = false;
}
else if(x <=0 && y>=0)
{
if(Math.abs(l) >= Math.abs(x) && Math.abs(u) >= Math.abs(y)) flag = true;
else flag = false;
}
else if(x <=0 && y<=0)
{
if(Math.abs(l) >= Math.abs(x) && Math.abs(d) >= Math.abs(y)) flag = true;
else flag = false;
}
else if(x >=0 && y<=0)
{
if(Math.abs(r) >= Math.abs(x) && Math.abs(d) >= Math.abs(y)) flag = true;
else flag = false;
}
if(flag) writer.println("YES");
else writer.println("NO");
}
writer.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 8 | 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 | 2ee0f6f16612fc01e92e9bb07bedae08 | 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.math.BigInteger;
import static java.lang.Math.max;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.TreeMap;
import java.util.Vector;
import java.util.Scanner;
public class ahh {
static Scanner scn = new Scanner(System.in);
public static int a;
int k = 10;
public static void main(String[] brr) {
// TODO Auto-generated method stub
int t=scn.nextInt();
while(t-->0)
{
int px=scn.nextInt(),py=scn.nextInt();
String str=scn.next();
int l = 0, r = 0, u = 0, d = 0,n=str.length();
if (px>0) r = px;
else l = -px;
if (py>0) u = py;
else d = -py;
for (int i = 0; i <n; i++) {
if (str.charAt(i)=='L') l--;
if (str.charAt(i)=='R') r--;
if (str.charAt(i)=='U') u--;
if (str.charAt(i)=='D') d--;
}
if (max(max(l, r), max(u, d))<=0) {
System.out.println("YES");
}
else System.out.println("NO");
}
}
public static void fac(int n) {
BigInteger b = new BigInteger("1");
for (int i = 1; i <= n; i++) {
b = b.multiply(BigInteger.valueOf(i));
}
System.out.println(b);
}
public static int coin(int arr[], int i, int j, int count, int sumb) {
if (count == arr.length / 2)
return 0;
if (i == arr.length || j == 0)
return 0;
int a = 0, b = 0, c = 0, d = 0;
if (count % 2 == 0) {
a = coin(arr, i + 1, j, count + 1, sumb) + arr[i];
b = coin(arr, i, j - 1, count + 1, sumb) + arr[j];
} else {
c = coin(arr, i + 1, j, count + 1, sumb + arr[i]);
d = coin(arr, i, j - 1, count + 1, sumb + arr[j]);
}
return Math.max(a, Math.max(b, Math.max(c, d)));
}
public static long gcd(long a, long b) {
while (b > 0) {
long c = a % b;
a = b;
b = c;
}
return a;
}
}
class covid
{
int x,y,cost;
public covid(int a,int b,int c)
{
this.x=a;
this.y=b;
this.cost=c;
}
}
class pair {
int x, y;
pair(int a, int b) {
this.x = a;
this.y = b;
}
public int hashCode() {
return x * 31 + y * 31;
}
public boolean equals(Object other) {
if (this == other)
return true;
if (other instanceof pair) {
pair pt = (pair) other;
return pt.x == this.x && pt.y == this.y;
} else
return false;
}
}
class sort implements Comparator<pair> {
@Override
public int compare(pair o1, pair o2) {
// TODO Auto-generated method stub
int a = o1.x - o2.x, b = o1.y - o2.y;
if (b < 0)
return -1;
else if (b == 0) {
if (a < 0)
return -1;
else
return 1;
} else
return 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 8 | 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 | ff57d0d9cb8925449aa839a7a0ea21ea | 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 Codechef
{
static FastReader fs = new FastReader();
static void solve(){
/** if si=U, you move to (x,y+1);
if si=D, you move to (x,y−1);
if si=R, you move to (x+1,y);
if si=L, you move to (x−1,y). **/
int x = fs.nextInt();
int y = fs.nextInt();
String st = fs.nextLine();
char a=' ',b=' ';
if(x > 0){
a = 'R';
}else if(x < 0){
a = 'L';
}
if(y > 0){
b = 'U';
}else if(y < 0){
b = 'D';
}
int c1=x,c2=y;
for(int i=0;i<st.length();i++){
char c = st.charAt(i);
if(c == a){
if(c1 == 0)
continue;
if(c1 > 0)
c1--;
else if(c1 < 0)
c1++;
}
if(c == b){
if(c2 == 0)
continue;
if(c2 > 0)
c2--;
else if(c2 < 0)
c2++;
}
}
if(c1 == 0 && c2 == 0){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
public static void main (String[] args) throws java.lang.Exception
{
int t = fs.nextInt();
while(t-->0){
solve();
}
}
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(Exception e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
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 8 | 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 | 26ee3a68cb13aad9987d1284e766f440 | 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.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
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);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int t = in.nextInt();
for (int i = 0; i < t; ++i) {
int x = in.nextInt();
int y = in.nextInt();
char[] s = in.next().toCharArray();
int r = 0, l = 0, u = 0, d = 0;
for (int j = 0; j < s.length; ++j) {
switch (s[j]) {
case 'R':
r++;
break;
case 'L':
l++;
break;
case 'U':
u++;
break;
case 'D':
d++;
break;
}
}
if (x > 0 && x > r || x < 0 && l + x < 0 || y > 0 && y > u || y < 0 && y + d < 0) {
out.println("NO");
} else {
out.println("YES");
}
}
}
}
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());
}
public Long nextLong() {
return Long.parseLong(next());
}
public 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 8 | 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 | 381036568c68f149dca1d66a5878d070 | 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 x = new Scanner(System.in);
int n = x.nextInt();
while(n>0){
boolean bool = true;
boolean dool = true;
int xx = x.nextInt();int y = x.nextInt();
int a = 0; int b = 0; int c = 0; int d = 0;
String s = x.next();
for(char t: s.toCharArray()){
if (t == 'R') a++;
else if(t == 'L') b++;
else if(t == 'U') c++;
else if (t == 'D') d++;
}
if(xx>0 && a>=xx) bool = false;
if(xx<=0 && b>=Math.abs(xx)) bool = false;
if (y>0 && c >=y) dool = false;
if(y<=0 && d >= Math.abs(y)) dool = false;
System.out.println((bool == false&&dool == false)?"YES":"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 8 | 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 | 9e356e1eaac949cb2940682431254c0f | 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.*;
/*
polyakoff
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int oo = (int) 1e9 + 10;
static final long OO = (long) 2e18 + 10;
static final int MOD = (int) 1e9 + 7;
static void solve() {
int px = in.nextInt();
int py = in.nextInt();
char[] s = in.next().toCharArray();
int n = s.length;
int[] cnt = new int[4];
for (int i = 0; i < n; i++) {
if (s[i] == 'U')
cnt[0]++;
else if (s[i] == 'R')
cnt[1]++;
else if (s[i] == 'D')
cnt[2]++;
else if (s[i] == 'L')
cnt[3]++;
}
if (((px >= 0 && cnt[1] >= px) || (px < 0 && cnt[3] >= -px)) &&
((py >= 0 && cnt[0] >= py) || (py < 0 && cnt[2] >= -py)))
out.println("YES");
else
out.println("NO");
}
public static void main(String[] args) {
in = new FastReader();
out = new PrintWriter(System.out);
int T = 1;
T = in.nextInt();
while (T-- > 0)
solve();
out.flush();
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
this(System.in);
}
FastReader(String file) throws FileNotFoundException {
this(new FileInputStream(file));
}
FastReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
String nextLine() {
String line;
try {
line = br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
}
} | 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 8 | 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 | 3dccc27a6796e08602950f32d29fb323 | 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;
import java.util.Scanner;
public class SpaceNavigation {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int test = input.nextInt();
while(test-- > 0){
int x = input.nextInt(),y = input.nextInt();
String str = input.next();
System.out.println(result(x,y,str));
}
}
private static String result(int x, int y, String str) {
if(x == 0 && y == 0)return "YES";
if(x > 0 && y > 0){
if(str.chars().filter(ch->ch == 'R').count() >= x && str.chars().filter(ch->ch == 'U').count() >= y)
return "YES";
return "NO";
}else if(x > 0 && y == 0){
if(str.chars().filter(ch->ch == 'R').count() >= x)
return "YES";
return "NO";
}else if(x == 0 && y > 0){
if(str.chars().filter(ch->ch == 'U').count() >= y)
return "YES";
return "NO";
}else if(x < 0 && y < 0){
if(str.chars().filter(ch->ch == 'L').count() >= (-1*x) && str.chars().filter(ch->ch == 'D').count() >= (-1*y))
return "YES";
return "NO";
}else if(x < 0 && y == 0){
if(str.chars().filter(ch->ch == 'L').count() >= (-1*x))
return "YES";
return "NO";
}else if(x == 0 && y < 0){
if(str.chars().filter(ch->ch == 'D').count() >= (-1*y))
return "YES";
return "NO";
}else if(x > 0 && y < 0){
if(str.chars().filter(ch->ch == 'R').count() >= x && str.chars().filter(ch->ch == 'D').count() >= (-1*y))
return "YES";
return "NO";
}else if(x < 0 && y > 0) {
if (str.chars().filter(ch -> ch == 'L').count() >= (-1 * x) && str.chars().filter(ch -> ch == 'U').count() >= y)
return "YES";
return "NO";
}
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 17 | 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 | 16951a7c7b83d8952fe636beae8a1e90 | 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 Practice {
static boolean multipleTC = true;
final static int mod = 1000000007;
final static int mod2 = 998244353;
final double E = 2.7182818284590452354;
final double PI = 3.14159265358979323846;
int MAX = 3001;
int N = 3001;
void pre() throws Exception {
}
// All the best
void solve(int TC) throws Exception {
int px = ni();
int py = ni();
String s = n();
char cx = 'R';
if (px < 0) {
px = 0 - px;
cx = 'L';
}
char cy = 'U';
if (py < 0) {
py = 0 - py;
cy = 'D';
}
int x = 0;
int y = 0;
for (int i = 0; i < s.length(); i++) {
char c1 = s.charAt(i);
if (c1 == cx) {
x++;
} else if (c1 == cy) {
y++;
}
}
if (x >= px && y >= py) {
pn("YES");
} else {
pn("NO");
}
}
// 2 3 4 5 1
// 1 2 3 4 5
// 1 2 3 4
// 2 1 4 3
// 1 2 4 3
//
double dist(int x1, int y1, int x2, int y2) {
double a = x1 - x2, b = y1 - y2;
return Math.sqrt((a * a) + (b * b));
}
int[] readArr(int n) throws Exception {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = ni();
}
return arr;
}
void sort(int arr[], int left, int right) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = left; i <= right; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = left; i <= right; i++)
arr[i] = list.get(i - left);
}
void sort(int arr[]) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < arr.length; i++)
arr[i] = list.get(i);
}
public long max(long... arr) {
long max = arr[0];
for (long itr : arr)
max = Math.max(max, itr);
return max;
}
public int max(int... arr) {
int max = arr[0];
for (int itr : arr)
max = Math.max(max, itr);
return max;
}
public long min(long... arr) {
long min = arr[0];
for (long itr : arr)
min = Math.min(min, itr);
return min;
}
public int min(int... arr) {
int min = arr[0];
for (int itr : arr)
min = Math.min(min, itr);
return min;
}
public long sum(long... arr) {
long sum = 0;
for (long itr : arr)
sum += itr;
return sum;
}
public long sum(int... arr) {
long sum = 0;
for (int itr : arr)
sum += itr;
return sum;
}
String bin(long n) {
return Long.toBinaryString(n);
}
String bin(int n) {
return Integer.toBinaryString(n);
}
static int bitCount(int x) {
return x == 0 ? 0 : (1 + bitCount(x & (x - 1)));
}
static void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
int abs(int a) {
return (a < 0) ? -a : a;
}
long abs(long a) {
return (a < 0) ? -a : a;
}
void p(Object o) {
out.print(o);
}
void pn(Object o) {
out.println(o);
}
void pni(Object o) {
out.println(o);
out.flush();
}
void pn(int[] arr) {
int n = arr.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(arr[i] + " ");
}
pn(sb);
}
void pn(long[] arr) {
int n = arr.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(arr[i] + " ");
}
pn(sb);
}
String n() throws Exception {
return in.next();
}
String nln() throws Exception {
return in.nextLine();
}
int ni() throws Exception {
return Integer.parseInt(in.next());
}
long nl() throws Exception {
return Long.parseLong(in.next());
}
double nd() throws Exception {
return Double.parseDouble(in.next());
}
public static void main(String[] args) throws Exception {
new Practice().run();
}
FastReader in;
PrintWriter out;
void run() throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int T = (multipleTC) ? ni() : 1;
pre();
for (int t = 1; t <= T; t++)
solve(t);
out.flush();
out.close();
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
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 17 | 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 | 604c66530da63a7b2f52c2533397687b | 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.Integer.parseInt;
public class _1681A_SpaceNavigation {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int test = parseInt(input.nextLine());
while(test-- > 0){
int x = input.nextInt();
int y = input.nextInt();
input.nextLine();
String direction = input.nextLine();
int up = 0;
int right = 0;
int down = 0;
int left = 0;
boolean flag1 = false;
boolean flag2 = false;
for(char c: direction.toCharArray()){
switch(c){
case 'U':
up++;
break;
case 'R':
right++;
break;
case 'L':
left--;
break;
case 'D':
down--;
break;
}
if(x == left || x == right){
flag1 = true;
}
if(y == up || y == down){
flag2 = true;
}
if(flag1 && flag2){
break;
}
}
if(flag1 && flag2){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
/*
6
10 5
RRRRRRRRRRUUUUU
1 1
UDDDRLLL
-3 -5
LDLDLDDDR
1 2
LLLLUU
3 -2
RDULRLLDR
-1 6
RUDURUUUUR
*/ | 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 17 | 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 | d789cd26c5cf6284bee8ef9079420177 | 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 |
//https://codeforces.com/problemset/problem/1481/A
import java.util.Scanner;
public class Space_Navigation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testcase = sc.nextInt();
while (testcase != 0) {
testcase--;
String result = "NO";
int x_fin = sc.nextInt(), y_fin = sc.nextInt(), count[] = new int[27];
String str = sc.next();
char s[] = str.toCharArray();
for (int i = 0; i < str.length(); i++) {
if (s[i] != 'L' && s[i] != 'D')
count[s[i] - (int) 'A']++;
else
count[s[i] - (int) 'A']--;
}
if (x_fin >= 0 && count['R' - (int) 'A'] >= x_fin) {
if (y_fin >= 0 && count['U' - (int) 'A'] >= y_fin || y_fin < 0 && count['D' - (int) 'A'] <= y_fin)
result = "YES";
} else if (x_fin <= 0 && count['L' - (int) 'A'] <= x_fin) {
if (y_fin >= 0 && count['U' - (int) 'A'] >= y_fin || y_fin < 0 && count['D' - (int) 'A'] <= y_fin)
result = "YES";
}
System.out.print(result);
if (testcase > 0)
System.out.println();
}
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 17 | 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 | 3ef120cf96e50cb96261b88e28426b74 | 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 n = sc.nextInt();
for(int i=0;i<n;i++){
int x=sc.nextInt();
int y=sc.nextInt();
boolean m=false;
boolean t=false;
String s=sc.next();
int r=0,u=0,l=0,d=0;
for(int k=0;k<s.length();k++){
if(s.charAt(k)=='R'){
r++;
}
if(s.charAt(k)=='U'){
u++;
}
if(s.charAt(k)=='L'){
l++;
}
if(s.charAt(k)=='D'){
d++;
}
}
if (x>=0 && r>=x){
m=true;
}
else if(x<=0 && l>=Math.abs(x)){
m=true;
}
if(y>=0 && u>=y){
t=true;
}
else if(y<=0 && d>=Math.abs(y)){
t=true;
}
if(m==true && t==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 | 5022101e71f489119fe18a4b966336d2 | 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.util.StringTokenizer;
/*
* A. Space Navigation
*/
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for (int t = 0; t < T; t++) {
st = new StringTokenizer(br.readLine()," ");
int X = Integer.parseInt(st.nextToken());
int Y = Integer.parseInt(st.nextToken());
int[] dist = new int[4];
String command = br.readLine();
for(int i =0;i<command.length();i++) {
char ch = command.charAt(i);
switch (ch) {
case 'U':
dist[0]++;
break;
case 'D':
dist[1]++;
break;
case 'R':
dist[2]++;
break;
case 'L':
dist[3]++;
break;
}
}
boolean answer = false;
if(X>0&& dist[2] >= X) {
if(Y>0 && dist[0]>=Y) {
answer = true;
}else if(Y<=0 && dist[1]>= Math.abs(Y)){
answer = true;
}
}else if(X<=0&& dist[3] >= Math.abs(X)){
if(Y>0 && dist[0]>= Y) {
answer = true;
}else if(Y<=0 && dist[1]>= Math.abs(Y)){
answer = true;
}
}
if(answer) {
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 | ee525204653d97d28f5d8450e05e50c3 | 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 FastScanner sc;
static PrintWriter pw;
static void pn(Object o){pw.println(o);}
static void p(Object o){pw.print(o);}
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
sc = new FastScanner();
pw = new PrintWriter(System.out);
int t = sc.ni();
while(t-->0)
{
int x=sc.ni(),y=sc.ni(),u=0,d=0,l=0,r=0;
String s = sc.next();
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 r++;
}
if(x>=0&&y>=0)
{
if(u>=y&&r>=x)pn("YES");
else pn("NO");
}
else if(x<=0&&y>=0)
{
if(l>=-x&&u>=y)pn("YES");
else pn("NO");
}
else if(x<=0&&y<=0)
{
if(d>=-y&&l>=-x)pn("YES");
else pn("NO");
}
else if(x>=0&&y<=0)
{
if(d>=-y&&r>=x)pn("YES");
else pn("NO");
}
}
pw.close();
// String[] s = sc.next().split(":");
// int h = Integer.valueOf(s[0]),m=Integer.valueOf(s[1]),fg=0;
// String i=h+"",j=(m+1)+"";
//
// while(!isPalindrome(i,j))
// {
// m++;
// j = m+"";
// if(m>=60) {h++;m=00;j=m+"";}
// if(h>=24) {h=00;m=00;i="00";j="00";}
// }
// pn((h!=0&&m!=0)?i+":"+j:"00:00");
// pw.close();
}
static boolean isPalindrome(String a, String b)
{
String x= "";
for(int i=0;i<b.length();i++)
{
x = b.charAt(i)+x;
}
if(x.equals(a))return true;
else return false;
}
static int[] reverse(int a[]){
for(int i=0;i<a.length/2;i++)
{
int temp = a[i];
a[i] = a[a.length-i-1];
a[a.length-i-1] = temp;
}
return a;
}
// static String swap(int n,String s)
// {
// String ans = "";
//
// for(int i=0;i<s.length();i++)
// {
// if(i==n)
// {
// ans += s.charAt(i+1);
// ans += s.charAt(i);
// continue;
// }
// ans += s.charAt(i);
//
// }
// return ans;
// }
static boolean check(int[][] a,int n,int m)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)if(a[i][j]!=-1)return false;
}
return true;
}
// static boolean check2(int n,int d)
// {
// while(n>d)
// {
// n -=d;
// if(check(n,d))return true;
// }
// return false;
// }
// static int sum(int n)
// {
// if(n>=10)return n;
// else
// {
// sum(n);
// }
// }
static int gcd(int a,int b)
{
if(b!=0)return gcd(b,a%b);
else return a;
}
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 | d2b9199010ca49c4efd942e893290b27 | 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.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
public class CF699Div2A {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine(int size) throws IOException {
byte[] buf = new byte[size]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
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 long nextLong() throws IOException {
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 double nextDouble() throws IOException {
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() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
final static PrintWriter out = new PrintWriter(new DataOutputStream(System.out));
final static StringBuilder ans = new StringBuilder();
public static void main(String[] args) {
try {
final Reader reader = new Reader();
int test = reader.nextInt();
int px, py;
String s;
for (; test > 0; test--) {
px = reader.nextInt();
py = reader.nextInt();
reader.readLine(0);
s = reader.readLine(1_000_000);
solution(px, py, s);
}
out.println(ans);
out.flush();
out.close();
} catch (Exception e) {
return;
}
}
private static void solution(int px, int py, String s) {
int u, r, l, d;
u = r = l = d = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == 'U') {
u++;
} else if (c == 'R') {
r++;
} else if (c == 'L') {
l++;
} else if (c == 'D') {
d++;
}
}
if (px >= 0 && py >= 0) {
if (r >= px && u >= py) {
ans.append("YES").append('\n');
return;
}
} else if (px >= 0 && py < 0) {
if (r >= px && d >= Math.abs(py)) {
ans.append("YES").append('\n');
return;
}
} else if (px < 0 && py >= 0) {
if (l >= Math.abs(px) && u >= py) {
ans.append("YES").append('\n');
return;
}
} else if (px < 0 && py < 0) {
if (l >= Math.abs(px) && d >= Math.abs(py)) {
ans.append("YES").append('\n');
return;
}
}
ans.append("NO").append('\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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.