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
79e52172b399fe421c8562a08f4baf67
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class Rough { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); String str = sc.next(); String s = sc.next(); char c [] = str.toCharArray(); char c1 [] = s.toCharArray(); boolean flag = true; for(int i=0; i<n; i++) { if(c[i]==c1[i] || (c[i]=='G' && c1[i]=='B') || c[i]=='B' && c1[i]=='G') { flag = true; }else { flag = false; break; } } if(flag==false) { System.out.println("NO"); }else{ System.out.println("YES"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
8e8d349722ce5d78d3cbf49c947ced7a
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Fast f = new Fast(System.in); int t = f.nextInt(); while (t--!=0) { int n = f.nextInt(); String s1 = f.next(); String s2 = f.next(); boolean flag = true; for (int i = 0 ; i < n ; i++) { if((s1.charAt(i) == 'R' && s2.charAt(i) != 'R') || (s1.charAt(i) != 'R' && s2.charAt(i) == 'R') ) flag = false; } System.out.println(flag?"YES":"NO"); } System.out.flush(); System.out.close(); } } class Fast { StringTokenizer st; BufferedReader br; public Fast(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Fast(String file) throws IOException { br = new BufferedReader(new FileReader(file)); } public Fast(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
f861fa0cb7e1487ae9b2cccde9b26df7
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { Fast f = new Fast(System.in); int t = f.nextInt(); while (t--!=0) { int n = f.nextInt(); String s1 = f.next(); String s2 = f.next(); System.out.println(s1.replace("B","G").equals(s2.replace("B","G"))?"YES":"NO"); } System.out.flush(); System.out.close(); } } class Fast { StringTokenizer st; BufferedReader br; public Fast(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Fast(String file) throws IOException { br = new BufferedReader(new FileReader(file)); } public Fast(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
5572989cc7f2c6c7a1693dc2a8f4577a
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedReader; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.Flushable; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Submit { public static void main(String ...strings) { try(InputReader reader = new InputReader(); OutputWriter writer = new OutputWriter(true)){ int testCase = reader.nextInt(); for(int i = 0; i< testCase; i++) { int rowLength = reader.nextInt(); char [] firstRow = reader.next().toCharArray(); char [] secondRow = reader.next().toCharArray(); boolean status = true; for(int j = 0; j< rowLength; j++) { if((firstRow [j] == 'R' && secondRow [j] != 'R') || (firstRow[j] != 'R' && secondRow[j] == 'R')) { status = false; break; } } if(status) { writer.println("YES"); } else { writer.println("NO"); } } } } } 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(); } } } class OutputWriter implements AutoCloseable, Flushable { private final BufferedWriter writer; private boolean autoFlush; public OutputWriter() { this.writer = new BufferedWriter(new OutputStreamWriter(System.out)); } public OutputWriter(boolean autoFlush) { this(); this.autoFlush = autoFlush; } public void printWithSpace(int input) { try { writer.append(input + " "); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void print(int input) { try { writer.append(input + ""); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void println(int input) { try { writer.append(input + System.lineSeparator()); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void printWithSpace(String input) { try { writer.append(input + " "); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void print(String input) { try { writer.append(input); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void println(CharSequence input) { try { writer.append(input); writer.append(System.lineSeparator()); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void printArray() { // implement if (autoFlush) { flush(); } } @Override public void flush() { try { this.writer.flush(); } catch (IOException e) { e.printStackTrace(); } } @Override public void close() { try { writer.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
b5411bbfb4e776f9db05e9462c27f2b3
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedReader; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.Flushable; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Submit { public static void main(String ...strings) { try(InputReader reader = new InputReader(); OutputWriter writer = new OutputWriter(true)){ int testCase = reader.nextInt(); for(int i = 0; i< testCase; i++) { int rowLength = reader.nextInt(); char [] firstRow = reader.next().toCharArray(); char [] secondRow = reader.next().toCharArray(); int counter = 0; for(int j = 0; j< rowLength; j++) { if((firstRow [j] == 'R' && secondRow [j] != 'R') || (firstRow[j] != 'R' && secondRow[j] == 'R')) { continue; } else { counter++; } } if(counter == rowLength) { writer.println("YES"); } else { writer.println("NO"); } } } } } 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(); } } } class OutputWriter implements AutoCloseable, Flushable { private final BufferedWriter writer; private boolean autoFlush; public OutputWriter() { this.writer = new BufferedWriter(new OutputStreamWriter(System.out)); } public OutputWriter(boolean autoFlush) { this(); this.autoFlush = autoFlush; } public void printWithSpace(int input) { try { writer.append(input + " "); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void print(int input) { try { writer.append(input + ""); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void println(int input) { try { writer.append(input + System.lineSeparator()); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void printWithSpace(String input) { try { writer.append(input + " "); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void print(String input) { try { writer.append(input); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void println(CharSequence input) { try { writer.append(input); writer.append(System.lineSeparator()); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void printArray() { // implement if (autoFlush) { flush(); } } @Override public void flush() { try { this.writer.flush(); } catch (IOException e) { e.printStackTrace(); } } @Override public void close() { try { writer.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
a18d92f17cf506dbaaaf73629b461cf9
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class Div2 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int count=0; for (int i = 0; i < n; i++) { int num=sc.nextInt(); String str1=sc.next(); String str2=sc.next(); String str3=str1.replace('B', 'G'); String str=str2.replace('B', 'G'); for (int j = 0; j < num; j++) { if(str3.charAt(j)==str.charAt(j)){ count ++; } } if(count ==num){ System.out.println("YES"); } else{ System.out.println("NO"); } count=0; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
a1bc6933b6a55c70365a18b3bee07f88
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; /** * * @author mafia */ public class ProblemSolving { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner scan = new Scanner(System.in); int t, n; t = scan.nextInt(); while (t-- > 0) { boolean x = true; n = scan.nextInt(); String[][] arr = new String[2][n]; String[] array = new String[2]; array[0] = scan.next(); array[1] = scan.next(); for (int i = 0; i < 2; i++) { for (int j = 0; j < n; j++) { arr[i][j] = "" + array[i].charAt(j); } } for (int k = 0; k < n; k++) { if (arr[0][k].compareTo(arr[1][k]) == 0 || (arr[0][k].compareTo("G") == 0 && arr[1][k].compareTo("B") == 0) || (arr[0][k].compareTo("B") == 0 && arr[1][k].compareTo("G") == 0)) { x = true; } else { x = false; break; } } if (x == true) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
15ab7f4e4b942f4c73ef15a58d4961d1
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
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(); for (int i = 0; i < t; i++) { int n = in.nextInt(); String s1 = in.next(); String s2 = in.next(); StringBuilder compareS1 = new StringBuilder(); StringBuilder compareS2 = new StringBuilder(); for (int j = 0; j < n; j++) { if (s1.charAt(j) == 'B') compareS1.append('G'); else compareS1.append(s1.charAt(j)); } for (int j = 0; j < n; j++) { if (s2.charAt(j) == 'B') compareS2.append('G'); else compareS2.append(s2.charAt(j)); } if (String.valueOf(compareS1).equals(String.valueOf(compareS2))) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
f8a37d6e2ee0800b39df152b4c451194
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
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(); for (int i = 0; i < t; i++) { int n = in.nextInt(); String s1 = in.next(); String s2 = in.next(); StringBuilder compareS1 = new StringBuilder(); StringBuilder compareS2 = new StringBuilder(); for (int j = 0; j < n; j++) { if (s1.charAt(j) == 'B') compareS1.append('G'); else compareS1.append(s1.charAt(j)); } for (int j = 0; j < n; j++) { if (s2.charAt(j) == 'B') compareS2.append('G'); else compareS2.append(s2.charAt(j)); } String ScompareS1 = String.valueOf(compareS1); String ScompareS2 = String.valueOf(compareS2); if (ScompareS1.equals(ScompareS2)) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
d4015658a070f9ab138dc9223e289fb3
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class colurBlind { public static void main(String[] args) throws Exception { // Scanner scn=new Scanner(System.in); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); //int t= scn.nextInt(); while(t-->0){ int n=Integer.parseInt(br.readLine()); // int n=scn.nextInt(); char[][] arr=new char[2][n]; //String s1=scn.next(); String s1=br.readLine(); String s2=br.readLine(); // String s2=scn.next(); int i=0; for( i=0;i<n;i++){ arr[0][i]=s1.charAt(i); arr[1][i]=s2.charAt(i); if(arr[0][i]==arr[1][i]){ continue; } else if(arr[0][i]=='B' && arr[1][i] =='G'){ continue; } else if(arr[0][i]=='G' && arr[1][i] =='B'){ continue; } else{ System.out.println("NO"); break; } } if(i==n){ System.out.println("YES"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
ba702ccdc23817798044a259dfc464aa
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
//package codeforces; import java.util.Scanner; public class colurBlind { public static void main(String[] args) { Scanner scn=new Scanner(System.in); int t= scn.nextInt(); while(t-->0){ int n=scn.nextInt(); char[][] arr=new char[2][n]; String s1=scn.next(); String s2=scn.next(); int i=0; for( i=0;i<n;i++){ arr[0][i]=s1.charAt(i); arr[1][i]=s2.charAt(i); if(arr[0][i]==arr[1][i]){ continue; } else if(arr[0][i]=='B' && arr[1][i] =='G'){ continue; } else if(arr[0][i]=='G' && arr[1][i] =='B'){ continue; } else{ System.out.println("NO"); break; } } if(i==n){ System.out.println("YES"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
c9624fae69fc905b55cd857b0a12f10a
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner ; public class Main{ public static void main(String[] args) { Scanner user = new Scanner (System.in); int cases = user.nextInt(); for(int i = 0 ; i < cases ; i++){ int r = user.nextInt(); String color1 = user.next(); String color2 = user.next(); char[] arr1 = color1.toCharArray(); char[] arr2 = color2.toCharArray(); // green from blue. for(int j = 0 ; j < arr1.length ;j++){ if(arr1[j] == 'G'){ arr1[j] = 'B'; } if(arr2[j] == 'G'){ arr2[j] = 'B'; } } boolean res = true; for(int k = 0 ; k < arr1.length ; k++){ if(arr1[k] != arr2[k]){ res = false; } } System.out.println((res) ? "YES" : "NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
5141053f4e46e69223d58fd5bb3285df
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String [] args) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); StringBuilder res = new StringBuilder(); int t = fs.nextInt(); while(t-- > 0) { int n = fs.nextInt(); boolean ch = true; char [] c1 = fs.next().toCharArray(); char [] c2 = fs.next().toCharArray(); int cnt = 0, a = 0; for (int i = 0; i < n; i++) { if((c1[i] == 'G' && c2[i]=='B') || (c2[i] == 'G' && c1[i]=='B')) { cnt++; } if(c1[i] == c2[i]) { cnt++; } } res.append(cnt== n ? "YES" : "NO").append("\n"); } out.print(res); out.close(); } 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()); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
3794d892e624b37f05d99656b339db78
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String [] args) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); StringBuilder res = new StringBuilder(); int t = fs.nextInt(); while(t-- > 0) { int n = fs.nextInt(); boolean ch = true; char [] c1 = fs.next().toCharArray(); char [] c2 = fs.next().toCharArray(); int cnt = 0, a = 0; for (int i = 0; i < n; i++) { if((c1[i] == 'G' && c2[i]=='B') || (c2[i] == 'G' && c1[i]=='B')) { cnt++; } if((c1[i] == 'G' && c2[i]=='G') || (c2[i] == 'B' && c1[i]=='B') || (c2[i] == 'R' && c1[i]=='R')) { cnt++; } } res.append(cnt== n ? "YES" : "NO").append("\n"); } out.print(res); out.close(); } 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()); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
15f8dae462e1b9854b0de9c97398f63d
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.PrintWriter; public class T1722B { private static final T1722BFastScanner in = new T1722BFastScanner(); private static final PrintWriter out = new PrintWriter(System.out); public static void main(String args[]) { int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); String first = in.nextLine(); String second = in.nextLine(); first = first.replaceAll("B", "G"); second = second.replaceAll("B", "G"); out.println(first.equals(second) ? "YES" : "NO"); } out.flush(); } } class T1722BFastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public T1722BFastScanner() { in = new BufferedInputStream(System.in, BS); } public T1722BFastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n' && c != '\r') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
07aece360242f06ed767835891bcafc2
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.PrintWriter; public class T1722B { private static final T1722BFastScanner in = new T1722BFastScanner(); private static final PrintWriter out = new PrintWriter(System.out); public static void main(String args[]) { int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); String first = in.nextLine(); String second = in.nextLine(); first = first.replaceAll("B", "G"); second = second.replaceAll("B", "G"); System.out.println(first.equals(second) ? "YES" : "NO"); } out.flush(); } } class T1722BFastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public T1722BFastScanner() { in = new BufferedInputStream(System.in, BS); } public T1722BFastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n' && c != '\r') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
fc957490816472ebc6e3fc82532ae689
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; public class A { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) throws IOException { FastReader ob =new FastReader(); try { int t=ob.nextInt(); while(t--!=0) { int n=ob.nextInt(); char[][] mat =new char[2][n]; for(int i=0;i<2;i++) { String a=ob.next(); for(int j=0;j<n;j++) { mat[i][j]=a.charAt(j); } } StringBuilder a =new StringBuilder(); StringBuilder b =new StringBuilder(); for(int i=0;i<2;i++) { for(int j=0;j<n;j++) { mat[i][j]=mat[i][j]=='G'?'B':mat[i][j]; if(i==0) a.append(mat[i][j]); else b.append(mat[i][j]); } } System.out.println(a.toString().equals(b.toString())?"YES":"NO"); } } catch (Exception e) { return; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
e427022a3000ae70d535b9f94890a846
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int test = in.nextInt(); for(int t = 1;t <=test;t++){ int n = in.nextInt(); String s1 = in.next(); String s2 = in.next(); s1=s1.replaceAll("G","B"); s2=s2.replace('G', 'B'); debug(s1+" "+s2); if(s1.equals(s2)){ pw.println("YES"); } else { pw.println("NO"); } } pw.close(); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
0f757350bee833ef9b949016b07e85e9
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int test = in.nextInt(); for(int t =1;t<=test;t++) { int n = in.nextInt(); String s1 = in.next(); String s2 = in.next(); char ch1[] =s1.toCharArray(),ch2[] = s2.toCharArray(); boolean flag = true; for(int i = 0;i<n;i++) { if(ch1[i]=='R'){ if(ch2[i]=='R'){ continue; } else { flag= false; break; } } else if (ch1[i] == 'G') { if (ch2[i] == 'G' || ch2[i] == 'B') { continue; } else { flag = false; break; } } else { if (ch2[i] == 'G' || ch2[i] == 'B') { continue; } else { flag = false; break; } } } if(flag){ pw.println("YES"); } else { pw.println("NO"); } } pw.close(); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
358943fd85c958684db326f4e6c2ae48
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
//package codeforces; import com.sun.org.apache.bcel.internal.generic.BREAKPOINT; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; public class B { public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); StringBuffer sb = new StringBuffer(); while (t-->0){ int n =sc.nextInt(); char[][] grid = new char[2][n]; for (int i=0;i<2;i++){ String inp = sc.next(); for (int j=0;j<n;j++){ grid[i][j] = inp.charAt(j); if (grid[i][j]=='G') grid[i][j]='B'; } } String ans = "Yes"; for (int i=0;i<n;i++){ if (grid[0][i] != grid[1][i]){ ans = "No"; } } sb.append(ans).append("\n"); } System.out.print(sb.toString()); } 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\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
1ab86e9b5af719a8356bb569272f7872
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); a: for (int i = 0; i < t; i++) { int n = scan.nextInt(); String s1 = scan.next(); String s2 = scan.next(); char[] arr1 = s1.toCharArray(); char[] arr2 = s2.toCharArray(); if (arr1.length != arr2.length) { System.out.println("No"); continue; } for (int j = 0; j < arr1.length; j++) { if (arr1[j] == 'R' && arr2[j] == 'R') { } else if ((arr1[j] == 'B' || arr1[j] == 'G') && (arr2[j] == 'B' || arr2[j] == 'G')) { } else { System.out.println("No"); continue a; } } System.out.println("Yes"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
b5286c35faf939f22621d31f661fdf39
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class Solution { public static String isSame(String s1,String s2) { if(s1.equals(s2)) return "YES"; if(s1.length()!=s2.length()) return "NO"; /* Map<Character,Integer> map1=new HashMap<>(); Map<Character,Integer> map2=new HashMap<>(); for(int i=0;i<s1.length();i++) { if(!map1.containsKey(s1.charAt(i))) map1.put(s1.charAt(i), 1); else map1.put(s1.charAt(i), map1.get(s1.charAt(i))+1); } for(int i=0;i<s2.length();i++) { if(!map2.containsKey(s2.charAt(i))) map2.put(s2.charAt(i), 1); else map2.put(s2.charAt(i), map2.get(s2.charAt(i))+1); }*/ for(int i=0;i<s1.length();i++) { if(s1.charAt(i)=='R' && s2.charAt(i)!='R' || s1.charAt(i)!='R' && s2.charAt(i)=='R') return "NO"; } return "YES"; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); String s1=sc.next(); String s2=sc.next(); System.out.println(isSame(s1,s2)); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
d6c50e918bebc945fe16eef8300ee42c
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; public class Colourblind { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int test = 0;test<t;test++) { int n = sc.nextInt();sc.nextLine(); String a = sc.nextLine(); String b = sc.nextLine(); String newa = ""; String newb = ""; for(int i=0; i<n; i++) { if(a.charAt(i) == 'G' || a.charAt(i) == 'B') { newa += 'K'; }else { newa += a.charAt(i); } } for(int i=0; i<n; i++) { if(b.charAt(i) == 'G' || b.charAt(i) == 'B') { newb += 'K'; }else { newb += b.charAt(i); } } if(!newa.equals(newb)) { System.out.println("NO"); }else { System.out.println("YES"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
1c755a81947be8a9a54e5c471f94fbfb
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class Ok { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int cnt=0; cnt<t; cnt++) { int n = sc.nextInt(); String w = sc.nextLine(); String s1 = sc.nextLine(); String s2 = sc.nextLine(); int flag=0; for (int i=0; i<n; i++) { char ch1 = s1.charAt(i); char ch2 = s2.charAt(i); if (ch1==ch2)continue; if (ch1=='G' && ch2=='B')continue; if (ch1=='B' && ch2 =='G')continue; flag = 1; } if (flag==1) System.out.println("NO"); else System.out.println("YES"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
8afaa0a4a20169dfd7b7421bd6ddfbf3
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class sol { public static void main(String args[]) { // Your Code Here Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); String s1 = sc.next(); String s2 = sc.next(); int c = 0; for(int i = 0; i < n ;i++){ if(s2.charAt(i) == 'R' && s1.charAt(i) == 'R'){ c++; }else if((s1.charAt(i) == 'B' || s1.charAt(i)=='G') && (s2.charAt(i) == 'B' || s2.charAt(i) == 'G')){ c++; } } if(c == n){ System.out.println("YES"); }else{ System.out.println("NO"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
4b93eb3394d6a3a8b50328782d56de49
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int x=0;x<n;x++){ int k=sc.nextInt(); String s1=sc.next(); String s2=sc.next(); int i=0;int flag=0; while(i<k){ if( s1.charAt(i)=='G' && s2.charAt(i)=='B' || s1.charAt(i)=='B' && s2.charAt(i)=='G' || s1.charAt(i)==s2.charAt(i)) i++; else{ flag=1; break; } } if(flag==0) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
0b7b7798c54bcb302abd87f52329f264
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import javax.naming.NamingEnumeration; import javax.swing.plaf.IconUIResource; import javax.swing.plaf.synth.SynthOptionPaneUI; import java.awt.font.FontRenderContext; import java.awt.image.ImageProducer; import java.beans.beancontext.BeanContextServiceRevokedEvent; import java.lang.reflect.Array; import java.util.*; import java.math.BigInteger; public class ques { 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(); String s1= sc.next(); String s2= sc.next(); char[] arr1= s1.toCharArray(); char[] arr2= s2.toCharArray(); int ans=1; for (int j=0; j<x; j++){ if (arr1[j]=='B') arr1[j] ='G'; if (arr2[j]=='B') arr2[j] ='G'; } for (int j=0; j<x; j++){ if (arr1[j]!=arr2[j]) ans =0; } if (ans==1) System.out.println("yes"); else System.out.println("no"); } }}
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
501ecceed1ba1bbf3301601c5059fdf5
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.lang.reflect.Array; import java.util.*; public class SecondProjectkoi{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(); for (int i = 0; i < n; i++) { int san = in.nextInt(); String first = in.next(); char[] chars = first.toCharArray(); ArrayList<Character> arrayList = new ArrayList<>(); ArrayList<Character> array = new ArrayList<>(); String second = in.next(); char[] charss = second.toCharArray(); for (int j = 0; j < chars.length; j++) { arrayList.add(chars[j]); array.add(charss[j]); } int count = 0; for (int j = 0; j < array.size(); j++) { if(arrayList.get(j) == 'R') { if(array.get(j) == 'R'){ count++; continue; } else { System.out.println("No"); break; } } else if(array.get(j) == 'R') { if(arrayList.get(j) == 'R'){ count++; continue; } else { System.out.println("No"); break; } } else count++; } if(count == array.size()) System.out.println("Yes"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
4cc1458d828c8a6714405372484a3410
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; public class B{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } 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()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static void main(String[] args) { try { FastReader in = new FastReader(); FastWriter out = new FastWriter(); int testCases = in.nextInt(); while(testCases --> 0){ // write code here int n = in.nextInt(); String str1 = in.next(); String str2 = in.next(); int countR = 1; for (int i = 0; i < n; i++) { if (str1.charAt(i) == 'R') if (str2.charAt(i) != 'R') countR = 0; if (str2.charAt(i) == 'R') if (str1.charAt(i) != 'R') countR = 0; } if (countR == 1) System.out.println("YES"); else System.out.println("NO"); } out.close(); } catch (Exception e) { return; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
f372d50183771f4932114f1d5714a665
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class Colourblindness { public static void fun(int n, String[] s){ for(int i=0; i<n; i++){ if( ('R'==s[0].charAt(i) && 'R'!=s[1].charAt(i)) || ('G'==s[0].charAt(i) && 'R'==s[1].charAt(i)) || ('B'==s[0].charAt(i) && 'R'==s[1].charAt(i)) ){ System.out.println("NO"); return; } } System.out.println("YES"); return; } public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0){ int n = sc.nextInt(); String[] s = new String[2]; s[0] = sc.next(); s[1] = sc.next(); // System.out.println(s[0].charAt(0)); // System.out.println(s[1].charAt(0)); fun(n,s); t--; } sc.close(); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
9c1505e11fdc88f8facd448ccff201f2
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // String template = "Timur"; while(n--!=0){ int len = sc.nextInt(); String s1 = sc.next(); String s2 = sc.next(); char[] s_list = s1.toCharArray(); char[] t_list = s2.toCharArray(); // Arrays.sort(s_list); // Arrays.sort(t_list); boolean flag = false; for(int i=0;i<len;i++){ if(s_list[i]!=t_list[i]){ if(s_list[i]=='R'||t_list[i]=='R'){ flag = true; break; } } } if(flag) System.out.println("NO"); else System.out.println("YES"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
a7c699af716a1f3086547f6ba3426ca0
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
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 { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0) { int n=sc.nextInt(); long ans1=0, ans2=0; String s=sc.next(); String s1=sc.next(); int ans=0; for(int i=0; i<n; i++) { char ch=s.charAt(i); char ch1=s1.charAt(i); if(s.charAt(i)==s1.charAt(i)|| (s.charAt(i)=='G' && s1.charAt(i)=='B') || (s1.charAt(i)=='G' && s.charAt(i)=='B'))ans++; } if(ans==n) System.out.println("YES"); else System.out.println("NO"); } } catch(Exception e) { } // your code goes here } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
3fe2390fd2c3a4ba5ee6a42a1b431858
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class rgb { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t != 0) { int l=sc.nextInt(); String s = sc.next(); String d = sc.next(); int i; for (i = 0; i < s.length(); i++) { char c = s.charAt(i); char e=d.charAt(i); if((c=='B' ||c=='G') && e=='R') {System.out.println("No"); break;} else if((e=='B' || e=='G') && c=='R') {System.out.println("No"); break;} } if(i==s.length()) System.out.println("Yes"); t--; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
299bec7ec2e0a5139f78785d4e4d343f
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class ColurBlinds { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0) { int c = sc.nextInt(); String str = sc.next(); String str2 =sc.next(); int flag=0; for(int i=0;i<c;i++) { if(str.charAt(i)==str2.charAt(i)) { flag=0; } else if((str.charAt(i)=='G' && str2.charAt(i)=='B') || (str.charAt(i)=='B' && str2.charAt(i)=='G')) { flag=0; } else { flag=1; break; } } if(flag==1) { System.out.println("NO"); } else { System.out.println("YES"); } t--; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
3deb16981ae42d65d576a271a83b82d4
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
/****************************************************************************** Online Java Compiler. Code, Compile, Run and Debug java program online. Write your code in this editor and press "Run" button to execute it. *******************************************************************************/ 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)); BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); int t=Integer.parseInt(br.readLine()); for(int m=0;m<t;m++){ int n=Integer.parseInt(br.readLine()); String s1=br.readLine(); String s2=br.readLine(); char[] c1=s1.toCharArray(); char[] c2=s2.toCharArray(); for(int i=0;i<n;i++){ if(c1[i]=='G') c1[i]='B'; if(c2[i]=='G') c2[i]='B'; } if(Arrays.equals(c1,c2)) bw.write("Yes"); else bw.write("NO"); bw.write("\n"); } bw.flush(); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
656761a4708fb2c729bf9348b867c53b
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.lang.*; import java.io.*; 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 n=sc.nextInt(); sc.nextLine(); String s1=sc.nextLine(); String s2=sc.nextLine(); boolean flag=true; for(int i=0;i<n;i++){ if((s1.charAt(i)=='R' && s2.charAt(i)=='B') || (s1.charAt(i)=='R' && s2.charAt(i)=='G') || (s1.charAt(i)=='B' && s2.charAt(i)=='R') || (s1.charAt(i)=='G' && s2.charAt(i)=='R')){ flag=false; break; } } if(flag) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
aa28ac8ee966ad450605d02aba058220
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class B { public static void main (String[] args) throws java.lang.Exception { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); while (t-- != 0) { int n = sc.nextInt(); String s1 = sc.next(); String s2 = sc.next(); boolean contains = false; for(int i = 0; i < s1.length(); i++) { if ((s1.charAt(i) == 'B' || s1.charAt(i) == 'G') && (s2.charAt(i) == 'R')) { contains = true; } else if ((s2.charAt(i) == 'B' || s2.charAt(i) == 'G') && (s1.charAt(i) == 'R')) { contains = true; } } out.println(!contains ? "YES" : "NO"); } out.close(); } public static PrintWriter out; public static 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\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
922c682cd27a8b9940e7b9f636e30ca7
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
//import java.util.ArrayList; //import java.util.Objects; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt(),y; int flag; String s,c; String[] arr=new String[x]; for (int i = 0; i < x; i++) { y=scan.nextInt(); s=scan.next(); c=scan.next(); flag=0; for(int j=0;j<y;j++){ if(!(s.charAt(j)==c.charAt(j)||(s.charAt(j)=='B'&&c.charAt(j)=='G')||(s.charAt(j)=='G'&&c.charAt(j)=='B'))) flag=1; } if(flag==1) arr[i]="NO"; else arr[i]="YES"; } for (String string : arr) { System.out.println(string); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
3c094635ff9f73121dd555b66cec16a8
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; /** * * @author Hp */ public class ColorBlindedness { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); String output[] = new String[t]; for (int i = 0; i < t; i++) { int n = sc.nextInt(); sc.nextLine(); String firstLine = sc.nextLine(); String secondLine = sc.nextLine(); firstLine = firstLine.replaceAll("G", "B"); secondLine = secondLine.replaceAll("G", "B"); if (secondLine.equals(firstLine)) { output[i] = "YES"; } else { output[i] = "NO"; } } for (int i = 0; i < t; i++) { System.out.println(output[i]); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
0970abd685b375b041293484178f39f4
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; public class CF1722B { public static void main (String[] arg) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); Outer: for(int i = 0; i < n; i++) { int l = Integer.parseInt(br.readLine()); String s1 = br.readLine(); String s2 = br.readLine(); for(int j = 0; j < s1.length(); j++) { char c1 = s1.charAt(j); char c2 = s2.charAt(j); if (c1 == c2 || (c1 == 'G' && c2 == 'B') || (c1 == 'B' && c2 == 'G')) continue; System.out.println("No"); continue Outer; } System.out.println("Yes"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
b5934c4e116b55e682bff7928c9d5e83
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int q=0;q<t;q++) { boolean flag=true; int n=sc.nextInt(); char[][]arr=new char[2][n]; for(int z=0;z<2;z++) { String str=sc.next(); for(int j=0;j<str.length();j++) { arr[z][j]=str.charAt(j); } } for(int k=0;k<2;k++) { for(int r=0;r<n;r++) { if(arr[k][r]=='G') arr[k][r]='B'; } } HashMap<String, Integer>map=new HashMap<>(); for(int k=0;k<2;k++) { String str2=""; for(int r=0;r<n;r++) { str2+=arr[k][r]; } if(!map.containsKey(str2)) map.put(str2,1); else { System.out.println("YES"); flag=false; break; } } if(flag==true) System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
193802e17964d051b81398be39716a72
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int t = Integer.parseInt(in.readLine()); while(t-- > 0) { int n = Integer.parseInt(in.readLine()); String r1 = in.readLine(); String r2 = in.readLine(); String ret = "YES"; for (int i = 0; i < r1.length(); i++) { if((r1.charAt(i) == 'R' && r2.charAt(i) != 'R') || (r1.charAt(i) != 'R' && r2.charAt(i) == 'R')) { ret = "NO"; } } out.write(ret+"\n"); out.flush(); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
fd50f50e9e24c0b4c0324500e4d2e0aa
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import com.sun.org.apache.xerces.internal.impl.xpath.XPath; import java.io.*; import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int t = in.nextInt(); while (t-- > 0){ int n = in.nextInt(); String s1 = in.next(); String s2 = in.next(); int f = 0; for (int i = 0; i < n; i++) { char a = s1.charAt(i); char b = s2.charAt(i); if (a != b){ if (!(a == 'G' && b == 'B' || a == 'B' && b == 'G')){ f = 1; break; } } } if (f == 0) out.println("YES"); else out.println("NO"); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } boolean hasNext() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (Exception e) { return false; // TODO: handle exception } } return true; } 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 String nextLine() { String str = null; try { str = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble(){ return Double.parseDouble(next()); } public long nextLong(){ return Long.parseLong(next()); } public BigInteger nextBigInteger() { return new BigInteger(next()); } public BigDecimal nextBigDecimal() { return new BigDecimal(next()); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
0e3911d10bed8f8e0a75361c175fcce8
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class esep { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); while(x-->0) { int n = sc.nextInt(); sc.nextLine(); String s = sc.nextLine(); String l = sc.nextLine(); System.out.println(play(s,l)?"YES":"NO"); } } public static boolean play(String s,String l) { for (int i = 0; i < s.length(); i++) { if(s.charAt(i)=='R' && l.charAt(i)!='R') return false; else if(l.charAt(i)=='R' && s.charAt(i)!='R') return false; else if((s.charAt(i)=='B' || s.charAt(i)=='G') && l.charAt(i)=='R') return false; else if((l.charAt(i)=='B' || l.charAt(i)=='G') && s.charAt(i)=='R') return false; } return true; } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
285591ae548693ba2a7b9b1e713bef9c
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); for(int i=0;i<T;i++) { int n=sc.nextInt(); String s1=sc.next(); String s2=sc.next(); int j=0; for(j=0;j<n;j++) { char ch1=s1.charAt(j); char ch2=s2.charAt(j); if(ch1==ch2) { // do nothing } else if((ch1=='G' && ch2=='B') || (ch1=='B' && ch2=='G')) { // do nothing } else { break; } } if(j==n) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
83471526c2f568487a1554c9c2f82cd5
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.*; import java.lang.*; import java.util.*; public class Main { static PrintWriter out; static int MOD = 1000000007; static FastReader scan; /*-------- I/O usaing short named function ---------*/ public static String ns() { return scan.next(); } public static int ni() { return scan.nextInt(); } public static long nl() { return scan.nextLong(); } public static double nd() { return scan.nextDouble(); } public static String nln() { return scan.nextLine(); } public static void p(Object o) { out.print(o); } public static void ps(Object o) { out.print(o + " "); } public static void pn(Object o) { out.println(o); } /*-------- for output of an array ---------------------*/ static void iPA(int arr[]) { StringBuilder output = new StringBuilder(); for (int i = 0; i < arr.length; i++) output.append(arr[i] + " "); out.println(output); } static void lPA(long arr[]) { StringBuilder output = new StringBuilder(); for (int i = 0; i < arr.length; i++) output.append(arr[i] + " "); out.println(output); } static void sPA(String arr[]) { StringBuilder output = new StringBuilder(); for (int i = 0; i < arr.length; i++) output.append(arr[i] + " "); out.println(output); } static void dPA(double arr[]) { StringBuilder output = new StringBuilder(); for (int i = 0; i < arr.length; i++) output.append(arr[i] + " "); out.println(output); } /*-------------- for input in an array ---------------------*/ static void iIA(int arr[]) { for (int i = 0; i < arr.length; i++) arr[i] = ni(); } static void lIA(long arr[]) { for (int i = 0; i < arr.length; i++) arr[i] = nl(); } static void sIA(String arr[]) { for (int i = 0; i < arr.length; i++) arr[i] = ns(); } static void dIA(double arr[]) { for (int i = 0; i < arr.length; i++) arr[i] = nd(); } /*------------ for taking input faster ----------------*/ 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; } } // Method to check if x is power of 2 static boolean isPowerOfTwo(int x) { return x != 0 && ((x & (x - 1)) == 0); } //Method to return lcm of two numbers static int gcd(int a, int b) { return a == 0 ? b : gcd(b % a, a); } //Method to count digit of a number static int countDigit(long n) { return (int) Math.floor(Math.log10(n) + 1); } //Method for sorting 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); } //Method for checking if a number is prime or not static boolean isPrime(int 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; } public static void reverse(int a[], int n) { int i, k, t; for (i = 0; i < n / 2; i++) { t = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = t; } // printing the reversed array System.out.println("Reversed array is: \n"); for (k = 0; k < n; k++) { System.out.println(a[k]); } } public static int binarysearch(int arr[],int left,int right,int num){ int idx=0; while(left<=right){ int mid=(left+right)/2; if(arr[mid]>=num){ idx=mid; if(arr[mid]==num)break; right=mid-1; }else{ left=mid+1; } } return idx; } public static void main(String[] args) throws java.lang.Exception { OutputStream outputStream = System.out; out = new PrintWriter(outputStream); scan = new FastReader(); //for fast output sometimes HashSet<Integer> set = new HashSet<>(); StringBuilder sb = new StringBuilder(); int t = ni(); while(t-->0){ int n=ni(); String str=scan.nextLine(); String str2=scan.nextLine(); boolean flag=true; for(int i=0;i<n;i++){ if(str.charAt(i)==str2.charAt(i)){ }else{ if((str.charAt(i)=='G'&&str2.charAt(i)=='B')||(str2.charAt(i)=='G'&&str.charAt(i)=='B')){ }else{ flag=false; break; } } } if(flag)System.out.println("YES"); else{ System.out.println("NO"); } } out.flush(); out.close(); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
2c902cb2c3b860c9394e4666552d228a
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
// "static void main" must be defined in a public class. import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int T = fs.nextInt(); for(int i = 0; i < T; i++) { int N = fs.nextInt(); String s = fs.next(); String t = fs.next(); char[] ch = s.toCharArray(); char[] ch1 = t.toCharArray(); int count = 0; int count1 = 0; for(char c : ch) { if(c == 'G' || c == 'B') { count++; } } for(char c : ch1) { if(c == 'G' || c == 'B') { count1++; } } boolean a = true; for(int j = 0; j < N; j++) { if(ch[j] == 'G' && ch1[j] == 'G') { }else if(ch[j] == 'B' && ch1[j] == 'B') { }else if(ch[j] == 'G' && ch1[j] == 'B') { }else if(ch[j] == 'B' && ch1[j] == 'G') { }else if(ch[j] == 'R' && ch1[j] == 'R') { }else{ a = false; break; } } if(a) { out.println("YES"); }else{ out.println("NO"); } } out.close(); } static int gcd(int a, int b) { if(b == 0) { return a; }else{ return gcd(b, a%b); } } 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) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
e946ebe1993383df8ba19110d4f654ac
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; public class C{ public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0){ int n=s.nextInt(); char c[]=s.next().toCharArray(); char d[]=s.next().toCharArray(); for(int i=0;i<n;i++){ if(c[i]=='G')c[i]='B'; if(d[i]=='G')d[i]='B'; } String a=new String(c); String b=new String(d);System.out.println(a.equals(b)?"Yes": "No"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
30c54c52a53b161495635d221b42eac6
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class Daltonizm { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i =0;i<n;i++){ int size = sc.nextInt(); String l1 = sc.next(); String l2 = sc.next(); String str1 = l1.replace('G','B'); String str2 = l2.replace('G','B'); if(str1.contains(str2)&&str2.contains(str1)){ System.out.println("YES"); } else{ System.out.println("NO"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
fb7c42c0267ec7e7dfd09a7856911ae9
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public final class B_Colourblindness { //int 2e9 - long 9e18 static PrintWriter out = new PrintWriter(System.out); static FastReader fs = new FastReader(); static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)}; static Pair[] movesDiagonal = new Pair[]{new Pair(-1, -1), new Pair(-1, 1), new Pair(1, -1), new Pair(1, 1)}; static int mod = (int) (1e9 + 7); static int mod2 = 998244353; public static void main(String[] args) { int tt = fs.nextInt(); while (tt-- > 0) { solve(); } out.flush(); } public static void solve() { int n=fs.nextInt(); String a=fs.next(); String b=fs.next(); for(int i=0;i<n;i++) { if(a.charAt(i)!=b.charAt(i)) { if((a.charAt(i)=='G' && b.charAt(i)=='B') || (a.charAt(i)=='B' && b.charAt(i)=='G')) { continue; } else { out.println("NO"); return; } } } out.println("YES"); } // (10,5) = 2 ,(11,5) = 3 static long upperDiv(long a, long b) { return (a / b) + ((a % b == 0) ? 0 : 1); } static long sum(int[] a) { long sum = 0; for (int x : a) { sum += x; } return sum; } static int[] preint(int[] a) { int[] pre = new int[a.length + 1]; pre[0] = 0; for (int i = 0; i < a.length; i++) { pre[i + 1] = pre[i] + a[i]; } return pre; } static long[] pre(int[] a) { long[] pre = new long[a.length + 1]; pre[0] = 0; for (int i = 0; i < a.length; i++) { pre[i + 1] = pre[i] + a[i]; } return pre; } static long[] post(int[] a) { long[] post = new long[a.length + 1]; post[0] = 0; for (int i = 0; i < a.length; i++) { post[i + 1] = post[i] + a[a.length - 1 - i]; } return post; } static long[] pre(long[] a) { long[] pre = new long[a.length + 1]; pre[0] = 0; for (int i = 0; i < a.length; i++) { pre[i + 1] = pre[i] + a[i]; } return pre; } 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 long mul(long a, long b) { return (a*b)%mod; } static long exp(long base, long exp) { if (exp==0) return 1; long half=exp(base, exp/2); if (exp%2==0) return mul(half, half); return mul(half, mul(half, base)); } static long[] factorials=new long[2_000_001]; static long[] invFactorials=new long[2_000_001]; static void precompFacts() { factorials[0]=invFactorials[0]=1; for (int i=1; i<factorials.length; i++) factorials[i]=mul(factorials[i-1], i); invFactorials[factorials.length-1]=exp(factorials[factorials.length-1], mod-2); for (int i=invFactorials.length-2; i>=0; i--) invFactorials[i]=mul(invFactorials[i+1], i+1); } static long nCk(int n, int k) { return mul(factorials[n], mul(invFactorials[k], invFactorials[n-k])); } static int[][] inputWithIdx(int N) { int A[][] = new int[N][2]; for (int i = 0; i < N; i++) { A[i] = new int[]{i, fs.nextInt()}; } return A; } static int[] input(int N) { int A[] = new int[N]; for (int i = 0; i < N; i++) { A[i] = fs.nextInt(); } return A; } static long[] inputLong(int N) { long A[] = new long[N]; for (int i = 0; i < A.length; i++) { A[i] = fs.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); } } static long LCM(int a, int b) { return (long) a / GCD(a, b) * b; } static long LCM(long a, long b) { return a / GCD(a, b) * b; } // find highest i which satisfy a[i]<=x static int lowerbound(int[] a, int x) { int l = 0; int r = a.length - 1; while (l < r) { int m = (l + r + 1) / 2; if (a[m] <= x) { l = m; } else { r = m - 1; } } return l; } static void shuffle(int[] arr) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); int temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } } static void shuffleAndSort(int[] arr) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); int temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } static void shuffleAndSort(int[][] arr, Comparator<? super int[]> comparator) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); int[] temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr, comparator); } static void shuffleAndSort(long[] arr) { for (int i = 0; i < arr.length; i++) { int rand = (int) (Math.random() * arr.length); long temp = arr[rand]; arr[rand] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } static boolean isPerfectSquare(double number) { double sqrt = Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static void swap(int A[], int a, int b) { int t = A[a]; A[a] = A[b]; A[b] = t; } static void swap(char A[], int a, int b) { char t = A[a]; A[a] = A[b]; A[b] = t; } static long pow(long a, long b, int mod) { 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 long pow(long a, long b) { long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) { pow *= x; } x = x * x; b /= 2; } return pow; } static long modInverse(long x, int mod) { return pow(x, mod - 2, mod); } 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; } public static String reverse(String str) { if (str == null) { return null; } return new StringBuilder(str).reverse().toString(); } public static void reverse(int[] arr) { int l = 0; int r = arr.length - 1; while (l < r) { swap(arr, l, r); l++; r--; } } public static String repeat(char ch, int repeat) { if (repeat <= 0) { return ""; } final char[] buf = new char[repeat]; for (int i = repeat - 1; i >= 0; i--) { buf[i] = ch; } return new String(buf); } public static int[] manacher(String s) { char[] chars = s.toCharArray(); int n = s.length(); int[] d1 = new int[n]; for (int i = 0, l = 0, r = -1; i < n; i++) { int k = (i > r) ? 1 : Math.min(d1[l + r - i], r - i + 1); while (0 <= i - k && i + k < n && chars[i - k] == chars[i + k]) { k++; } d1[i] = k--; if (i + k > r) { l = i - k; r = i + k; } } return d1; } public static int[] kmp(String s) { int n = s.length(); int[] res = new int[n]; for (int i = 1; i < n; ++i) { int j = res[i - 1]; while (j > 0 && s.charAt(i) != s.charAt(j)) { j = res[j - 1]; } if (s.charAt(i) == s.charAt(j)) { ++j; } res[i] = j; } return res; } } class Pair { int i; int j; Pair(int i, int j) { this.i = i; this.j = j; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Pair pair = (Pair) o; return i == pair.i && j == pair.j; } @Override public int hashCode() { return Objects.hash(i, j); } } class ThreePair { int i; int j; int k; ThreePair(int i, int j, int k) { this.i = i; this.j = j; this.k = k; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } ThreePair pair = (ThreePair) o; return i == pair.i && j == pair.j && k == pair.k; } @Override public int hashCode() { return Objects.hash(i, 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; } } class Node { int val; public Node(int val) { this.val = val; } } class ST { int n; Node[] st; ST(int n) { this.n = n; st = new Node[4 * Integer.highestOneBit(n)]; } void build(Node[] nodes) { build(0, 0, n - 1, nodes); } private void build(int id, int l, int r, Node[] nodes) { if (l == r) { st[id] = nodes[l]; return; } int mid = (l + r) >> 1; build((id << 1) + 1, l, mid, nodes); build((id << 1) + 2, mid + 1, r, nodes); st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]); } void update(int i, Node node) { update(0, 0, n - 1, i, node); } private void update(int id, int l, int r, int i, Node node) { if (i < l || r < i) { return; } if (l == r) { st[id] = node; return; } int mid = (l + r) >> 1; update((id << 1) + 1, l, mid, i, node); update((id << 1) + 2, mid + 1, r, i, node); st[id] = comb(st[(id << 1) + 1], st[(id << 1) + 2]); } Node get(int x, int y) { return get(0, 0, n - 1, x, y); } private Node get(int id, int l, int r, int x, int y) { if (x > r || y < l) { return new Node(0); } if (x <= l && r <= y) { return st[id]; } int mid = (l + r) >> 1; return comb(get((id << 1) + 1, l, mid, x, y), get((id << 1) + 2, mid + 1, r, x, y)); } Node comb(Node a, Node b) { if (a == null) { return b; } if (b == null) { return a; } return new Node(GCD(a.val, b.val)); } static int GCD(int a, int b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
990c4ee177a7c25d1fca0a03c9e63ab5
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Task_1722B { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int i = 0; i < t; i++) { solve(in); } } private static void solve(Scanner in) { long n = in.nextInt(); String s1 = in.next(); String s2 = in.next(); System.out.println(s1.replace("G", "B").equals(s2.replace("G", "B")) ? "YES" : "NO"); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
b92592bddc709c9b68bd766bc718889a
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
/** * @Jai_Bajrang_Bali * @Har_Har_Mahadev */ //@Author : Sanat04 import java.util.*; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder res = new StringBuilder(); int t = sc.nextInt(); // int t=1; while (t-- > 0) { int n = sc.nextInt(); String str = sc.next(); String str1= sc.next(); StringBuilder ans=new StringBuilder(str); StringBuilder ans1=new StringBuilder(str1); for (int i = 0; i < n; i++) { if(str.charAt(i)=='B' || str.charAt(i)=='G') ans.setCharAt(i,'A'); if(str1.charAt(i)=='B' || str1.charAt(i)=='G') ans1.setCharAt(i,'A'); } if (ans.toString().equals(ans1.toString())) res.append("YES").append("\n"); else res.append("NO").append("\n"); } System.out.println(res.toString()); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
5576b873b827eda329877f441c64543f
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class Test63 { public static void main (String[] args) throws java.lang.Exception { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int i; for (i = 0; i < t; i++) { int n = sc.nextInt(); sc.nextLine(); String a = sc.nextLine(); String b = sc.nextLine(); int flag = 0; for(int j=0; j<n ;j++) { if((a.charAt(j) == 'R' && b.charAt(j) != 'R') || (b.charAt(j) == 'R' && a.charAt(j) != 'R')) { flag = 1; break; } } if(flag == 0) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
1addc7fbc448e8e3bb1f89e7c566189d
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class leetcode { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-->0){ int n = sc.nextInt(); String s1 = sc.next(); String s2 = sc.next(); int cc = 0; for (int i = 0; i<s1.length(); i++){ if (String.valueOf(s1.charAt(i)).equals("R") && String.valueOf(s2.charAt(i)).equals("R")){ cc++; } else if ((String.valueOf(s1.charAt(i)).equals("B")&&String.valueOf(s2.charAt(i)).equals("B")) || (String.valueOf(s1.charAt(i)).equals("B")&&String.valueOf(s2.charAt(i)).equals("G")) || (String.valueOf(s1.charAt(i)).equals("G")&&String.valueOf(s2.charAt(i)).equals("B")) || (String.valueOf(s1.charAt(i)).equals("G")&&String.valueOf(s2.charAt(i)).equals("G"))){ cc++; } } if (s1.length()==cc){ System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
63db5e0cfc3089c23a4f76ea95589503
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; /** * @author Naitik * */ public class Main { static FastReader sc=new FastReader(); static int dp[][]; // static boolean v[][][]; // static int mod=998244353;; static int mod=1000000007; static long max; static int bit[]; static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { // StringBuffer sb=new StringBuffer(""); int ttt=1; ttt =i(); outer :while (ttt-- > 0) { int n=i(); char A[]=s().toCharArray(); char B[]=s().toCharArray(); for(int i=0;i<n;i++) { if(A[i]=='R' && B[i]!='R') { System.out.println("NO"); continue outer; } if(B[i]=='R' && A[i]!='R') { System.out.println("NO"); continue outer; } } System.out.println("YES"); } //System.out.println(sb.toString()); out.close(); //CHECK FOR N=1 //CHECK FOR M=0 //CHECK FOR N=1 //CHECK FOR M=0 //CHECK FOR N=1 } // public static void main(String args[]) { // Scanner sc=new Scanner(System.in); // // } static class Pair implements Comparable<Pair> { int x; int y; int z; Pair(int x,int y){ this.x=x; this.y=y; // this.z=z; } @Override public int compareTo(Pair o) { if(this.x>o.x) return 1; else if(this.x<o.x) return -1; else { if(this.y>o.y) return 1; else if(this.y<o.y) return -1; else return 0; } } public int hashCode() { final int temp = 14; long ans = 1; ans =x*31+y*13; return (int)ans; } // @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (this.getClass() != o.getClass()) { return false; } Pair other = (Pair)o; if (this.x != other.x || this.y!=other.y) { return false; } return true; } // /* FOR TREE MAP PAIR USE */ // public int compareTo(Pair o) { // if (x > o.x) { // return 1; // } // if (x < o.x) { // return -1; // } // if (y > o.y) { // return 1; // } // if (y < o.y) { // return -1; // } // return 0; // } } //static int find(int A[],int a) { // if(A[a]==a) // return a; // return A[a]=find(A, A[a]); //} //FENWICK TREE static void update(int i, int x){ for(; i < bit.length; i += (i&-i)) bit[i] += x; } static int sum(int i){ int ans = 0; for(; i > 0; i -= (i&-i)) ans += bit[i]; return ans; } //END static void add(HashMap<Long,Integer> map,long v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void remove(HashMap<Long,Integer> map,long v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } static void add(HashMap<Integer,Integer> map,int v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void remove(HashMap<Integer,Integer> map,int v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } static void add(TreeMap<Integer,Integer> map,int v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void add(TreeMap<Long,Integer> map,long v) { if(!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v)+1); } } static void remove(TreeMap<Integer,Integer> map,int v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } static void remove(TreeMap<Long,Integer> map,long v) { if(map.containsKey(v)) { map.put(v, map.get(v)-1); if(map.get(v)==0) map.remove(v); } } static long modInverse(long n, int p) { return power(n, p - 2, p); } static int[] copy(int A[]) { int B[]=new int[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static long[] copy(long A[]) { long B[]=new long[A.length]; for(int i=0;i<A.length;i++) { B[i]=A[i]; } return B; } static int[] input(int n) { int A[]=new int[n]; for(int i=0;i<n;i++) { A[i]=sc.nextInt(); } return A; } static long[] inputL(int n) { long A[]=new long[n]; for(int i=0;i<n;i++) { A[i]=sc.nextLong(); } return A; } static String[] inputS(int n) { String A[]=new String[n]; for(int i=0;i<n;i++) { A[i]=sc.next(); } return A; } static long sum(int A[]) { long sum=0; for(int i : A) { sum+=i; } return sum; } static long sum(long A[]) { long sum=0; for(long i : A) { sum+=i; } return sum; } static void reverse(long A[]) { int n=A.length; long B[]=new long[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static void reverse(int A[]) { int n=A.length; int B[]=new int[n]; for(int i=0;i<n;i++) { B[i]=A[n-i-1]; } for(int i=0;i<n;i++) A[i]=B[i]; } static void input(int A[],int B[]) { for(int i=0;i<A.length;i++) { A[i]=sc.nextInt(); B[i]=sc.nextInt(); } } static int[][] input(int n,int m){ int A[][]=new int[n][m]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { A[i][j]=i(); } } return A; } static char[][] charinput(int n,int m){ char A[][]=new char[n][m]; for(int i=0;i<n;i++) { String s=s(); for(int j=0;j<m;j++) { A[i][j]=s.charAt(j); } } return A; } static int nextPowerOf2(int n) { if(n==0) return 1; n--; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n++; return n; } static int highestPowerof2(int x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static long highestPowerof2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } static int max(int A[]) { int max=Integer.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static int min(int A[]) { int min=Integer.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long max(long A[]) { long max=Long.MIN_VALUE; for(int i=0;i<A.length;i++) { max=Math.max(max, A[i]); } return max; } static long min(long A[]) { long min=Long.MAX_VALUE; for(int i=0;i<A.length;i++) { min=Math.min(min, A[i]); } return min; } static long [] prefix(long A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] prefix(int A[]) { long p[]=new long[A.length]; p[0]=A[0]; for(int i=1;i<A.length;i++) p[i]=p[i-1]+A[i]; return p; } static long [] suffix(long A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static long [] suffix(int A[]) { long p[]=new long[A.length]; p[A.length-1]=A[A.length-1]; for(int i=A.length-2;i>=0;i--) p[i]=p[i+1]+A[i]; return p; } static void fill(int dp[]) { Arrays.fill(dp, -1); } static void fill(int dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(int dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(int dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static void fill(long dp[]) { Arrays.fill(dp, -1); } static void fill(long dp[][]) { for(int i=0;i<dp.length;i++) Arrays.fill(dp[i], -1); } static void fill(long dp[][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { Arrays.fill(dp[i][j],-1); } } } static void fill(long dp[][][][]) { for(int i=0;i<dp.length;i++) { for(int j=0;j<dp[0].length;j++) { for(int k=0;k<dp[0][0].length;k++) { Arrays.fill(dp[i][j][k],-1); } } } } static int min(int a,int b) { return Math.min(a, b); } static int min(int a,int b,int c) { return Math.min(a, Math.min(b, c)); } static int min(int a,int b,int c,int d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static int max(int a,int b) { return Math.max(a, b); } static int max(int a,int b,int c) { return Math.max(a, Math.max(b, c)); } static int max(int a,int b,int c,int d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long min(long a,long b) { return Math.min(a, b); } static long min(long a,long b,long c) { return Math.min(a, Math.min(b, c)); } static long min(long a,long b,long c,long d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static long max(long a,long b) { return Math.max(a, b); } static long max(long a,long b,long c) { return Math.max(a, Math.max(b, c)); } static long max(long a,long b,long c,long d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long power(long x, long y, long p) { if(y==0) return 1; if(x==0) return 0; long 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 long power(long x, long y) { if(y==0) return 1; if(x==0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } static void print(int A[]) { for(int i : A) { out.print(i+" "); } out.println(); } static void print(long A[]) { for(long i : A) { System.out.print(i+" "); } System.out.println(); } static long mod(long x) { return ((x%mod + mod)%mod); } static String reverse(String s) { StringBuffer p=new StringBuffer(s); p.reverse(); return p.toString(); } static int i() { return sc.nextInt(); } static String s() { return sc.next(); } static long l() { return sc.nextLong(); } static void sort(int[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } static String sort(String s) { Character ch[]=new Character[s.length()]; for(int i=0;i<s.length();i++) { ch[i]=s.charAt(i); } Arrays.sort(ch); StringBuffer st=new StringBuffer(""); for(int i=0;i<s.length();i++) { st.append(ch[i]); } return st.toString(); } static HashMap<Integer,Integer> hash(int A[]){ HashMap<Integer,Integer> map=new HashMap<Integer, Integer>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static HashMap<Long,Integer> hash(long A[]){ HashMap<Long,Integer> map=new HashMap<Long, Integer>(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap<Integer,Integer> tree(int A[]){ TreeMap<Integer,Integer> map=new TreeMap<Integer, Integer>(); for(int i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static TreeMap<Long,Integer> tree(long A[]){ TreeMap<Long,Integer> map=new TreeMap<Long, Integer>(); for(long i : A) { if(map.containsKey(i)) { map.put(i, map.get(i)+1); } else { map.put(i, 1); } } return map; } static boolean prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean prime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq=Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } 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\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
fc7d2b3b50927888661c6acc03e4ebd2
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.*; import java.util.*; public class A { static void solve(boolean ok) { if (ok) System.out.println("YES"); else System.out.println("NO"); } public static void main(String[] args) { FastScanner sc = new FastScanner(); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); String s1 = sc.next(); String s2 = sc.next(); boolean bool = true; for (int i = 0; i < n; i++) { if ((s1.charAt(i) == 'B' && s2.charAt(i) == 'G') || (s1.charAt(i) == 'G' && s2.charAt(i) == 'B') ) continue; if (s1.charAt(i) != s2.charAt(i)){ bool = false; break; } } if (bool) System.out.println("YES"); else System.out.println("NO"); } } static boolean IsPowerOfTwo(int x) { return (x & (x - 1)) == 0; } 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()); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
518ed7999c1d8e6d6c11f6989595a9d5
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class Colourblindness { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testCases = scanner.nextInt(); for(int i = 0; i < testCases; i++){ scanner.nextInt(); scanner.nextLine(); String one = scanner.nextLine().replaceAll("G", "B"); String two = scanner.nextLine().replaceAll("G", "B"); System.out.println(one.equals(two) ? "YES" : "NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
3164a7329fb1e222e922f01eca35c341
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
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 n = sc.nextInt(); sc.nextLine(); String row1 = sc.nextLine(); String row2 = sc.nextLine(); boolean same = true; for (int i=0; i<n; i++){ if ((row1.charAt(i) == 'R' || row2.charAt(i) == 'R') && (row1.charAt(i) == 'G' || row2.charAt(i) == 'G' || row1.charAt(i) == 'B' || row2.charAt(i) == 'B') ){ same = false; break; } } if (same){ System.out.println("YES"); } else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
8a81e8b80496b4c40e46a9ab75d141c2
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class codeforces { public static void main(String[] args) { Scanner ob=new Scanner(System.in); int t=ob.nextInt(); for(int o=0;o<t;o++) { int n=ob.nextInt(); ob.nextLine(); String s1=ob.nextLine(); String s2=ob.nextLine(); char c1[]=s1.toCharArray(); char c2[]=s2.toCharArray(); int e=0; for(int i=0;i<n;i++) { if((c1[i]==c2[i]) || (c1[i]=='B' && c2[i]=='G') || (c1[i]=='G' && c2[i]=='B')) { e++; } } if(e==n) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
d49877e9206f1fd0dbd571fb171517cd
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class CodeForces { public static void main(String[] args) { Scanner scan = new Scanner(System.in); List<Character> colors1 = new ArrayList<>(); List<Character> colors2 = new ArrayList<>(); int count = 0; int num1 = scan.nextInt(); for (int i = 0; i < num1; i++) { int num2 = scan.nextInt(); String color1 = scan.next(); String color2 = scan.next(); for (int k = 0; k < num2; k++) { char c1 = color1.charAt(k); char c2 = color2.charAt(k); colors1.add(c1); colors2.add(c2); } for (int j = 0; j < num2; j++) { char col1 = colors1.get(j), col2 = colors2.get(j); if(col1 == col2) count++; else if(col1 == 'G' && col2 == 'B') count++; else if(col1 == 'B' && col2 == 'G') count++; } if(count == num2) System.out.println("YES"); else System.out.println("NO"); colors1.clear(); colors2.clear(); count = 0; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
15f66afac7520c9940d0aa74c29b3aa7
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; public class B { public static void main(String[] args) throws IOException { FastReader in = new FastReader(System.in); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); int t = in.nextInt(); for (int tt = 0; tt < t; tt++) { int n = in.nextInt(); char[] ch1 = in.next().toCharArray(); char[] ch2 = in.next().toCharArray(); boolean x = false; for (int i = 0; i < n; i++) { if (ch1[i] == 'R' && ch2[i] != 'R') { x = true; break; } if (ch2[i] == 'R' && ch1[i] != 'R') { x = true; break; } } if (x) pw.println("NO"); else pw.println("YES"); } pw.close(); } public static void Sort(int[] a) { ArrayList<Integer> lst = new ArrayList<>(); for (int i : a) lst.add(i); Collections.sort(lst); for (int i = 0; i < lst.size(); i++) a[i] = lst.get(i); } static void debug(Object... obj) { System.err.println(Arrays.deepToString(obj)); } static class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; public FastReader(InputStream is) { this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int c = skip(); StringBuilder sb = new StringBuilder(); while (!isEndOfLine(c)) { sb.appendCodePoint(c); c = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public char readChar() { return (char) skip(); } public long[] readArrayL(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
69a873dc73bc56c29aba8bf0d6411bbe
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.*; public class Cf_0 { public static void main(String[] args) throws IOException { // Reader r= new Reader(); FastReader sc= new FastReader(System.in); int t= sc.nextInt(); for(int i=0;i<t;i++){ int n=sc.nextInt(); char[][]strs= new char[2][n]; for(int it=0;it<2;it++){ for (int j=0;j<n;j++){ strs[it][j]= sc.readChar(); } } solveA(strs); } } // public static void solveA(char[][]grid){ for(int i=0;i<grid[0].length;i++){ if(grid[0][i]=='G'){ grid[0][i]='B'; } } for(int i=0;i<grid[0].length;i++){ if(grid[1][i]=='G'){ grid[1][i]='B'; } } int flag=0; for(int i=0;i<grid[0].length;i++){ if(grid[0][i]!=grid[1][i]){ flag++; break; } } System.out.println(flag==0? "YES":"NO"); } public static void print(int []a){ for(int t:a){ if(t!=0) System.out.print(t+" "); } System.out.println(); } } 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') { if (cnt != 0) { break; } else { continue; } } 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(); } } class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; public FastReader(InputStream is) { this.is = is; } public int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int c = skip(); StringBuilder sb = new StringBuilder(); while (!isEndOfLine(c)) { sb.appendCodePoint(c); c = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = (num << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public char readChar() { return (char) skip(); } public long[] readArrayL(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } public int[] readArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
cba88d5de92a2c21e79e59080adf5cb6
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class ColourBlindness { public static void main(String arg[]) { Scanner scan=new Scanner(System.in); int t=scan.nextInt(); for(int i=0;i<t;i++) { int n=scan.nextInt(); String str=scan.next(); String str1=scan.next(); boolean flag=true; for(int j=0;j<n;j++) { if(str.charAt(j)=='R'&&str1.charAt(j)!='R') { System.out.println("NO"); flag=false; break; } else if(str1.charAt(j)=='R'&&str.charAt(j)!='R') { flag=false; System.out.println("NO"); break; } } if(flag) System.out.println("YES"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
15fc44d383e1ee699e268a02cf74e651
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.*; import java.util.*; import java.lang.System; import static java.lang.System.out; public class CodeForces { public static void main(String[] args) { FastReader fastReader = new FastReader(); int n = fastReader.nextInt(); while (n-->0) { int l = fastReader.nextInt(); String s = fastReader.nextToken(); String s2 = fastReader.nextToken(); int countRed = 0; int countRed2 = 0; for (int i = 0; i < l; i++) { if(s.charAt(i) == 'R') countRed++; if(s2.charAt(i) == 'R') countRed2++; if(s.charAt(i) == s2.charAt(i) && s.charAt(i) == 'R') { countRed--; countRed2--; } } if(countRed == 0 && countRed2 == 0) out.println("YES"); else out.println("NO"); } } static int factorial(int n){ if (n == 0) return 1; else return(n * factorial(n-1)); } static boolean isPowerOfTwo(int n) { return (int) (Math.ceil((Math.log(n) / Math.log(2)))) == (int) (Math.floor(((Math.log(n) / Math.log(2))))); } static int findGCD(int x, int y) { int r = 0, a, b; a = Math.max(x, y); // a is greater number b = Math.min(x, y); // b is smaller number r = b; while (a % b != 0) { r = a % b; a = b; b = r; } return r; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } String nextLine() { String str = ""; try { if (st.hasMoreTokens()) { str = st.nextToken("\n"); } else { str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
16ca637ce9bd0f6409bcd002f3804b57
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class Code { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); while (a-- > 0) { int n = sc.nextInt(); String s1 = sc.next(); String s2 = sc.next(); String str1 = s1.replace('G', 'T'); String str11 = str1.replace('B', 'T'); String str2 = s2.replace('G', 'T'); String str22 = str2.replace('B', 'T'); if (str11.equals(str22)) { System.out.println("YES"); } else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
b0c11134c3e97b5e4436a8b3a1016060
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
/* ...|/G\/E\/O\/R\/G\/E\|... */ //Advanced Java //BufferedWriter //BufferedReader import javax.swing.*; import java.math.BigInteger; import java.util.*; import java.io.*; public class Main{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.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()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("").append(String.valueOf(object)); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static <Charachter> void main(String[] args) { try { FastReader in = new FastReader(); FastWriter out = new FastWriter(); int n = in.nextInt(); while(n-->0) { int m = in.nextInt(); String s1 = in.next(); String s2 = in.next(); int c = 0; boolean a = true; for (int i = 0 ; i<s1.length() ; i++) { if ((s1.charAt(i)=='R' && s2.charAt(i)=='R') || (s1.charAt(i)=='G' && s2.charAt(i)=='B') || (s1.charAt(i)=='B' && s2.charAt(i)=='G') || (s1.charAt(i)=='G' && s2.charAt(i)=='G') || (s1.charAt(i)=='B' && s2.charAt(i)=='B')) c++; else { a=false; break; } } if (a && c==s1.length()) System.out.println("YES"); else System.out.println("NO"); } out.close(); } catch (Exception e) { return; } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
51c05ce3601773dc02ef6b4339b68c4f
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.io.*; public class Colorblindness { public static void main(String[] args) { try { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); int testcases = in.nextInt(); while (testcases-- > 0) { int n = in.nextInt(); char[][] a=new char[2][n]; for(int i=0;i<2;i++) { a[i]=in.nextLine().toCharArray(); for(int j=0;j<n;j++) { if(a[i][j]=='G') a[i][j]='B'; } } boolean istrue=true; for(int i=0;i<n;i++) { if(a[0][i]!=a[1][i]) istrue=false; } if(istrue) out.println("Yes"); else out.println("No"); } out.close(); } catch (Exception e) { // TODO: handle exception return; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null; static void dbg(Object... o) { if (LOCAL) System.err.println(Arrays.deepToString(o)); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
1f206530fb88dc35582b3c137f049bce
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class R817B { public static void main(String[] args) throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(in.readLine()); while(n-- > 0){ int l=Integer.parseInt(in.readLine()); String s1=in.readLine(); String s2=in.readLine(); s1=s1.replace("G", "B"); s2=s2.replace("G", "B"); if(s1.equals(s2)){ System.out.println("YES"); }else{ System.out.println("NO"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
787907e93d9441068d25fb62ce070b38
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int t = sc.nextInt(); char[] target = "Timur".toCharArray(); Arrays.sort(target); while (t-- > 0) { sc.nextInt(); String s1 = sc.next(); String s2 = sc.next(); s1 = s1.replace("G", "B"); s2 = s2.replace("G", "B"); if (s1.equals(s2)) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
f35c6a08746a5c20b6820a48a1bd1b79
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; import java.util.stream.Stream; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int test_cases = sc.nextInt(); for(int test_case=0;test_case<test_cases;test_case++){ int n = sc.nextInt(); String s1 = sc.next(); String s2 = sc.next(); boolean invalid = false; for(int i=0;i<n;i++){ char ch1 = s1.charAt(i); char ch2 = s2.charAt(i); if(ch1!=ch2){ if((ch1=='G' && ch2=='B') || (ch1=='B' && ch2=='G')){ continue; }else{ invalid = true; } } } if(invalid){ System.out.println("NO"); }else{ System.out.println("YES"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
c9c445b74d2c468150430abf89f32c75
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; public class Application { public static void main(String[] somethingstrangewithme) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); for ( int i = 0; i < n; i ++ ) { int m = scan.nextInt(); String name1 = scan.next(); String name2 = scan.next(); String text1 = name1.replace('B', 'G');; String text2 = name2.replace('B', 'G');; if ( text1.contains(text2) && text2.contains(text1) ) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
51556a9ae5eaf514055f9f6cb5bf67e6
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class solution { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); sc.nextLine(); String s = sc.nextLine(); String k = sc.nextLine(); String y = k.replace('B', 'G'); String z = s.replace('B', 'G'); int m = y.compareTo(z); //System.out.println(m); if (m == 0) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
93646dca9a47a271aa183473cabfb91d
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
/* * * * * * * * * * * P A U L A * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ import javax.swing.*; import java.awt.*; import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Double.*; import static java.lang.Float.*; public class Main { static final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); static final InputStream inputStream = System.in; static final FastReader in = new FastReader(inputStream); public static void main(String[] args) throws IOException { int numOfTestCase = 1;//in.nextInt() ; while (numOfTestCase-- > 0) Task.solve(in, out); finish(); } static class Task { public static void solve(FastReader input, BufferedWriter out) throws IOException { /* ---------------------------------------------------------------------------------------------------------- كود بيتاكد ان كل الحروف الابجدية موجودة ف الاسترنج distinct() ميثود بتحذف تكرار الحروف يعني مثلا aabbcc هتكون abc int n=input.nextInt(); System.out.println(input.next().toLowerCase().chars().distinct().count()>=26?"YES":"NO"); ---------------------------------------------------------------------------------------------------------- >>>>>>>>> soooooort String <<<<<<<<<<<< String s = in.next(); //cba char[] Arr = s.toCharArray(); Arrays.sort(Arr); String x = new String(Arr); System.out.println(x); ---------------------------------------------------------------------------------------------------------- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>MMMMMMAAAAAAAAPPPPPPPP<<<<<<<<<<<<<<<<<<<<<<< int n = in.nextInt(); HashMap<String,Integer> mp = new HashMap<>(); for (int i = 1 ; i<=n ; i++) { String s = in.next(); if (!mp.containsKey(s)) { mp.put(s,0); System.out.println("OK"); } else { mp.put(s,mp.get(s)+1); System.out.println(s+mp.get(s)); } } ---------------------------------------------------------------------------------------------------------- >>>>>>>>>>>>>>>مودلس للاسترنج>>>>>>>>>>>>>>>>> String s= input.next(); BigInteger b =new BigInteger(s); if (b.mod(new BigInteger("9")).equals(new BigInteger("0"))) System.out.println("YES"); else System.out.println("NO"); ********************************************** String s= input.next(); int i=0; for (int j = 0; j <s.length() ; j++) { i=(i+(s.charAt(s.length()-1-j) -'0')%9) % 9; } System.out.println(i==0?"YES" : "NO"); ------------------------------------------------------------------------------------------------------------ <<<<<<<<<<<<<<<<<<<< PREFEX SUM<<<<<<<<<<<<<<<<<<<<<<< int size=input.nextInt(); int range=input.nextInt(); long arr[]=new long [size]; for (int i = 0; i <size ; i++) { arr[i]=input.nextInt(); if (i==0) continue; arr[i]+=arr[i-1]; } for (int i = 0; i <range ; i++) { int ind1=input.nextInt(); int ind2=input.nextInt(); System.out.print(ind1 -1 ==0?arr[--ind2] +"\n" : arr[--ind2] - arr[ind1-2]+"\n"); } ----------------------------------------------------------------------------------------------------------------- GCD قانون BigInteger b1=BigInteger.valueOf(input.nextInt()); BigInteger b2=BigInteger.valueOf(input.nextInt()); BigInteger b3=b1.gcd(b2); System.out.println(b3); ------------------------------------------------------------------------------------------------------------------- قانونLCM BigInteger b1=BigInteger.valueOf(input.nextInt()); BigInteger b2=BigInteger.valueOf(input.nextInt()); BigInteger b3=b1.gcd(b2); System.out.println((b1.multiply(b2)) .divide(b3)); -------------------------------------------------------------------------------------------------------------------- */ //---------------------------------------------------------------------------------------------------------// int t = in.nextInt(); while (t-->0){ in.nextInt(); String s1 = in.next();//GRBG==>BRBG String s2 = in.next();//GBGB==>BBBB s1 = s1.replace('G', 'B'); s2 = s2.replace('G', 'B'); System.out.println(s1.equals(s2)?"YES":"NO"); } // -----------------------------------------------------------------------------------------------------------/ } } static int[] readArray1d(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = in.nextInt(); return a; } static int[][] readArray2d(int row, int col) throws IOException { int[][] a = new int[row][col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { a[i][j] = in.nextInt(); } } return a; } static long[][] readArray2d(long row, long col) throws IOException { long[][] a = new long[(int) row][(int) col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { a[i][j] = in.nextLong(); } } return a; } private static void printArray(int[] numbers) throws IOException { for (int number : numbers) { out.write(number + " "); } } private static void printArray(long[] numbers) throws IOException { for (long number : numbers) { out.write(number + " "); } } static class FastReader { private static byte[] buf = new byte[1024]; private static int index; private static InputStream in; private static int total; public FastReader(InputStream in) { FastReader.in = in; } public static int scan() throws IOException { if (total < 0) throw new InputMismatchException(); if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } public int nextInt() throws IOException { int integer = 0; int n = scan(); while (isWhiteSpace(n)) n = scan(); int neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { integer *= 10; integer += n - '0'; n = scan(); } else { throw new InputMismatchException(); } } return neg * integer; } public double nextDouble() throws IOException { return parseDouble(next()); } public double nextFloat() throws IOException { return parseFloat(next()); } public long nextLong() throws IOException { long integer = 0; long n = scan(); while (isWhiteSpace(n)) n = scan(); long neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { integer *= 10; integer += n - '0'; n = scan(); } else { throw new InputMismatchException(); } } return neg * integer; } public String next() throws IOException { StringBuilder sb = new StringBuilder(); int n = scan(); while (isWhiteSpace(n)) n = scan(); while (!isWhiteSpace(n)) { sb.append((char) n); n = scan(); } return sb.toString(); } public String nextLine() throws IOException { StringBuilder sb = new StringBuilder(); int n = scan(); while (isWhiteSpace(n)) n = scan(); while (!newLine(n)) { sb.append((char) n); n = scan(); } return sb.toString(); } private static boolean isWhiteSpace(long n) { return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1; } private boolean newLine(long n) { return n == '\n' || n == -1; } } static void finish () throws IOException { out.flush(); out.close(); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
8d59efbfbe81f1d819be578fe3445fc7
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); static int n; static String s1, s2; public static void main(String[] args) { int _t = sc.nextInt(); while (_t -- > 0){ n = sc.nextInt(); s1 = sc.next(); s2 = sc.next(); char[] a1 = s1.toCharArray(); char[] a2 = s2.toCharArray(); for (int i = 0; i < a1.length; i++) { if (a1[i] == 'G') a1[i] = 'B'; if (a2[i] == 'G') a2[i] = 'B'; } int flg = 1; for (int i = 0; i < a1.length; i++) { if (a1[i] != a2[i]) flg = 0; } if (flg == 1) System.out.println("YES"); else System.out.println("NO"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
2b522ca0f33bf6429564cab4c2f7be08
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.Scanner; /** * * @author HP */ public class bluegreen { public static void main(String[] args) { Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int l=in.nextInt(); String a=in.next(); String b=in.next(); int r=0; int g=0; int e=0; for (int i = 0; i < l; i++) { if(a.charAt(i)=='R'&&(b.charAt(i)=='G'||b.charAt(i)=='B')){ r++; }else if(b.charAt(i)=='R'&&(a.charAt(i)=='G'||a.charAt(i)=='B')) r++;} if(r>0){ System.out.println("NO"); }else{ System.out.println("YES"); } } }}
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
5c8590d0811f3ba9e9db2d762870d544
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
//package colourblindness; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); public Main () { int t = sc.nextInt(); sc.nextLine(); for(int i=0; i<t; i++) { int n = sc.nextInt(); sc.nextLine(); String s1 = sc.nextLine(); String s2 = sc.nextLine(); boolean isSame = true; for(int j=0; j<s1.length(); j++) { if((s1.charAt(j) == 'R' || s2.charAt(j) == 'R') && s1.charAt(j) != s2.charAt(j)) { isSame = false; break; } } if(isSame) System.out.println("YES"); else System.out.println("NO"); } } public static void main(String[] args) { new Main(); } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
51a9a28e1206c12f5918207735de4c9b
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
// package com.company; import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.stream.IntStream; import java.math.*; public class Scanner { static boolean[] x; StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } /*public static void luckyNumbers(int a, int b, ArrayList x) { if(a>Math.pow(10,9) || b>Math.pow(10,9)) return; x.add(a); x.add(b); luckyNumbers((a*10)+4,(b*10)+4,x); luckyNumbers((a*10)+7,(b*10)+7,x); } */ public static void prefixSum(long[] cost, long[] prefixSum) { // prefix Sum for the cost Array prefixSum[0] = cost[0]; for(int i=1;i<cost.length;i++) prefixSum[i] = prefixSum[i-1] + cost[i]; } public static void prefixSumSorted(Integer[] costSorted, long[] prefixSum) { // prefix Sum for the sorted cost Array prefixSum[0] = costSorted[0]; for(int i=1;i<costSorted.length;i++) prefixSum[i] = prefixSum[i-1] + costSorted[i]; } /* public static boolean isOperator(char c) { return c == '^' || c == '/' || c == '*' || c == '+' || c == '-'; } public static int getPrecedence(char c) { case '+', '-' -> 1; case '*', '/' -> 3; default -> 5; }; } */ public static boolean isPrime (int a) { for(int i=2;i<a;i++) { if(a%i == 0) return false; } return true; } /*public static int getP(int y) { int p = 0; for(int i=2;i<=y;i++) { if(y%i == 0 && x.contains(y)) p++; } return p; } */ public static void luckyNumbers(long a, ArrayList x) { if(a>Math.pow(10,15)) return; if(a!=0) x.add(a); luckyNumbers(a*10+4,x); luckyNumbers(a*10+7,x); } // CODE STARTS HERE public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int c=0;c<t;c++) { int n = sc.nextInt(); char[][] grid = new char[2][n]; boolean blind = false; for(int i=0;i<2;i++){ String s = sc.nextLine(); for(int j=0;j<n;j++) { grid[i][j] = s.charAt(j); } } for(int j=0;j<n;j++) { if((grid[0][j] == grid[1][j]) || ((grid[0][j] == 'G' || grid[0][j] == 'B') && (grid[1][j] == 'G' || grid[1][j] == 'B'))) continue; else { blind = true; break; } } if(blind) System.out.println("NO"); else System.out.println("YES"); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
dd3ea878d238b5884bfc7a1468a065b9
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.*; import java.util.*; public class Main { // public static void den(int []arr,int i) { // for (int j = 0; j < arr.length-1; j++) { // if(j==arr.length-i) { // break; // } // int temp=0; // temp=arr[j]; // arr[j]=arr[j+1]; // arr[j+1]=temp; // } // } public static double aver(int[]arr) { int sum=0; for (int i = 0; i < arr.length; i++) { sum=sum+arr[i]; } return sum/arr.length; } public static int fac(int x) { int sum=1; while(x>0) { sum=sum*x; x=x-1; } return sum; } public static int comb(int x,int y) { int sum=0; sum=fac(x); int temp=(fac(y)*fac(x-y)); return sum/temp; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); while(n>0) { sc.nextInt(); sc.nextLine(); String []f=sc.nextLine().split(""); // System.out.println(f[0]); String []s=sc.nextLine().split(""); // System.out.println(s[0]); boolean flag=true; for (int i = 0; i < f.length; i++) { if(f[i].equals("R")) { if(s[i].equals("B")||s[i].equals("G"))flag=false; } if(s[i].equals("R")) { if(f[i].equals("B")||f[i].equals("G"))flag=false; } } if(flag)System.out.println("YES"); else System.out.println("NO"); n=n-1; } }}
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
6bed6d73a9b849716d0d97882ba1b7e5
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.util.*; public class CodeforcesColourblind { public static void main(String[] args){ Scanner sc= new Scanner(System.in); int n = sc.nextInt(); for(int i=0;i<n;i++){ int col= sc.nextInt(); String first = sc.next(); String second = sc.next(); int flag =0; for(int j=0;j<col;j++){ char ch1 = first.charAt(j); char ch2 = second.charAt(j); if(ch1=='R'){ if(!(ch2 == 'R')){ flag++; System.out.println("NO"); break; } }else{ if(ch2 == 'R'){ flag++; System.out.println("NO"); break; } } } if(flag==0){ System.out.println("yes"); } } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
f5f7c5f3c49bb16a08f92ede09716d6b
train_109.jsonl
1661871000
Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.
256 megabytes
import java.io.BufferedReader; import java.io.OutputStreamWriter; import java.util.Arrays; import java.io.BufferedWriter; import java.io.IOException; import java.io.Flushable; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Submit { public static void main(String... strings) throws IOException { // rgb -> r count must be equal // rgb -> r positions must be equal try (InputReader reader = new InputReader(); OutputWriter writer = new OutputWriter(true)) { int t = reader.nextInt(); int i; // unused while (t-- > 0) { i = reader.nextInt(); if (haveEqualPositionsForRed( reader.nextLine().toCharArray(), reader.nextLine().toCharArray())) { writer.println("YES"); } else { writer.println("NO"); } } } } private static boolean haveEqualPositionsForRed(char[] left, char[] right) { for (int i = 0; i < left.length; i++) { if (left[i] != 'R' && right[i] != 'R') { continue; } else if (left[i] == 'R' && right[i] == 'R') { continue; } else { return false; } } return true; } } 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(); } } } class OutputWriter implements AutoCloseable, Flushable { private final BufferedWriter writer; private boolean autoFlush; public OutputWriter() { this.writer = new BufferedWriter(new OutputStreamWriter(System.out)); } public OutputWriter(boolean autoFlush) { this(); this.autoFlush = autoFlush; } public void printWithSpace(int input) { try { writer.append(input + " "); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void print(int input) { try { writer.append(input + ""); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void println(int input) { try { writer.append(input + System.lineSeparator()); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void printWithSpace(String input) { try { writer.append(input + " "); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void print(String input) { try { writer.append(input); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void println(CharSequence input) { try { writer.append(input); writer.append(System.lineSeparator()); } catch (IOException e) { e.printStackTrace(); } if (autoFlush) { flush(); } } public void printArray() { // implement if (autoFlush) { flush(); } } @Override public void flush() { try { this.writer.flush(); } catch (IOException e) { e.printStackTrace(); } } @Override public void close() { try { writer.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
Java
["6\n\n2\n\nRG\n\nRB\n\n4\n\nGRBG\n\nGBGB\n\n5\n\nGGGGG\n\nBBBBB\n\n7\n\nBBBBBBB\n\nRRRRRRR\n\n8\n\nRGBRRGBR\n\nRGGRRBGR\n\n1\n\nG\n\nG"]
1 second
["YES\nNO\nYES\nNO\nYES\nYES"]
NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.
Java 8
standard input
[ "implementation" ]
86a2e0854f9faf0b119d0d5e4b8fe952
The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.
800
For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).
standard output
PASSED
a8ef423ea307c1ac6c01d507b4504ad2
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.sql.Time; import java.text.SimpleDateFormat; import java.util.*; public class Cf { static Scanner scanner = new Scanner(System.in); public static void main(String... args) { int t = scanner.nextInt(); int n, q; int h, w; long[][] field = new long[1001][1001]; for (int i = 0; i < t; i++) { n = scanner.nextInt(); q = scanner.nextInt(); for (int j = 0; j < n; j++) { h = scanner.nextInt(); w = scanner.nextInt(); field[h][w] += (long) h * w; } for (int a = 1; a <= 1000; a++) { for (int b = 1; b <= 1000; b++) { field[a][b] += field[a - 1][b] + field[a][b - 1] - field[a - 1][b - 1]; } } int hSmall, wSmall, hBig, wBig; for (int j = 0; j < q; j++) { hSmall = scanner.nextInt(); wSmall = scanner.nextInt(); hBig = scanner.nextInt(); wBig = scanner.nextInt(); long res = field[hBig - 1][wBig - 1] - field[hBig - 1][wSmall] - field[hSmall][wBig - 1] + field[hSmall][wSmall]; System.out.println(res); } for (long[] row : field) { Arrays.fill(row, 0); } } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
b7de0ec92c73c8f18f3703205b4bc736
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.util.*; public class Test1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); while(tc-->0) { int n = sc.nextInt(), q = sc.nextInt(); long[][] pre = new long[1001][1001]; for(int i=0;i<n;i++) { int h = sc.nextInt(), w = sc.nextInt(); pre[h][w] += h * w; } for(int i=1;i<=1000;i++) { for(int j=1;j<=1000;j++) { pre[i][j] += pre[i-1][j] + pre[i][j-1] - pre[i-1][j-1]; } } StringBuilder sb = new StringBuilder(); while(q-->0) { int hs = sc.nextInt(), ws = sc.nextInt(); int hb = sc.nextInt(), wb = sc.nextInt(); int h = hb-1, w = wb-1; long res = pre[h][w] - (pre[hs][w] + pre[h][ws] - pre[hs][ws]); sb.append(res).append("\n"); } sb.setLength(sb.length()-1); System.out.println(sb.toString()); } // #################### } // #################### }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
07d2d8db78922abaac6b61c8b22f5e5e
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); while (T-- > 0) { int n=in.nextInt(); int q=in.nextInt(); long arr[][]=new long[1001][1001]; for(int i=0;i<n;i++) { int h=in.nextInt(); int w=in.nextInt(); arr[h][w]+=h*w; } long pre[][]=new long[1001][1001]; long sum1=0,sum2=0; for(int i=1;i<=1000;i++) { sum1+=arr[1][i]; sum2+=arr[i][1]; pre[1][i]=sum1; pre[i][1]=sum2; } for(int i=2;i<=1000;i++) { for(int j=2;j<=1000;j++) { pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+arr[i][j]; } } for(int i=0;i<q;i++) { int hs=in.nextInt()+1; int ws=in.nextInt()+1; int hb=in.nextInt()-1; int wb=in.nextInt()-1; System.out.println((long)pre[hb][wb]-(long)pre[hb][ws-1]-(long)pre[hs-1][wb]+(long)pre[hs-1][ws-1]); } } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
bcf416f83160e99f190967e85e8be7e4
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class Task1722E { public static void main(String[] args) { Scanner sc = new Scanner(System.in); ArrayList<Long> answers = new ArrayList<Long>(); int t = sc.nextInt(); for (int t1 = 0; t1 < t; t1++) { long[][] rectangle = new long[1001][1001]; long[][] pref = new long[1001][1001]; int n = sc.nextInt(), q = sc.nextInt(); for (int i = 0; i < n; i++) { int h = sc.nextInt(), w = sc.nextInt(); rectangle[h][w] += h * w; } for (int i = 1; i < 1001; i++) { for (int j = 1; j < 1001; j++) { pref[i][j] = rectangle[i][j] + pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]; } } for (int i = 0; i < q; i++) { int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt(); answers.add(pref[c - 1][d - 1] - pref[c - 1][b] - pref[a][d - 1] + pref[a][b]); } } for(long ans : answers) System.out.println(ans); } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
a56fd630018004cdf457c4bcac15d6f9
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class CountingRectanglesSubmit { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numTestCase = sc.nextInt(); for (int i = 0; i < numTestCase; i++) { int n = sc.nextInt(); int q = sc.nextInt(); long prefix[][] = new long[1001][1001]; for (int j = 0; j <= 1000; j++) { for (int k = 0; k <= 1000; k++) { prefix[j][k] = 0; } } for (int j = 0; j < n; j++) { int h = sc.nextInt(); int w = sc.nextInt(); prefix[h][w] = prefix[h][w] + h * w; } for (int j = 1; j <= 1000; j++) { for (int k = 2; k <= 1000; k++) { prefix[j][k] = prefix[j][k - 1] + prefix[j][k]; } } for (int j = 1; j <= 1000; j++) { for (int k = 2; k <= 1000; k++) { prefix[k][j] = prefix[k - 1][j] + prefix[k][j]; } } for (int j = 0; j < q; j++) { int hs = sc.nextInt(); int ws = sc.nextInt(); int hb = sc.nextInt(); int wb = sc.nextInt(); long ans = prefix[hb - 1][wb - 1] - prefix[hs][wb - 1] - prefix[hb - 1][ws] + prefix[hs][ws]; System.out.println(ans); } } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
8158c6e0103510d1ae4d5b10fa10ab06
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintStream; import java.lang.reflect.Array; import java.util.*; import java.util.function.IntFunction; import java.util.function.IntUnaryOperator; import java.util.function.ToIntFunction; import java.util.stream.IntStream; import java.util.stream.Stream; public class Codeforces { static void solve() { int t = i32(); while (t-- > 0) { int n = i32(), q = i32(), k = 1_000; long[][] mat = new long[k + 1][k + 1]; for (int i = 0; i < n; i++) { int w = i32(), h = i32(); mat[w][h] += (long) w * h; } for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { mat[i][j] += mat[i][j-1]; } } for (int j = 1; j <= k; j++) { for (int i = 1; i <= k; i++) { mat[i][j] += mat[i-1][j]; } } for (int l = 0; l < q; l++) { int ws = i32(), hs = i32(), wl = i32(), hl = i32(); print(mat[wl-1][hl-1] - mat[ws][hl-1] - mat[wl-1][hs] + mat[ws][hs]); } } } //#################################################################################################################### private static final Scanner _IN_ = new Scanner(new BufferedReader(new InputStreamReader(System.in))); private static final PrintStream _OUT_ = new PrintStream(new BufferedOutputStream(System.out)); public static void main(String[] args) { try (_IN_; _OUT_) { solve(); } catch (Exception e) { print(e.getMessage()); throw e; } } // ARRAY ############################################################################################################# private static <T> T[] array(int n, Class<T> type, IntFunction<T> fun) { @SuppressWarnings("unchecked") T[] array = (T[]) Array.newInstance(type, n); for (int i = 0; i < n; i++) array[i] = fun.apply(i); return array; } private static int[] array(int n, int d) { int[] array = new int[n]; Arrays.fill(array, d); return array; } private static int fst(int[] arr) { return arr[0]; } private static int last(int[] arr) { return arr[arr.length - 1]; } private static void swap(int[] arr, int i, int j) { int x = arr[i]; arr[i] = arr[j]; arr[j] = x; } private static void shuffle(int[] arr) { for (int i = 0; i < arr.length; i++) swap(arr, (int) (Math.random() * arr.length), i); } private static Stream<pair> pairs(int[] as) { int n = as.length; if (n < 2) return Stream.empty(); return Stream.iterate(new pair(0, 1), it -> it.fst < n - 1, it -> it.snd + 1 == n ? new pair(it.fst + 1, it.fst + 2) : new pair(it.fst, it.snd + 1)); } private static Stream<pair> cartesian(int m, int n) { return Stream.iterate(new pair(0, 0), it -> it.fst < m, it -> it.snd + 1 == n ? new pair(it.fst + 1, 0) : new pair(it.fst, it.snd + 1)); } // DS ################################################################################################################ private static class pair { final int fst, snd; pair(int fst, int snd) { this.fst = fst; this.snd = snd; } public String toString() { return fst + " " + snd; } boolean neq(pair p) { return fst != p.fst || snd != p.snd; } } private static class triple { final int fst, snd, thd; triple(int fst, int snd, int thd) { this.fst = fst; this.snd = snd; this.thd = thd; } public String toString() { return fst + " " + snd + " " + thd; } } // GEOMETRY ########################################################################################################## private static double dist(int x1, int y1, int x2, int y2) { return Math.sqrt(Math.pow(x1-x2, 2) + Math.pow(y1-y2, 2)); } // INPUT ############################################################################################################# private static int i32() { return _IN_.nextInt(); } private static int[] i32(int n) { return IntStream.generate(Codeforces::i32).limit(n).toArray(); } private static String str() { return _IN_.next(); } private static String[] str(int n) { return Stream.generate(Codeforces::str).limit(n).toArray(String[]::new); } // ITERATION ######################################################################################################### private static IntStream iter(int[] arr) { return Arrays.stream(arr); } private static IntStream iter(int l, int r) { return IntStream.range(l, r); } private static IntStream iter(int l, IntUnaryOperator next) { return IntStream.iterate(l, next); } private static class Window<T> { T[] arr; int i, sz; Window(T[] arr, int sz) { this.arr = arr; this.sz = sz; } T get(int j) { return arr[i + j]; } T fst() { return arr[i]; } T snd() { return arr[i + 1]; } boolean hasNext() { return i + sz <= arr.length; } public Window<T> next() { i++; return this; } } private static class IntWindow { int[] arr; int i, sz; IntWindow(int[] arr, int sz) { this.arr = arr; this.sz = sz; } int get(int j) { return arr[i + j]; } int fst() { return arr[i]; } int snd() { return arr[i + 1]; } boolean hasNext() { return i + sz <= arr.length; } public IntWindow next() { i++; return this; } } private static <T> Stream<Window<T>> windows(T[] arr, int sz) { if (sz > arr.length) return Stream.empty(); return Stream.iterate(new Window<>(arr, sz), Window::hasNext, Window::next); } private static Stream<IntWindow> windows(int[] arr, int sz) { if (sz > arr.length) return Stream.empty(); return Stream.iterate(new IntWindow(arr, sz), IntWindow::hasNext, IntWindow::next); } // NUMBER ############################################################################################################ private static final int INF = Integer.MAX_VALUE; private static int sum(int[] xs) { return iter(xs).sum(); } private static int sum(int[] xs, int l) { return Arrays.stream(xs).skip(l).sum(); } private static int min(int a, int b) { return Math.min(a, b); } private static int abs(int x) { return Math.abs(x); } // OUTPUT ############################################################################################################ private static void print(Object o) { _OUT_.println(o); } private static void print(int[] xs) { for (int x : xs) _OUT_.print(x + " "); _OUT_.println(); } private static void print(long[] xs) { for (long x : xs) _OUT_.print(x + " "); _OUT_.println(); } // SORT ############################################################################################################## private static <T> void sort(T[] arr, ToIntFunction<T> comp) { Arrays.sort(arr, Comparator.comparingInt(comp)); } private static void sort(int[] arr) { shuffle(arr); Arrays.sort(arr); } // STRING ############################################################################################################ private static class Str { final String s; final int l, r; Str(String s, int l, int r) { this.s = s; this.l = l; this.r = r; } int len() { return r - l; } boolean eq(Str that) { if (that.len() != this.len()) return false; for (int i = 0, len = len(); i < len; i++) if (s.charAt(l + i) != that.s.charAt(that.l + i)) return false; return true; } } private static String reverse(String s) { return new StringBuilder(s).reverse().toString(); } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
84437344f583ce6504fdd05c85342d57
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.BufferedInputStream; import java.util.Scanner; public class E { // 先入为主挺可怕的 // 根据数据的范围, 可以使用前缀和 static class Solution { public long[] solve(int hm, int hw, int[][] rec, int[][] qs) { long[][] boards = new long[hm + 1][hw + 1]; long[][] presum = new long[hm + 2][hw + 2]; for (int[] r: rec) { boards[r[0]][r[1]] += r[0] * r[1]; } for (int i = 1; i <= hm; i++) { for (int j = 1; j <= hw; j++) { presum[i + 1][j + 1] = presum[i + 1][j] + presum[i][j + 1] - presum[i][j] + boards[i][j]; } } long[] res = new long[qs.length]; for (int i = 0; i < qs.length; i++) { int y2 = qs[i][2], x2 = qs[i][3]; int y1 = qs[i][0], x1 = qs[i][1]; y2 = Math.min(y2, hm + 1); y1 = Math.min(y1, hm + 1); x2 = Math.min(x2, hw + 1); x1 = Math.min(x1, hw + 1); if (y2 >= y1 + 2 && x2 >= x1 + 2) { res[i] = presum[y2][x2] - presum[y2][x1 + 1] - presum[y1 + 1][x2] + presum[y1 + 1][x1 + 1]; } } return res; } } public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); int kase = sc.nextInt(); while (kase-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); int hm = 0, hw = 0; int[][] rec = new int[n][2]; for (int i = 0; i < n; i++) { rec[i][0] = sc.nextInt(); rec[i][1] = sc.nextInt(); hm = Math.max(hm, rec[i][0]); hw = Math.max(hw, rec[i][1]); } int[][] qs = new int[q][4]; for (int i = 0; i < q; i++) { qs[i][0] = sc.nextInt(); qs[i][1] = sc.nextInt(); qs[i][2] = sc.nextInt(); qs[i][3] = sc.nextInt(); } Solution solution = new Solution(); long[] res = solution.solve(hm, hw, rec, qs); for (int i = 0; i < res.length; i++) { System.out.println(res[i]); } } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
73c311aab3c26e2db4aa03b7f22d83a7
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.*; import java.util.*; public class CF1722E { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out)); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); int maxn = 1005; int []h = new int[n]; int []w = new int[n]; long [][]sum = new long[maxn][maxn]; long [][]a = new long[maxn][maxn]; for (int i = 0; i < n; i++) { h[i] = sc.nextInt(); w[i] = sc.nextInt(); a[h[i]][w[i]] += h[i] * w[i]; } for (int i = 1; i < maxn; i++) { for (int j = 1; j < maxn; j++) { sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + a[i][j]; } } while (q-- > 0) { int hs = sc.nextInt(); int ws = sc.nextInt(); int hb = sc.nextInt(); int wb = sc.nextInt(); long ans = sum[hb - 1][wb - 1] - sum[hb - 1][ws] - sum[hs][wb - 1] + sum[hs][ws]; pr.println(ans); } pr.flush(); } sc.close(); } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
515c1819ca6516324c7aaa283c42f497
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.PrintWriter; public class File { public static void main(String args[]) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int testcases = fs.nextInt(); while(testcases-- > 0) { final int nmm = 1005; long[][] pre = new long[nmm][nmm]; int n = fs.nextInt(); int q = fs.nextInt(); for(int i=0;i<n;i++) { int h = fs.nextInt(); int w = fs.nextInt(); pre[h][w] += h*w; } for(int i=1;i<nmm;i++) { for(int j=1;j<nmm;j++) { pre[i][j] += pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]; } } while(q-- > 0) { int hs = fs.nextInt(),ws = fs.nextInt(); int hb = fs.nextInt(),wb = fs.nextInt(); hb--; wb--; long ans = pre[hb][wb]-pre[hs][wb]-pre[hb][ws]+pre[hs][ws]; out.println(ans); } } out.close(); } 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()); } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
2701cb300ca5821cd5a3fd74e133c2c1
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class File { public static void main(String args[]) { FastScanner fs = new FastScanner(); int testcases = fs.nextInt(); while(testcases-- > 0) { final int nmm = 1005; long[][] pre = new long[nmm][nmm]; int n = fs.nextInt(); int q = fs.nextInt(); for(int i=0;i<n;i++) { int h = fs.nextInt(); int w = fs.nextInt(); pre[h][w] += h*w; } for(int i=1;i<nmm;i++) { for(int j=1;j<nmm;j++) { pre[i][j] += pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]; } } while(q-- > 0) { int hs = fs.nextInt(),ws = fs.nextInt(); int hb = fs.nextInt(),wb = fs.nextInt(); hb--; wb--; long ans = pre[hb][wb]-pre[hs][wb]-pre[hb][ws]+pre[hs][ws]; System.out.println(ans); } } } 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()); } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
2c274a8d2d00e00f6c045d42fdfe455e
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class E { private static Scan sc = new Scan(); public static void main(String[] args) { int n = sc.nextInt(); for (int i = 0; i < n; i++) { solve(); } } private static void solve() { int n = sc.nextInt(); int q = sc.nextInt(); long[][] a = new long[1001][1001]; for (int i = 0; i < n; i++) { int h = sc.nextInt(); int w = sc.nextInt(); a[h][w] += h * w; } for (int i = 1; i < 1001; i++) { for (int j = 1; j < 1001; j++) { a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1]; } } for (int i = 0; i < q; i++) { int b = sc.nextInt(); int c = sc.nextInt(); int d = sc.nextInt(); int e = sc.nextInt(); System.out.println(a[d - 1][e - 1] - a[d - 1][c] - a[b][e - 1] + a[b][c]); } } private static class Scan { BufferedReader br; StringTokenizer st; public Scan() { 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()); } String nextLine() { String line = ""; try { line = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return line; } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
0d8fcc7515451cb8eb13444e4cece547
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.util.*; public class CountingRectangles { public static void main(String[] args){ Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-- > 0){ int n = s.nextInt(); int q = s.nextInt(); long[][] matr = new long[1001][1001]; for(int i = 0; i < n; i++){ int h = s.nextInt(); int w = s.nextInt(); matr[h][w] += h*w; } long[][] dp = dpify(matr); for(int i = 0; i < q; i++){ int hs = s.nextInt(); int ws = s.nextInt(); int hb = s.nextInt(); int wb = s.nextInt(); long ans = (dp[hb-1][wb-1] - dp[hs][wb-1] - dp[hb-1][ws] + dp[hs][ws]); System.out.println(ans); } } } public static long[][] dpify(long[][] matr){ long[][] result = new long[1001][1001]; for(int i = 0; i < 1001; i++){ result[i][0] = 0; result[0][i] = 0; } for(int i = 1; i < 1001; i++){ for(int j = 1; j < 1001; j++){ result[i][j] = matr[i][j] + result[i-1][j] + result[i][j-1] - result[i-1][j-1]; } } return result; } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
40760eedf3361227b2d5bc837ff569eb
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
// package com.algorithms; import java.util.*; public class Pset11 { static long[][] mat; static long[][] prefix; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int q = sc.nextInt(); int[][] rect = new int[n][2]; for (int i = 0; i < n; i++) { rect[i][0] = sc.nextInt(); rect[i][1] = sc.nextInt(); } int[][] queries = new int[q][4]; for (int i = 0; i < q; i++) { queries[i][0] = sc.nextInt(); queries[i][1] = sc.nextInt(); queries[i][2] = sc.nextInt(); queries[i][3] = sc.nextInt(); } mat = new long[1001][1001]; prefix = new long[1001][1001]; for (int i = 0; i < n; i++) { int h = rect[i][0]; int w = rect[i][1]; mat[h][w] += h * w; } for (int i = 1; i <= 1000; i++) { for (int j = 1; j <= 1000; j++) { prefix[i][j] = prefix[i-1][j] + prefix[i][j-1] - prefix[i-1][j-1] + mat[i][j]; } } for (int i = 0; i < q; i++) { int hs = queries[i][0]; int ws = queries[i][1]; int hb = queries[i][2]; int wb = queries[i][3]; System.out.println(prefix[hb-1][wb-1] - prefix[hb-1][ws] - prefix[hs][wb-1] + prefix[hs][ws]); } } sc.close(); } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
5ba109bca21b6cea67a0ac0ccd1b9b9d
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import javax.print.DocFlavor; import java.math.BigInteger; import java.util.*; import java.io.*; public class Vaibhav { static long bit[]; static boolean prime[]; public static long lcm(long x, long y) { return (x * y) / gcd(x, y); } static class Pair {//implements Comparable<Pair> { int peldo; int bachalo; Pair(int peldo, int bachalo) { this.peldo = peldo; this.bachalo = bachalo; } /* //public int compareTo(Pair o){ return this.cqm-o.cqm; }*/ } //BIT public static void update(long bit[], int i, int x) { for (; i < bit.length; i += (i & (-i))) { bit[i] += x; } } public static long sum(int i) { long sum = 0; for (; i > 0; i -= (i & (-i))) { sum += bit[i]; } return sum; } static long power(long x, long y, long p) { if (y == 0) return 1; if (x == 0) return 0; long res = 1l; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static long power(long x, long y) { if (y == 0) return 1; if (x == 0) return 0; long res = 1; while (y > 0) { if (y % 2 == 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } 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()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readlongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } static void sieveOfEratosthenes(int n) { prime = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } } public static int log2(int x) { return (int) (Math.log(x) / Math.log(2)); } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } static long nCk(int n, int k) { long res = 1; for (int i = n - k + 1; i <= n; ++i) res *= i; for (int i = 2; i <= k; ++i) res /= i; return res; } static BigInteger bi(String str) { return new BigInteger(str); } // Author - vaibhav_1710 static FastScanner fs = null; static long ans; static long mod = 1_000_000_007; static ArrayList<Integer> al[]; static long dp[][][]; static int n; static int k; public static void main(String[] args) { fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); outer: while (t-- > 0) { int n = fs.nextInt(); int q = fs.nextInt(); long g[][] = new long[1001][1001]; for(int i=0;i<n;i++){ long x = fs.nextLong(); long y = fs.nextLong(); g[(int)x][(int)y] += (x*y); } long sum[][] = new long[1001][1001]; for(int i=1;i<1001;i++){ for(int j=1;j<1001;j++){ sum[i][j] = sum[i-1][j] + sum[i][j-1] + g[i][j] - sum[i-1][j-1]; } } for(int i=0;i<q;i++){ int x1 = fs.nextInt(); int y1 = fs.nextInt(); int x2 = fs.nextInt(); int y2 = fs.nextInt(); if(x1+2>x2 || y1+2>y2) out.println(0); else{ long ans = sum[x2-1][y2-1] - sum[x2-1][y1] - sum[x1][y2-1] + sum[x1][y1]; out.println(ans); } } } out.close(); } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
bc8ad81f0a8c799c8becaae0b0827e18
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class CF1722E { public static void main(String[] args) { Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { int n = scanner.nextInt(); int q = scanner.nextInt(); int[][] hw = new int[n][2]; for (int j = 0; j < n; j++) { hw[j][0] = scanner.nextInt(); hw[j][1] = scanner.nextInt(); } int[][] queries = new int[q][4]; for (int j = 0; j < q; j++) { queries[j][0] = scanner.nextInt(); queries[j][1] = scanner.nextInt(); queries[j][2] = scanner.nextInt(); queries[j][3] = scanner.nextInt(); } List<String> res = solve(n, q, hw, queries); for (String re : res) { System.out.println(re); } } } private static final int MAX_LEN = 1005; // logn private static List<String> solve(int n, int q, int[][] hw, int[][] queries) { long[][] matrix = new long[MAX_LEN][MAX_LEN]; for (int[] tuple : hw) { matrix[tuple[0]][tuple[1]] += (long) tuple[0] * tuple[1]; } // 预处理前缀和 long[][] preSum2d = new long[MAX_LEN][MAX_LEN]; for (int i = 1; i < MAX_LEN; i++) { for (int j = 1; j < MAX_LEN; j++) { // 当前格 = 上 + 左 - 左上 + 原值 preSum2d[i][j] = preSum2d[i - 1][j] + preSum2d[i][j - 1] - preSum2d[i - 1][j - 1] + matrix[i - 1][j - 1]; } } List<String> resList = new ArrayList<>(); for (int[] query : queries) { int row1 = query[0] + 1; int col1 = query[1] + 1; int row2 = query[2] - 1; int col2 = query[3] - 1; long res = preSum2d[row2 + 1][col2 + 1] - preSum2d[row2 + 1][col1] - preSum2d[row1][col2 + 1] + preSum2d[row1][col1]; resList.add(String.valueOf(res)); } return resList; } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
148a0f3e58085954742dedb2e9d408fd
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.*; import java.util.*; public class E { final static boolean multipleTests = true; Input in; PrintWriter out; public E() { in = new Input(System.in); out = new PrintWriter(System.out); } public static void main(String[] args) { E solution = new E(); int t = 1; if (multipleTests) t = solution.in.nextInt(); for (; t > 0; t--) { solution.solve(); } solution.out.close(); } final static int max = 1005; void solve() { int n = in.nextInt(); int q = in.nextInt(); long[][] dp = new long[max][max]; for (int i=0; i<n; i++) { int h = in.nextInt(); int w = in.nextInt(); dp[h+1][w+1] += (long) h * w; } for (int i=0; i<max; i++) { for (int j=0; j<max; j++) { if (i-1 >= 0) dp[i][j] += dp[i-1][j]; if (j-1 >= 0) dp[i][j] += dp[i][j-1]; if (i-1 >= 0 && j-1 >= 0) dp[i][j] -= dp[i-1][j-1]; } } for (int i=0; i<q; i++) { int hs = in.nextInt(); int ws = in.nextInt(); int hb = in.nextInt(); int wb = in.nextInt(); long ans = dp[hb][wb] - dp[hb][ws+1] - dp[hs+1][wb] + dp[hs+1][ws+1]; out.println(ans); } } static class Input { BufferedReader br; StringTokenizer st; public Input(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(""); } String nextString() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextString()); } long nextLong() { return Long.parseLong(nextString()); } double nextDouble() { return Double.parseDouble(nextString()); } int[] nextIntArray(int size) { int[] ans = new int[size]; for (int i = 0; i < size; i++) { ans[i] = nextInt(); } return ans; } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
c92ac2c3b2bde314ae9d839ec9b9dd21
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.SortedSet; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; /** * # * * @author pttrung */ public class E_Round_817_Div4 { public static long MOD = 1000000007; static long[][] dp; public static void main(String[] args) throws FileNotFoundException { // PrintWriter out = new PrintWriter(new FileOutputStream(new File( // "output.txt"))); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(); int T = in.nextInt(); for (int Z = 0; Z < T; Z++) { int n = in.nextInt(); int q = in.nextInt(); long[][] count = new long[1001][1001]; for (int i = 0; i < n; i++) { int h = in.nextInt(); int w = in.nextInt(); count[h][w] += w; } for (int i = 1; i < count.length; i++) { for (int j = 1; j < count[i].length; j++) { count[i][j] += count[i][j - 1]; } } for (int i = 0; i < q; i++) { long result = 0; int h1 = in.nextInt(); int w1 = in.nextInt(); int h2 = in.nextInt(); int w2 = in.nextInt(); for (int j = h1 + 1; j < h2; j++) { long total = count[j][w2 - 1] - count[j][w1]; result += (long)j*total; } out.println(result); } } out.close(); } static int abs(int a) { return a < 0 ? -a : a; } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point { long x; long y; public Point(long start, long end) { this.x = start; this.y = end; } public String toString() { return x + " " + y; } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, int b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return val * val; } else { return val * (val * a); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
aea3a341b4cf8ee9c31e52484704d107
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { // static int[] prime = new int[100001]; final static long mod = 1000000007; public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); // sieve(); long t = in.nextLong(); while(t-- > 0){ long[][] a = new long[1001][1001]; int n = in.nextInt(), q = in.nextInt(); for(int i = 0; i < n; i++){ int h = in.nextInt(), w = in.nextInt(); a[h][w] += h*w; } fill(a); while(q-- > 0){ int hb = in.nextInt(), wb = in.nextInt(), hs = in.nextInt(), ws = in.nextInt(); if(hs - hb == 1 || ws - wb == 1){ out.println(0); }else{ out.println((a[hs-1][ws-1] - a[hb][ws-1]) + (a[hb][wb] - a[hs-1][wb])); } } } out.flush(); } static void fill(long[][] a){ for(int i = 1; i < 1001; i++){ for(int j = 1; j < 1001; j++){ a[i][j] += (a[i-1][j] - a[i-1][j-1]) + a[i][j-1]; } } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static Integer[] intInput(int n, InputReader in) { Integer[] a = new Integer[n]; for (int i = 0; i < a.length; i++) a[i] = in.nextInt(); return a; } static Long[] longInput(int n, InputReader in) { Long[] a = new Long[n]; for (int i = 0; i < a.length; i++) a[i] = in.nextLong(); return a; } static String[] strInput(int n, InputReader in) { String[] a = new String[n]; for (int i = 0; i < a.length; i++) a[i] = in.next(); return a; } // static void sieve() { // for (int i = 2; i * i < prime.length; i++) { // if (prime[i]) // continue; // for (int j = i * i; j < prime.length; j += i) { // prime[j] = true; // } // } // } } class Segment { int[] a; final int n; Segment(int n){ this.n = n; a = new int[4*n]; Arrays.fill(a, Integer.MIN_VALUE); } void set(int index, int val){ set(0, n-1, 0, index, val); } private void set(int s, int e, int ind, int index, int val) { if(s == e){ a[ind] = val; return; } int mid = (s+e)/2; if(mid <= index){ set(s, mid, 2*ind+1, index, val); }else{ set(mid+1, e, 2*ind+2, index, val); } a[ind] = Math.max(a[2*ind+1], a[2*ind+2]); } int get(int l, int h){ return get(0, n-1, l, h, 0); } private int get(int s, int e, int l, int h, int ind) { if(s >= l && e <= h){ return a[ind]; } if(s > h || e < l){ return Integer.MIN_VALUE; } int mid = (s+e)/2; return Math.max(get(s, mid, l, h, 2*ind+1), get(mid+1, e, l, h, 2*ind+2)); } } class Data{ int i, ind; public Data(int i, int ind) { this.i = i; this.ind = ind; } } // class compareVal implements Comparator<Data> { // @Override // public int compare(Data o1, Data o2) { // return (o1.val - o2.val); // } // } // class compareInd implements Comparator<Data> { // @Override // public int compare(Data o1, Data o2) { // return o1.ind - o2.ind == 0 ? o1.val - o2.val : o1.ind - o2.ind; // } // } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
d0a85472aa28bbe4608b1bdace45554e
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import java.util.*; public class Main { public static final int MAXN = 1000; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0){ int n = sc.nextInt(); int q = sc.nextInt(); long [][] a = new long[MAXN + 1][MAXN + 1]; for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); a[x][y] += x * y; } for (int i = 1; i < MAXN; i++) { for (int j = 1; j < MAXN; j++) { a[i][j] += a[i][j - 1]; } } for (int i = 1; i < MAXN; i++) { for (int j = 1; j < MAXN; j++) { a[i][j] += a[i - 1][j]; } } while(q-- > 0){ int x0 = sc.nextInt(); int y0 = sc.nextInt(); int x1 = sc.nextInt() - 1; int y1 = sc.nextInt() - 1; System.out.println(x1 > x0 && y1 > y0 ? a[x1][y1] - a[x1][y0] - a[x0][y1] + a[x0][y0] : 0); } } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output
PASSED
b2b0cb8cb93e96ca05be20bd5cc91c37
train_109.jsonl
1661871000
You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s &lt; h_i &lt; h_b$$$ and $$$w_s &lt; w_i &lt; w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ public class E { public static void process() throws IOException { int n = sc.nextInt(), q = sc.nextInt(); long count[][] = new long[1002][1002]; for(int i = 0; i<n; i++) { int h = sc.nextInt(), w = sc.nextInt(); count[h][w] += h*w; } for(int i = 1; i<=1001; i++) { for(int j = 1; j<=1001; j++) { count[i][j] += count[i][j-1]; } } while(q-- > 0) { int a = sc.nextInt(), b = sc.nextInt(); int l = sc.nextInt(), r = sc.nextInt(); long ans = 0; for(int i = a+1; i<l; i++) { ans+=count[i][r-1]-count[i][b]; } System.out.println(ans); } } //============================================================================= //--------------------------The End--------------------------------- //============================================================================= private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; private static void google(int tt) { System.out.print("Case #" + (tt) + ": "); } static FastScanner sc; static FastWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new FastWriter(System.out); } else { sc = new FastScanner("input.txt"); out = new FastWriter("output.txt"); } long s = System.currentTimeMillis(); int t = 1; t = sc.nextInt(); int TTT = 1; while (t-- > 0) { // google(TTT++); process(); } out.flush(); // tr(System.currentTimeMillis()-s+"ms"); } private static boolean oj = System.getProperty("ONLINE_JUDGE") != null; private static void tr(Object... o) { if (!oj) System.err.println(Arrays.deepToString(o)); } static class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } /* @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Pair)) return false; Pair key = (Pair) o; return x == key.x && y == key.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } */ } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long sqrt(long z) { long sqz = (long) Math.sqrt(z); while (sqz * 1L * sqz < z) { sqz++; } while (sqz * 1L * sqz > z) { sqz--; } return sqz; } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } public static long gcd(long a, long b) { if (a > b) a = (a + b) - (b = a); if (a == 0L) return b; return gcd(b % a, a); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = -1; while (low <= high) { mid = (low + high) / 2; if (arr[mid] > x) { high = mid - 1; } else { ans = mid; low = mid + 1; } } return ans; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length - 1, mid = -1; int ans = arr.length; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) { ans = mid; high = mid - 1; } else { low = mid + 1; } } return ans; } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void reverseArray(int[] a) { int n = a.length; int arr[] = new int[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } static void reverseArray(long[] a) { int n = a.length; long arr[] = new long[n]; for (int i = 0; i < n; i++) arr[i] = a[n - i - 1]; for (int i = 0; i < n; i++) a[i] = arr[i]; } //custom multiset (replace with HashMap if needed) public static void push(TreeMap<Integer, Integer> map, int k, int v) { //map[k] += v; if (!map.containsKey(k)) map.put(k, v); else map.put(k, map.get(k) + v); } public static void pull(TreeMap<Integer, Integer> map, int k, int v) { //assumes map[k] >= v //map[k] -= v int lol = map.get(k); if (lol == v) map.remove(k); else map.put(k, lol - v); } // compress Big value to Time Limit public static int[] compress(int[] arr) { ArrayList<Integer> ls = new ArrayList<Integer>(); for (int x : arr) ls.add(x); Collections.sort(ls); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); int boof = 1; //min value for (int x : ls) if (!map.containsKey(x)) map.put(x, boof++); int[] brr = new int[arr.length]; for (int i = 0; i < arr.length; i++) brr[i] = map.get(arr[i]); return brr; } // Fast Writer public static class FastWriter { private static final int BUF_SIZE = 1 << 13; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastWriter() { out = null; } public FastWriter(OutputStream os) { this.out = os; } public FastWriter(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastWriter write(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastWriter write(char c) { return write((byte) c); } public FastWriter write(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastWriter write(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } private static int countDigits(int l) { if (l >= 1000000000) return 10; if (l >= 100000000) return 9; if (l >= 10000000) return 8; if (l >= 1000000) return 7; if (l >= 100000) return 6; if (l >= 10000) return 5; if (l >= 1000) return 4; if (l >= 100) return 3; if (l >= 10) return 2; return 1; } public FastWriter write(int x) { if (x == Integer.MIN_VALUE) { return write((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } private static int countDigits(long l) { if (l >= 1000000000000000000L) return 19; if (l >= 100000000000000000L) return 18; if (l >= 10000000000000000L) return 17; if (l >= 1000000000000000L) return 16; if (l >= 100000000000000L) return 15; if (l >= 10000000000000L) return 14; if (l >= 1000000000000L) return 13; if (l >= 100000000000L) return 12; if (l >= 10000000000L) return 11; if (l >= 1000000000L) return 10; if (l >= 100000000L) return 9; if (l >= 10000000L) return 8; if (l >= 1000000L) return 7; if (l >= 100000L) return 6; if (l >= 10000L) return 5; if (l >= 1000L) return 4; if (l >= 100L) return 3; if (l >= 10L) return 2; return 1; } public FastWriter write(long x) { if (x == Long.MIN_VALUE) { return write("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { write((byte) '-'); x = -x; } int d = countDigits(x); for (int i = ptr + d - 1; i >= ptr; i--) { buf[i] = (byte) ('0' + x % 10); x /= 10; } ptr += d; return this; } public FastWriter write(double x, int precision) { if (x < 0) { write('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } write((long) x).write("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; write((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastWriter writeln(char c) { return write(c).writeln(); } public FastWriter writeln(int x) { return write(x).writeln(); } public FastWriter writeln(long x) { return write(x).writeln(); } public FastWriter writeln(double x, int precision) { return write(x, precision).writeln(); } public FastWriter write(int... xs) { boolean first = true; for (int x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter write(long... xs) { boolean first = true; for (long x : xs) { if (!first) write(' '); first = false; write(x); } return this; } public FastWriter writeln() { return write((byte) '\n'); } public FastWriter writeln(int... xs) { return write(xs).writeln(); } public FastWriter writeln(long... xs) { return write(xs).writeln(); } public FastWriter writeln(char[] line) { return write(line).writeln(); } public FastWriter writeln(char[]... map) { for (char[] line : map) write(line).writeln(); return this; } public FastWriter writeln(String s) { return write(s).writeln(); } private void innerflush() { try { out.write(buf, 0, ptr); ptr = 0; } catch (IOException e) { throw new RuntimeException("innerflush"); } } public void flush() { innerflush(); try { out.flush(); } catch (IOException e) { throw new RuntimeException("flush"); } } public FastWriter print(byte b) { return write(b); } public FastWriter print(char c) { return write(c); } public FastWriter print(char[] s) { return write(s); } public FastWriter print(String s) { return write(s); } public FastWriter print(int x) { return write(x); } public FastWriter print(long x) { return write(x); } public FastWriter print(double x, int precision) { return write(x, precision); } public FastWriter println(char c) { return writeln(c); } public FastWriter println(int x) { return writeln(x); } public FastWriter println(long x) { return writeln(x); } public FastWriter println(double x, int precision) { return writeln(x, precision); } public FastWriter print(int... xs) { return write(xs); } public FastWriter print(long... xs) { return write(xs); } public FastWriter println(int... xs) { return writeln(xs); } public FastWriter println(long... xs) { return writeln(xs); } public FastWriter println(char[] line) { return writeln(line); } public FastWriter println(char[]... map) { return writeln(map); } public FastWriter println(String s) { return writeln(s); } public FastWriter println() { return writeln(); } } // Fast Inputs static class FastScanner { //I don't understand how this works lmao private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] readArray(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] readArrayLong(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public int[][] readArrayMatrix(int N, int M, int Index) { if (Index == 0) { int[][] res = new int[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = (int) nextLong(); } return res; } int[][] res = new int[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = (int) nextLong(); } return res; } public long[][] readArrayMatrixLong(int N, int M, int Index) { if (Index == 0) { long[][] res = new long[N][M]; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) res[i][j] = nextLong(); } return res; } long[][] res = new long[N][M]; for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) res[i][j] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] readArrayDouble(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } }
Java
["3\n\n2 1\n\n2 3\n\n3 2\n\n1 1 3 4\n\n5 5\n\n1 1\n\n2 2\n\n3 3\n\n4 4\n\n5 5\n\n3 3 6 6\n\n2 1 4 5\n\n1 1 2 10\n\n1 1 100 100\n\n1 1 3 3\n\n3 1\n\n999 999\n\n999 999\n\n999 998\n\n1 1 1000 1000"]
6 seconds
["6\n41\n9\n0\n54\n4\n2993004"]
Note In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 &lt; 2$$$ (comparing heights) and $$$1 &lt; 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 &lt; 3$$$ (comparing heights) and $$$3 &lt; 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.
Java 17
standard input
[ "brute force", "data structures", "dp", "implementation" ]
9e9c7434ebf0f19261012975fe9ee7d0
The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s &lt; h_b,\ w_s &lt; w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
1,600
For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.
standard output