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 | 035fbdb3a124f6b2f28d11bcdb58df21 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | //<———My cp————
//https://takeuforward.org/interview-experience/strivers-cp-sheet/?utm_source=youtube&utm_medium=striver&utm_campaign=yt_video
import java.util.*;
import java.io.*;
public class Solution{
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws Exception{
FastReader fr = new FastReader(System.in);
int t = fr.nextInt();
while(t-->0){
String line = fr.next();
int[] keys = new int[3];
boolean poss=true;
for(int i = 0;i<line.length()&&poss;i++){
if(line.charAt(i)=='r'){
keys[0]=1;
}
if(line.charAt(i)=='g'){
keys[1]=1;
}
if(line.charAt(i)=='b'){
keys[2]=1;
}
if(line.charAt(i)=='R'){
if(keys[0]==0){
poss=false;
}
}
if(line.charAt(i)=='G'){
if(keys[1]==0){
poss=false;
}
}
if(line.charAt(i)=='B'){
if(keys[2]==0){
poss=false;
}
}
}
if(poss){
pw.println("YES");
}else{
pw.println("NO");
}
}
pw.close();
}
static int lowerBound(int left,int right,int[] vals,int value){
int mid = (left+right)/2;
while(left<right){
mid = (left+right)/2;
if(vals[mid]<value){
left = mid+1;
}else{
right = mid;
}
}
return left;
}
static int upperBound(int left,int right,int[] vals,int value){
while(left<right){
int mid = (left+right+1)/2;
if(vals[mid]<=value){
left=mid;
}else{
right=mid-1;
}
}
return left;
}
static class Pair{
int vals;
int index;
public Pair(int index,int val){
this.vals = val;
this.index = index;
}
}
static int isPerfectSquare(int vals){
int lastPow=1;
while(lastPow*lastPow<vals){
lastPow++;
}
if(lastPow*lastPow==vals){
return lastPow*lastPow;
}else{
return -1;
}
}
public static int[] sort(int[] vals){
ArrayList<Integer> values = new ArrayList<>();
for(int i = 0;i<vals.length;i++){
values.add(vals[i]);
}
Collections.sort(values);
for(int i =0;i<values.size();i++){
vals[i] = values.get(i);
}
return vals;
}
public static long[] sort(long[] vals){
ArrayList<Long> values = new ArrayList<>();
for(int i = 0;i<vals.length;i++){
values.add(vals[i]);
}
Collections.sort(values);
for(int i =0;i<values.size();i++){
vals[i] = values.get(i);
}
return vals;
}
public static void reverseArray(long[] vals){
int startIndex = 0;
int endIndex = vals.length-1;
while(startIndex<=endIndex){
long temp = vals[startIndex];
vals[startIndex] = vals[endIndex];
vals[endIndex] = temp;
startIndex++;
endIndex--;
}
}
public static void reverseArray(int[] vals){
int startIndex = 0;
int endIndex = vals.length-1;
while(startIndex<=endIndex){
int temp = vals[startIndex];
vals[startIndex] = vals[endIndex];
vals[endIndex] = temp;
startIndex++;
endIndex--;
}
}
static class FastReader{
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan());
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan());
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan());
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
public static int GCD(int numA, int numB){
if(numA==0){
return numB;
}else if(numB==0){
return numA;
}else{
if(numA>numB){
return GCD(numA%numB,numB);
}else{
return GCD(numA,numB%numA);
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 7f22bc10c9e0cdc50bb699f68e7baf0e | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.util.*;
import java.io.*;
public class codeforceb
{
//ArrayList<Integer> arr2=new ArrayList<Integer>();
static ArrayList<Long> arr1=new ArrayList<Long>();
//Map<Integer,Integer> hm=new HashMap<Integer,Integer>();
//static Set<Integer> st1=new HashSet<Integer>();
static Set<Integer> prime=new HashSet<Integer>();
static int inf = Integer.MAX_VALUE ;
static long infL = Long.MAX_VALUE ;
static int mod=1000000007;
static FastReader sc=new FastReader();
static PrintWriter out=new PrintWriter(System.out);
// seive to find prime for a given range except 1;
public static void main (String[] args) throws java.lang.Exception
{
/*Arrays.sort(time,new Comparator<Pair>(){
public int compare(Pair p1,Pair p2){
if(p1.a==p2.a)
return p1.b-p2.b;
return p1.a-p2.a;
}
});*/
//int r[][]= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}
// };
int t=sc.nextInt();
//seive(1000000);
// seive to find prime for a given range except 1;
while(t-->0)
{
solve();
}
out.close();
}
public static void solve() throws IOException
{
String s = sc.nextLine();
int r=0,g=0,b=0;
boolean f=false;
for(int i =0;i<6;i++) {
if(s.charAt(i) =='R' ) {
if(r==0)
f=true;
}
else if(s.charAt(i) =='G') {
if(g==0)
f=true;
}
else if(s.charAt(i) =='B') {
if(b==0)
f=true;
}
else if(s.charAt(i) =='g') {
g=1;
}
else if(s.charAt(i) =='r') {
r=1;
}
else if(s.charAt(i) =='b') {
b=1;
}
}
if(f) out.println("NO");
else out.println("YES");
}
static class Pair{
int a;
int b;
Pair(int x, int y)
{
this.a = x;
this.b = y;
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] readLong(int n) {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static boolean isPrime(long x)
{
if(x==1)
return false;
if(x<=3)
return true;
if(x%2==0 || x%3==0)
return false;
for(int i=5;i<=Math.sqrt(x);i+=2)
if(x%i==0)
return false;
return true;
}
static long gcd(long a,long b)
{
return (b==0)?a:gcd(b,a%b);
}
static int gcd(int a,int b)
{
return (b==0)?a:gcd(b,a%b);
}
static int abs(int n) {
if(n<0) return n*-1;
else return n;
}
static long abs(long n) {
if(n<0) return n*-1;
else return n;
}
public static long myPow(long x, long n) {
if(x==0)
return 0;
if(n==0)
return 1;
if(n==1)
return x;
long calc=myPow((long)x,n/2);
//System.out.println(calc+" "+n/2);
if(Math.abs(n)%2==0)
return (calc*calc);
else
return (x*calc*calc);
}
public static long lcm(long a , long b){
return a * (b/gcd(a,b));
}
public static int lcm(int a , int b){
return (a * b)/gcd(a,b);
}
public static void swap(int[] arr, int left , int right){
int temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
public static void swap(char[] arr, int left , int right){
char temp = arr[left];
arr[left] = arr[right];
arr[right] = temp;
}
public static void reverse(int[] arr){
int left = 0;
int right = arr.length-1;
while(left <= right){
swap(arr, left,right);
left++;
right--;
}
}
public static void seive(int val) {
int arr[]=new int[val+1];
for(int i=2;i<=val;i++) {
if(arr[i]==0) {
prime.add(i);
for(int j=i;j<=val;j+=i) arr[j]=1;
}
else continue;
}
}
public static long maxL(long a,long b) {
return (long)Math.max(a,b);
}
public static int max(int a,int b) {
return (int)Math.max(a,b);
}
public static int max(int a,int b,int c) {
return max(a,max(b,c));
}
public static int min(int a,int b) {
return (int)Math.min(a,b);
}
public static long min(long a,long b) {
return (long)Math.min(a,b);
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | d217d5f8d0d4576742ac3dc6d682d6d5 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner kb = new Scanner(System.in);
int t = kb.nextInt();
while(t-- > 0)
{
String str = kb.next();
HashSet<Character> hs = new HashSet<>();
boolean flag = true;
for(char c : str.toCharArray())
{
if(c>=65 && c<=90)
{
if(hs.contains((char)(c+32)) == false)
{
//System.out.println("in the if c: "+c+" hs: "+hs+" "+(char)(c+32)+" ");
flag = false;
break;
}
}
else
{
hs.add(c);
}
}
//System.out.println(" "+hs);
if(flag)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 5e0cb4e16ed3ed6ef811108e7f92ea68 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
static FastScanner scan = new FastScanner();
static Scanner scanner = new Scanner(System.in);
static PrintWriter printWriter = new PrintWriter(System.out);
public static void main(String[] args) {
int t = scan.nextInt();
while (t-- > 0) {
solve();
}
printWriter.close();
scanner.close();
}
public static void solve() {
String[] arr = scan.next().split("");
ArrayList<String> list = new ArrayList<>();
String check = arr[0].toUpperCase();
if(arr[0].equals(check)){
printWriter.println("NO");
return;
}
for(int i =0;i<arr.length;i++){
list.add(arr[i]);
if(arr[i].equals("R")){
if(list.contains("r")){
}
else{
printWriter.println("NO");
return;
}
}
else if(arr[i].equals("G")){
if(list.contains("g")){
}
else{
printWriter.println("NO");
return;
}
}
else if(arr[i].equals("B")){
if(list.contains("b")){
}
else{
printWriter.println("NO");
return;
}
}
}
printWriter.println("YES");
}
public static boolean unique(long[] arr,int start){
Set<Long> set = new HashSet<>();
for(int i =start;i<arr.length;i++){
set.add(arr[i]);
}
return set.size() == arr.length-start;
}
public static void yes(){
printWriter.println("YES");
}
public static void no(){
printWriter.println("NO");
}
static long gcd(long A, long B) {
if (B == 0) return A;
return gcd(B, A % B);
}
public static boolean isInteger(int n) {
return Math.sqrt(n) % 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 | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 3ef7e8029aed4145c7f67c4fafc5f955 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
// write your code here
r.init(System.in);
int t = r.nextInt();
while (t-- > 0){
String s = r.next();
HashSet<Character> set = new HashSet<>();
char ch;
boolean ans = true;
for (int i = 0; i < s.length(); i++){
ch = s.charAt(i);
if (ch == 'R' && !set.contains('r')) ans = false;
else if (ch == 'G' && !set.contains('g')) ans = false;
else if (ch == 'B' && !set.contains('b')) ans = false;
else set.add(ch);
}
if (ans) System.out.println("YES");
else System.out.println("NO");
}
}
}
class r {
static BufferedReader reader;
static StringTokenizer tokenizer;
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer
= new StringTokenizer("");
}
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | ded16ebd2d549ccf909d6c67d8a064b8 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
import java.io.*;
public class A {
static boolean equal(char[] a, char[] b) {
for (int i = 0; i < a.length; i++) {
if (a[i] != b[i])
return false;
}
return true;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
StringBuilder str = new StringBuilder();
int t = sc.nextInt();
for (int xx = 1; xx <= t; xx++) {
String s = sc.next();
int r =0;
int g = 0;
int b =0;
int c =1;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='r')
r=1;
if(s.charAt(i)=='g')
g=1;
if(s.charAt(i)=='b')
b=1;
if(s.charAt(i)=='R'&&r==0)
c=0;
if(s.charAt(i)=='G'&&g==0)
c=0;
if(s.charAt(i)=='B'&&b==0)
c=0;
}
if(c==1)
str.append("Yes");
else
str.append("No");
str.append("\n");
}
System.out.println(str);
sc.close();
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 4e8609c3e31f0c7ea47384af8fba467d | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Class1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t =sc.nextInt();
for(int q=0;q<t;q++){
boolean pass=true;
String s=sc.next(),keys="";
for(int i=0;i<6;i++){
if(s.charAt(i)<90){
boolean haveKey=false;
for(int j=0;j<keys.length();j++){
if(keys.charAt(j)==32+s.charAt(i))haveKey=true;
}
if(!haveKey){
pass=false;
break;
}
}else{
keys+=s.charAt(i);
}
}
if(pass)System.out.println("YES");
else System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 1e0acc87c2261cdc7d8c0eeb769c3d90 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
public class coding {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
String str = br.readLine();
if(str == null)
throw new InputMismatchException();
st = new StringTokenizer(str);
} 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();
}
if(str == null)
throw new InputMismatchException();
return str;
}
public BigInteger nextBigInteger() {
// TODO Auto-generated method stub
return null;
}
public void close() {
// TODO Auto-generated method stub
}
}
public static <K, V> K getKey(Map<K, V> map, V value)
{
for (Map.Entry<K, V> entry: map.entrySet())
{
if (value.equals(entry.getValue())) {
return entry.getKey();
}
}
return null;
}
public static int median(ArrayList<Integer> x)
{
int p=0;
if(x.size()==1)
{
p=x.get(0);
}
else
{
p=x.get((x.size()-1)/2 );
}
return p;
}
public static boolean palindrome(long x)
{
String s="",s1="";
while(x!=0)
{
s=s+x%10;
x=x/10;
}
for(int i=0;i<s.length();i++)
{
s1=s1+s.charAt(s.length()-i-1);
}
if(s1.contentEquals(s))
{
return true;
}
else
{
return false;
}
}
static void reverse(String a[], int n)
{
String k="", t="";
for (int i = 0; i < n / 2; i++) {
t = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = t;
}
}
public static void main(String args[] ) throws Exception {
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
int t=sc.nextInt();
while(t-->0)
{
String s=sc.next();
int r1=-1,b1=-1,g1=-1,R1=-1,B1=-1,G1=-1;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='r')
{
r1=i;
}
else if(s.charAt(i)=='b')
{
b1=i;
}
else if(s.charAt(i)=='g')
{
g1=i;
}
else if(s.charAt(i)=='B')
{
B1=i;
}
else if(s.charAt(i)=='G')
{
G1=i;
}
else if(s.charAt(i)=='R')
{
R1=i;
}
}
if(s.length()<6)
{
System.out.println("NO");
}
else
{
if(r1<R1 && b1<B1 && g1<G1)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 8aa35b5c19b9a10e59680d66ba6eec60 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 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();
boolean c;
String s;
while(t -- > 0){
c = true;
s = sc.next();
for(int i = 0; i < 5; i ++){
for(int j = i + 1; j < 6; j ++){
if(s.codePointAt(j) - s.codePointAt(i) == 32){
c = false;
break;
}
}
}
System.out.println(c ? "YES" : "NO");
}
sc.close();
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 85ca3f106a09ffc93dc0d1f23391f94b | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
public class Round12 {
public static void main(String[] args) {
FastReader fastReader = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int t = fastReader.nextInt();
while (t-- > 0) {
char c[] = fastReader.nextLine().toCharArray();
int n = c.length;
int keyr = 0, keyb = 0, keyg = 0;
boolean ans = true;
for (int i = 0; i < n; i++) {
if (c[i] == 'R') {
if (keyr < 1){
ans = false;
break;
}
} else if (c[i] == 'B') {
if (keyb < 1){
ans = false;
break;
}
} else if (c[i] == 'G') {
if (keyg < 1){
ans = false;
break;
}
} else if (c[i] == 'r') {
keyr++;
} else if (c[i] == 'b') {
keyb++;
} else {
keyg++;
}
}
out.println(ans ? "YES" : "NO");
}
out.close();
}
// constants
static final int IBIG = 1000000007;
static final int IMAX = 2147483647;
static final long LMAX = 9223372036854775807L;
static Random __r = new Random();
// math util
static int minof(int a, int b, int c) {
return min(a, min(b, c));
}
static int minof(int... x) {
if (x.length == 1) return x[0];
if (x.length == 2) return min(x[0], x[1]);
if (x.length == 3) return min(x[0], min(x[1], x[2]));
int min = x[0];
for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];
return min;
}
static long minof(long a, long b, long c) {
return min(a, min(b, c));
}
static long minof(long... x) {
if (x.length == 1) return x[0];
if (x.length == 2) return min(x[0], x[1]);
if (x.length == 3) return min(x[0], min(x[1], x[2]));
long min = x[0];
for (int i = 1; i < x.length; ++i) if (x[i] < min) min = x[i];
return min;
}
static int maxof(int a, int b, int c) {
return max(a, max(b, c));
}
static int maxof(int... x) {
if (x.length == 1) return x[0];
if (x.length == 2) return max(x[0], x[1]);
if (x.length == 3) return max(x[0], max(x[1], x[2]));
int max = x[0];
for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];
return max;
}
static long maxof(long a, long b, long c) {
return max(a, max(b, c));
}
static long maxof(long... x) {
if (x.length == 1) return x[0];
if (x.length == 2) return max(x[0], x[1]);
if (x.length == 3) return max(x[0], max(x[1], x[2]));
long max = x[0];
for (int i = 1; i < x.length; ++i) if (x[i] > max) max = x[i];
return max;
}
static int powi(int a, int b) {
if (a == 0) return 0;
int ans = 1;
while (b > 0) {
if ((b & 1) > 0) ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static long powl(long a, int b) {
if (a == 0) return 0;
long ans = 1;
while (b > 0) {
if ((b & 1) > 0) ans *= a;
a *= a;
b >>= 1;
}
return ans;
}
static int fli(double d) {
return (int) d;
}
static int cei(double d) {
return (int) ceil(d);
}
static long fll(double d) {
return (long) d;
}
static long cel(double d) {
return (long) ceil(d);
}
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
static long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
static int[] exgcd(int a, int b) {
if (b == 0) return new int[]{1, 0};
int[] y = exgcd(b, a % b);
return new int[]{y[1], y[0] - y[1] * (a / b)};
}
static long[] exgcd(long a, long b) {
if (b == 0) return new long[]{1, 0};
long[] y = exgcd(b, a % b);
return new long[]{y[1], y[0] - y[1] * (a / b)};
}
static int randInt(int min, int max) {
return __r.nextInt(max - min + 1) + min;
}
static long mix(long x) {
x += 0x9e3779b97f4a7c15L;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebL;
return x ^ (x >> 31);
}
public static boolean[] findPrimes(int limit) {
assert limit >= 2;
final boolean[] nonPrimes = new boolean[limit];
nonPrimes[0] = true;
nonPrimes[1] = true;
int sqrt = (int) Math.sqrt(limit);
for (int i = 2; i <= sqrt; i++) {
if (nonPrimes[i]) continue;
for (int j = i; j < limit; j += i) {
if (!nonPrimes[j] && i != j) nonPrimes[j] = true;
}
}
return nonPrimes;
}
// array util
static void reverse(int[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
int swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(long[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
long swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(double[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
double swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void reverse(char[] a) {
for (int i = 0, n = a.length, half = n / 2; i < half; ++i) {
char swap = a[i];
a[i] = a[n - i - 1];
a[n - i - 1] = swap;
}
}
static void shuffle(int[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
int swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void shuffle(long[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
long swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void shuffle(double[] a) {
int n = a.length - 1;
for (int i = 0; i < n; ++i) {
int ind = randInt(i, n);
double swap = a[i];
a[i] = a[ind];
a[ind] = swap;
}
}
static void rsort(int[] a) {
shuffle(a);
sort(a);
}
static void rsort(long[] a) {
shuffle(a);
sort(a);
}
static void rsort(double[] a) {
shuffle(a);
sort(a);
}
static int[] copy(int[] a) {
int[] ans = new int[a.length];
for (int i = 0; i < a.length; ++i) ans[i] = a[i];
return ans;
}
static long[] copy(long[] a) {
long[] ans = new long[a.length];
for (int i = 0; i < a.length; ++i) ans[i] = a[i];
return ans;
}
static double[] copy(double[] a) {
double[] ans = new double[a.length];
for (int i = 0; i < a.length; ++i) ans[i] = a[i];
return ans;
}
static char[] copy(char[] a) {
char[] ans = new char[a.length];
for (int i = 0; i < a.length; ++i) ans[i] = a[i];
return ans;
}
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());
}
int[] ria(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = Integer.parseInt(next());
return a;
}
long nextLong() {
return Long.parseLong(next());
}
long[] rla(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = Long.parseLong(next());
return a;
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 60085a3fba8593359ef412c0bf24b388 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = sc.nextInt();
while (count > 0) {
char[] chars = sc.next().toCharArray();
int posr = 0, posg = 0, posb = 0;
int posR = 0, posG = 0, posB = 0;
for (int i = 0; i < chars.length; i++) {
if ('r' == chars[i]) {
posr = i;
} else if ('g' == chars[i]) {
posg = i;
} else if ('b' == chars[i]) {
posb = i;
} else if ('R' == chars[i]) {
posR = i;
} else if ('G' == chars[i]) {
posG = i;
} else if ('B' == chars[i]) {
posB = i;
}
}
if (posr < posR && posg < posG && posb < posB) {
System.out.println("YES");
} else {
System.out.println("NO");
}
count--;
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | fe641ef7c1577e54334876dd29dcc8ac | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numberOfCases = sc.nextInt();
HashMap<Character, Boolean> doors = new HashMap<>();
for (int i = 0; i < numberOfCases; i++) {
boolean isStuck = false;
doors.put('R', false);
doors.put('G', false);
doors.put('B', false);
for (char character : sc.next().toCharArray()) {
if (character == 'r') {
doors.put('R', true);
} else if (character == 'g') {
doors.put('G', true);
} else if (character == 'b') {
doors.put('B', true);
} else if (Boolean.FALSE.equals(doors.get(character))) {
isStuck = true;
}
}
if(isStuck){
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | e026d12b97102cca0ea6235c18245980 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | //package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class Solution {
public static String ques1(String s){
boolean r = false;
boolean g = false;
boolean b = false;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i)=='R' && r==false) return "NO";
if (s.charAt(i)=='G' && g==false) return "NO";
if (s.charAt(i)=='B' && b==false) return "NO";
if (s.charAt(i)=='r') r = true;
if (s.charAt(i)=='g') g = true;
if (s.charAt(i)=='b') b = true;
}
return "YES";
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
for (int i = 0; i < m; i++) {
String s = sc.next();
System.out.println(ques1(s));
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 02fe6b02ea662ef238cc440d8c291ec9 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Main {
static Scanner sc = new Scanner (System.in);
public static void main(String[] args) {
int test = sc.nextInt();
for ( int t=0; t<test; t++){
String str = sc.next();
int r,g,b,R,G,B;
r = str.indexOf("r");
g = str.indexOf("g");
b = str.indexOf("b");
R = str.indexOf("R");
B = str.indexOf("B");
G = str.indexOf("G");
if ( r>R || g>G || b>B)
System.out.println("NO");
else
System.out.println("YES");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 7af77f17d5819e206ce19e2164da3c15 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.security.cert.X509CRL;
import java.util.*;
import java.lang.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;
@SuppressWarnings("unused")
public class Main {
static InputStream is;
static PrintWriter out;
static String INPUT = "";
static String OUTPUT = "";
//global
private final static long BASE = 998244353L;
private final static int ALPHABET = (int)('z') - (int)('a') + 1;
//private final static int BASE = 1000000007;
private final static int INF_I = (1<<31)-1;
private final static long INF_L = (1l<<63)-1;
private final static int MAXN = 200100;
private final static int MAXK = 31;
private final static int[] DX = {-1,0,1,0};
private final static int[] DY = {0,1,0,-1};
static void solve() {
int ntest = readInt();
for (int test=0;test<ntest;test++) {
char[] S = readString().toCharArray();
boolean r=false,g=false,b=false;
boolean isOk = true;
for (int i=0;i<S.length;i++) {
if (S[i]=='r') r=true;
if (S[i]=='g') g=true;
if (S[i]=='b') b=true;
if (S[i]=='R') isOk &= r;
if (S[i]=='G') isOk &= g;
if (S[i]=='B') isOk &= b;
}
if (isOk) out.println("YES");
else out.println("NO");
}
}
public static void main(String[] args) throws Exception
{
long S = System.currentTimeMillis();
if (INPUT=="") {
is = System.in;
} else {
File file = new File(INPUT);
is = new FileInputStream(file);
}
if (OUTPUT == "") out = new PrintWriter(System.out);
else out = new PrintWriter(OUTPUT);
solve();
out.flush();
long G = System.currentTimeMillis();
}
private static class Point<T extends Number & Comparable<T>> implements Comparable<Point<T>> {
private T x;
private T y;
public Point(T x, T y) {
this.x = x;
this.y = y;
}
public T getX() {return x;}
public T getY() {return y;}
@Override
public int compareTo(Point<T> o) {
int cmp = x.compareTo(o.getX());
if (cmp==0) return y.compareTo(o.getY());
return cmp;
}
}
private static class ClassComparator<T extends Comparable<T>> implements Comparator<T> {
public ClassComparator() {}
@Override
public int compare(T a, T b) {
return a.compareTo(b);
}
}
private static class ListComparator<T extends Comparable<T>> implements Comparator<List<T>> {
public ListComparator() {}
@Override
public int compare(List<T> o1, List<T> o2) {
for (int i = 0; i < Math.min(o1.size(), o2.size()); i++) {
int c = o1.get(i).compareTo(o2.get(i));
if (c != 0) {
return c;
}
}
return Integer.compare(o1.size(), o2.size());
}
}
private static boolean eof()
{
if(lenbuf == -1)return true;
int lptr = ptrbuf;
while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;
try {
is.mark(1000);
while(true){
int b = is.read();
if(b == -1){
is.reset();
return true;
}else if(!isSpaceChar(b)){
is.reset();
return false;
}
}
} catch (IOException e) {
return true;
}
}
private static byte[] inbuf = new byte[1024];
static int lenbuf = 0, ptrbuf = 0;
private static 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++];
}
private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
// private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private static double readDouble() { return Double.parseDouble(readString()); }
private static char readChar() { return (char)skip(); }
private static String readString()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private static char[] readChar(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);
}
private static char[][] readTable(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = readChar(m);
return map;
}
private static int[] readIntArray(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = readInt();
return a;
}
private static long[] readLongArray(int n) {
long[] a = new long[n];
for (int i=0;i<n;i++) a[i] = readLong();
return a;
}
private static int readInt()
{
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 * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static long readLong()
{
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 * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | a09e7d08e72f398436a95f795654cd38 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class A_Doorsandkey
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int f=1; f<=T; f++)
{
int r = 0;
int R = 0;
int g = 0;
int G = 0;
int b = 0;
int B = 0;
String s = sc.next();
for(int i=0; i<s.length(); i++)
{
if(s.charAt(i) == 'r')
{
r = i;
}
else if(s.charAt(i) == 'g')
{
g = i;
}
else if(s.charAt(i) == 'b')
{
b = i;
}
else if(s.charAt(i) == 'R')
{
R = i;
}
else if(s.charAt(i) == 'G')
{
G = i;
}
else if(s.charAt(i) == 'B')
{
B = i;
}
}
if(r<R && g<G && b<B)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | c3f2300aa23d321fee94c056c3e88467 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
import java.util.Stack;
public class DoorsandKeys {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-->0){
String s = scn.next();
Stack<Character> stk = new Stack<>();
boolean r = false;
boolean g = false;
boolean b = false;
for(int i=0; i<6; i++){
if(s.charAt(i) == 'R' && stk.contains('r')){
r = true;
}
else if(s.charAt(i) == 'G' && stk.contains('g')){
g = true;
}
else if(s.charAt(i) == 'B' && stk.contains('b')){
b = true;
}
else{
stk.push(s.charAt(i));
}
}
if(r && g && b) System.out.println("YES");
else System.out.println("NO");
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | d63408023fceb5eb3cf21ac08dfdb5a5 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in) ;
int t = sc.nextInt() ;
while(t--!=0){
String str = sc.next();
int count = 0;
if(str.indexOf('r') < str.indexOf('R'))
count++;
if(str.indexOf('b') < str.indexOf('B'))
count++;
if(str.indexOf('g') < str.indexOf('G'))
count++;
if(count==3)
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 31f0953a53bcf0a7fa1e480d84b8e04e | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Codeforces {
public static void main(String[] args) {
Scanner Input = new Scanner(System.in);
int t = Input.nextInt();
boolean a,b,c;
String s;
for(;t>0;t--){
s = Input.next();
if(s.indexOf('r')<s.indexOf('R') && s.indexOf('b')<s.indexOf('B') && s.indexOf('g')<s.indexOf('G')){
System.out.println("YES");continue;}
System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 46c03764f3d900f32cd898df5c8ac732 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class Knights {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int antal = input.nextInt();
while (antal-- > 0) {
String str = input.next();
char[] arr = str.toCharArray();
boolean r = false;
boolean g = false;
boolean b = false;
boolean ok = false;
for (int i = 0; i < arr.length; i++) {
if (arr[i] == 'r') {
r = true;
} else if (arr[i] == 'g') {
g = true;
} else if (arr[i] == 'b') {
b = true;
}
if ((arr[i] == 'R' && !r)
|| (arr[i] == 'G' && !g)
|| (arr[i] == 'B' && !b)) {
ok = false;
break;
} else {
ok = true;
}
}
if (ok) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
input.close();
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | bdf97b1f1269d8fdb041f682d64e5db8 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.abs;
import static java.lang.Math.sqrt;
public class Main{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
boolean ifb = false;
int n = in.nextInt();
for (int i = 0; i < n; i++) {
boolean red=false,green=false,blue=false;
String str = in.next();
char[] c = str.toCharArray();
for (int j = 0; j < 6; j++) {
if(c[j] == 'r'){
red = true;
}
if(c[j] == 'g'){
green = true;
}
if(c[j] == 'b'){
blue = true;
}
if(c[j] == 'R' && red==false){
System.out.println("NO");
ifb = true;
break;
}
if(c[j] == 'G' && green==false){
System.out.println("NO");
ifb = true;
break;
}
if(c[j] == 'B' && blue==false){
System.out.println("NO");
ifb = true;
break;
}
}
if(ifb != true){
System.out.println("YES");
}
ifb = false;
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 2487e3ae6e7bab22c0d3c0072761eb79 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
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;
import java.math.BigInteger;
public final class Main{
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
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();
}
}
static class Kattio extends PrintWriter {
private BufferedReader r;
private StringTokenizer st;
// standard input
public Kattio() { this(System.in, System.out); }
public Kattio(InputStream i, OutputStream o) {
super(o);
r = new BufferedReader(new InputStreamReader(i));
}
// USACO-style file input
public Kattio(String problemName) throws IOException {
super(new FileWriter(problemName + ".out"));
r = new BufferedReader(new FileReader(problemName + ".in"));
}
// returns null if no more input
public String next() {
try {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(r.readLine());
return st.nextToken();
} catch (Exception e) { }
return null;
}
public int nextInt() { return Integer.parseInt(next()); }
public double nextDouble() { return Double.parseDouble(next()); }
public long nextLong() { return Long.parseLong(next()); }
}
static Kattio sc = new Kattio();
static long mod = 998244353l;
static PrintWriter out =new PrintWriter(System.out);
//Heapify function to maintain heap property.
public static void swap(int i,int j,int arr[]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void swap(int i,int j,long arr[]) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void swap(int i,int j,char arr[]) {
char temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static String endl = "\n" , gap = " ";
public static void main(String[] args)throws IOException {
int t =ri();
// List<Integer> list = new ArrayList<>();
// int MAX = (int)4e4;
// for(int i =1;i<=MAX;i++) {
// if(isPalindrome(i + "")) list.add(i);
// }
// // System.out.println(list);
// long dp[] = new long[MAX +1];
// dp[0] = 1;
// long mod = (long)(1e9+7);
// for(int x : list) {
// for(int i =1;i<=MAX;i++) {
// if(i >= x) {
// dp[i] += dp[i-x];
// dp[i] %= mod;
// }
// }
// }
// int MAK = (int)1e6;
// boolean seive[] = new boolean[MAK];
// Arrays.fill(seive , true);
// seive[1] = false;
// seive[0] = false;
// for (int i = 1; i < MAK; i++) {
// if(seive[i]) {
// for (int j = i+i; j < MAK; j+=i) {
// seive[j] = false;
// }
// }
// }
// for (int i = 1; i <= MAK; i++) {
// seive[i] += seive[i - 1];
// }
int test_case = 1;
while(t-->0) {
// out.write("Case #"+(test_case++)+": ");
solve();
}
out.close();
}
static HashMap<Integer , Boolean>dp;
public static void solve()throws IOException {
String s= rs();
if(s.indexOf('r') > s.indexOf('R')) {
System.out.println("NO");
return;
}if(s.indexOf('g') > s.indexOf('G')) {
System.out.println("NO");
return;
}if(s.indexOf('b') > s.indexOf('B')) {
System.out.println("NO");
return;
}
System.out.println("YES");
}
public static long callfun(int n) {
if(n == 1) return 1;
return n + n*callfun(n-1);
}
public static double getSlope(int a , int b,int x,int y) {
if(a-x == 0) return Double.MAX_VALUE;
if(b-y == 0) return 0.0;
return ((double)b-(double)y)/((double)a-(double)x);
}
public static int callfun(int a[], int []b) {
HashMap<Integer , Integer> map = new HashMap<>();
int n = a.length;
for(int i =0;i<b.length;i++) {
map.put(b[i] , i);
}
HashMap<Integer , Integer> cnt = new HashMap<>();
for(int i =0;i<n;i++) {
int move = (map.get(a[i])-i+n)%n;
cnt.put(move , cnt.getOrDefault(move,0) + 1);
}
int max =0;
for(int x : cnt.keySet()) max = Math.max(max , cnt.get(x));
return max;
}
public static boolean collinearr(long a[] , long b[] , long c[]) {
return (b[1]-a[1])*(b[0]-c[0]) == (b[0]-a[0])*(b[1]-c[1]);
}
public static boolean isSquare(int sum) {
int root = (int)Math.sqrt(sum);
return root*root == sum;
}
public static boolean canPlcae(int prev,int len , int sum,int arr[],int idx) {
// System.out.println(sum + " is sum prev " + prev);
if(len == 0) {
if(isSquare(sum)) return true;
return false;
}
for(int i = prev;i<=9;i++) {
arr[idx] = i;
if(canPlcae(i, len-1,sum + i*i,arr,idx + 1)) {
return true;
}
}
return false;
}
public static boolean isPalindrome(String s) {
int i =0 , j = s.length() -1;
while(i <= j && s.charAt(i) == s.charAt(j)) {
i++;
j--;
}
return i>j;
}
// digit dp hint;
public static long callfun(String num , int N, int last ,int secondLast ,int bound ,long dp[][][][]) {
if(N == 1) {
if(last == -1 || secondLast == -1) return 0;
long answer = 0;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i = 0;i<=max;i++) {
if(last > secondLast && last > i) {
answer++;
}
if(last < secondLast && last < i) {
answer++;
}
}
return answer;
}
if(secondLast == -1 || last == -1 ){
long answer = 0l;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i =0;i<=max;i++) {
int nl , nsl , newbound = bound==0?0:i==max?1:0;
if(last == - 1&& secondLast == -1 && i == 0) {
nl = -1 ; nsl = -1;
}
else {
nl = i;nsl = last;
}
long temp = callfun(num , N-1 , nl , nsl ,newbound, dp);
answer += temp;
if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++;
}
return answer;
}
if(dp[N][last][secondLast][bound] != -1) return dp[N][last][secondLast][bound];
long answer = 0l;
int max = (bound==1)?(num.charAt(num.length()-N)-'0') : 9;
for(int i =0;i<=max;i++) {
int nl , nsl , newbound = bound==0?0:i==max?1:0;
if(last == - 1&& secondLast == -1 && i == 0) {
nl = -1 ; nsl = -1;
}
else {
nl = i;nsl = last;
}
long temp = callfun(num , N-1 , nl , nsl ,newbound,dp);
answer += temp;
if(last != -1 && secondLast != -1 &&((last > secondLast && last > i)||(last < secondLast && last < i))) answer++;
}
return dp[N][last][secondLast][bound] = answer;
}
public static Long callfun(int index ,int pair,int arr[],Long dp[][]) {
long mod = (long)998244353l;
if(index >= arr.length) return 1l;
if(dp[index][pair] != null) return dp[index][pair];
Long sum = 0l , ans = 0l;
if(arr[index]%2 == pair) {
return dp[index][pair] = callfun(index + 1,pair^1 , arr,dp)%mod + callfun(index + 1 ,pair , arr , dp)%mod;
}
else {
return dp[index][pair] = callfun(index + 1,pair , arr,dp)%mod;
}
// for(int i =index;i<arr.length;i++) {
// sum += arr[i];
// if(sum%2 == pair) {
// ans = ans + callfun(i + 1,pair^1,arr , dp)%mod;
// ans%=mod;
// }
// }
// return dp[index][pair] = ans;
}
public static boolean callfun(int index , int n,int neg , int pos , String s) {
if(neg < 0 || pos < 0) return false;
if(index >= n) return true;
if(s.charAt(0) == 'P') {
if(neg <= 0) return false;
return callfun(index + 1,n , neg-1 , pos , s.charAt(1) + "N");
}
else {
if(pos <= 0) return false;
return callfun(index + 1 , n , neg , pos-1 , s.charAt(1) + "P");
}
}
public static void getPerm(int n , char arr[] , String s ,List<String>list) {
if(n == 0) {
list.add(s);
return;
}
for(char ch : arr) {
getPerm(n-1 , arr , s+ ch,list);
}
}
public static int getLen(int i ,int j , char s[]) {
while(i >= 0 && j < s.length && s[i] == s[j]) {
i--;
j++;
}
i++;
j--;
if(i>j) return 0;
return j-i + 1;
}
public static int getMaxCount(String x) {
char s[] = x.toCharArray();
int max = 0;
int n = s.length;
for(int i =0;i<n;i++) {
max = Math.max(max,Math.max(getLen(i , i,s) , getLen(i ,i+1,s)));
}
return max;
}
public static double getDis(int arr[][] , int x, int y) {
double ans = 0.0;
for(int a[] : arr) {
int x1 = a[0] , y1 = a[1];
ans += Math.sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1));
}
return ans;
}
public static boolean valid(String x ) {
if(x.length() == 0) return true;
if(x.length() == 1) return false;
char s[] = x.toCharArray();
if(x.length() == 2) {
if(s[0] == s[1]) {
return false;
}
return true;
}
int r = 0 , b = 0;
for(char ch : x.toCharArray()) {
if(ch == 'R') r++;
else b++;
}
return (r >0 && b >0);
}
public static long callfun(int day , int k, int limit,int n) {
if(k > limit) return 0;
if(day > n) return 1;
long ans = callfun(day + 1 , k , limit, n)*k + callfun(day + 1,k+1,limit,n)*(k+1);
return ans;
}
public static void primeDivisor(HashMap<Long , Long >cnt , long num) {
for(long i = 2;i*i<=num;i++) {
while(num%i == 0) {
cnt.put(i ,(cnt.getOrDefault(i,0l) + 1));
num /= i;
}
}
if(num > 2) {
cnt.put(num ,(cnt.getOrDefault(num,0l) + 1));
}
}
public static boolean isSubsequene(char a[], char b[] ) {
int i =0 , j = 0;
while(i < a.length && j <b.length) {
if(a[i] == b[j]) {
j++;
}
i++;
}
return j >= b.length;
}
public static long fib(int n ,long M) {
if (n == 0) {
return 0;
} else if (n == 1) {
return 1;
} else {
long[][] mat = {{1, 1}, {1, 0}};
mat = pow(mat, n-1 , M);
return mat[0][0];
}
}
public static long[][] pow(long[][] mat, int n ,long M) {
if (n == 1) return mat;
else if (n % 2 == 0) return pow(mul(mat, mat , M), n/2 , M);
else return mul(pow(mul(mat, mat,M), n/2,M), mat , M);
}
static long[][] mul(long[][] p, long[][] q,long M) {
long a = (p[0][0]*q[0][0] + p[0][1]*q[1][0])%M;
long b = (p[0][0]*q[0][1] + p[0][1]*q[1][1])%M;
long c = (p[1][0]*q[0][0] + p[1][1]*q[1][0])%M;
long d = (p[1][0]*q[0][1] + p[1][1]*q[1][1])%M;
return new long[][] {{a, b}, {c, d}};
}
public static long[] kdane(long arr[]) {
int n = arr.length;
long dp[] = new long[n];
dp[0] = arr[0];
long ans = dp[0];
for(int i = 1;i<n;i++) {
dp[i] = Math.max(dp[i-1] + arr[i] , arr[i]);
ans = Math.max(ans , dp[i]);
}
return dp;
}
public static void update(int low , int high , int l , int r, int val , int treeIndex ,int tree[]) {
if(low > r || high < l || high < low) return;
if(l <= low && high <= r) {
System.out.println("At " +low + " and " + high + " ans ttreeIndex " + treeIndex);
tree[treeIndex] += val;
return;
}
int mid = low + (high - low)/2;
update(low , mid , l , r , val , treeIndex*2 + 1, tree);
update(mid + 1 , high , l , r , val , treeIndex*2 + 2 , tree);
}
static int colx[] = {1 ,-1, 0,0 , 1,1,-1,-1};
static int coly[] = {0 ,0, 1,-1,1,-1,1,-1};
public static void reverse(char arr[]) {
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , arr);
i++;
j--;
}
}
public static long[] reverse(long arr[]) {
long newans[] = arr.clone();
int i =0 , j = arr.length-1;
while(i < j) {
swap(i , j , newans);
i++;
j--;
}
return newans;
}
public static long inverse(long x , long mod) {
return pow(x , mod -2 , mod);
}
public static int maxArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static long maxArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =1;i<n;i++) {
ans = Math.max(ans , arr[i]);
}
return ans;
}
public static int minArray(int arr[]) {
int ans = arr[0] , n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static long minArray(long arr[]) {
long ans = arr[0];
int n = arr.length;
for(int i =0;i<n;i++ ) {
ans = Math.min(ans ,arr[i]);
}
return ans;
}
public static int sumArray(int arr[]) {
int ans = 0;
for(int x : arr) {
ans += x;
}
return ans;
}
public static long sumArray(long arr[]) {
long ans = 0;
for(long x : arr) {
ans += x;
}
return ans;
}
public static long rl() {
return sc.nextLong();
}
public static char[] rac() {
return sc.next().toCharArray();
}
public static String rs() {
return sc.next();
}
public static char rc() {
return sc.next().charAt(0);
}
public static int [] rai(int n) {
int ans[] = new int[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextInt();
}
return ans;
}
public static long [] ral(int n) {
long ans[] = new long[n];
for(int i =0;i<n;i++) {
ans[i] = sc.nextLong();
}
return ans;
}
public static int ri() {
return sc.nextInt();
}
public static int getValue(int num ) {
int ans = 0;
while(num > 0) {
ans++;
num = num&(num-1);
}
return ans;
}
public static boolean isValid(int x ,int y , int n,char arr[][],boolean visited[][][][]) {
return x>=0 && x<n && y>=0 && y <n && !(arr[x][y] == '#');
}
// public static Pair join(Pair a , Pair b) {
// Pair res = new Pair(Math.min(a.min , b.min) , Math.max(a.max , b.max) , a.count + b.count);
// return res;
// }
// segment tree query over range
// public static int query(int node,int l , int r,int a,int b ,Pair tree[] ) {
// if(tree[node].max < a || tree[node].min > b) return 0;
// if(l > r) return 0;
// if(tree[node].min >= a && tree[node].max <= b) {
// return tree[node].count;
// }
// int mid = l + (r-l)/2;
// int ans = query(node*2 ,l , mid ,a , b , tree) + query(node*2 +1,mid + 1, r , a , b, tree);
// return ans;
// }
// // segment tree update over range
// public static void update(int node, int i , int j ,int l , int r,long value, long arr[] ) {
// if(l >= i && j >= r) {
// arr[node] += value;
// return;
// }
// if(j < l|| r < i) return;
// int mid = l + (r-l)/2;
// update(node*2 ,i ,j ,l,mid,value, arr);
// update(node*2 +1,i ,j ,mid + 1,r, value , arr);
// }
public static long pow(long a , long b , long mod) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2 , mod)%mod;
if(b%2 == 0) {
return (ans*ans)%mod;
}
else {
return ((ans*ans)%mod*a)%mod;
}
}
public static long pow(long a , long b ) {
if(b == 1) return a;
if(b == 0) return 1;
long ans = pow(a , b/2);
if(b%2 == 0) {
return (ans*ans);
}
else {
return ((ans*ans)*a);
}
}
public static boolean isVowel(char ch) {
if(ch == 'a' || ch == 'e'||ch == 'i' || ch == 'o' || ch == 'u') return true;
if((ch == 'A' || ch == 'E'||ch == 'I' || ch == 'O' || ch == 'U')) return true;
return false;
}
public static int getFactor(int num) {
if(num==1) return 1;
int ans = 2;
int k = num/2;
for(int i = 2;i<=k;i++) {
if(num%i==0) ans++;
}
return Math.abs(ans);
}
public static int[] readarr()throws IOException {
int n = sc.nextInt();
int arr[] = new int[n];
for(int i =0;i<n;i++) {
arr[i] = sc.nextInt();
}
return arr;
}
public static boolean isPowerOfTwo (long x) {
return x!=0 && ((x&(x-1)) == 0);
}
public static boolean isPrime(long num) {
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(long i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
public static boolean isPrime(int num) {
// System.out.println("At pr " + num);
if(num==1) return false;
if(num<=3) return true;
if(num%2==0||num%3==0) return false;
for(int i =5;i*i<=num;i+=6) {
if(num%i==0 || num%(i+2) == 0) return false;
}
return true;
}
// public static boolean isPrime(long num) {
// if(num==1) return false;
// if(num<=3) return true;
// if(num%2==0||num%3==0) return false;
// for(int i =5;i*i<=num;i+=6) {
// if(num%i==0) return false;
// }
// return true;
// }
public static long gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static int get_gcd(int a , int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static long get_gcd(long a , long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
// public static long fac(long num) {
// long ans = 1;
// int mod = (int)1e9+7;
// for(long i = 2;i<=num;i++) {
// ans = (ans*i)%mod;
// }
// return ans;
// }
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | dafdf84c424df39cc4beec251896bfe3 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Submit {
public static void main(String[] args) {
try (FastReader reader = new FastReader()) {
int t = reader.nextInt();
while (t-- > 0) {
char[] chars = reader.nextLine().toCharArray();
if (chars[0] < 83) {
System.out.println("NO");
continue;
}
String ans = "YES";
char[] keys = new char[3];
int i = 0;
for (char c : chars) {
if (c > 82) { // R
keys[i] = Character.toUpperCase(c);
i++;
} else if (!containsKey(keys, c)) {
ans = "NO";
break;
}
}
System.out.println(ans);
}
}
}
private static boolean containsKey(char[] keys, char key) {
for (int i = 0; i < keys.length; i++) {
if (keys[i] == key) {
return true;
}
}
return false;
}
}
class FastReader implements AutoCloseable {
private BufferedReader reader;
private StringTokenizer tokenizer;
public FastReader() {
this.reader = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return tokenizer.nextToken();
}
public int nextInt() {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return Integer.parseInt(tokenizer.nextToken());
}
public String nextLine() {
String line = "";
try {
line = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return line;
}
public char nextChar() {
char character = ' ';
try {
character = (char) reader.read();
} catch (IOException ex) {
ex.printStackTrace();
}
return character;
}
@Override
public void close() {
try {
this.reader.close();
} catch (IOException closingEx) {
// ignore
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | bca14f055dd5b295f045f8f3604be7ae | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) {
in = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
try {
int t = in.nextInt(); while(t-- > 0) { solve(); out.println();}
// solve();
} finally {
out.close();
}
return;
}
public static void solve() {
char[] s = fillArray();
int[] keys = new int[200];
for(int ch : s) {
if(ch >= 'a' && ch <= 'z') {
keys[ch]++;
}
if(ch >= 'A' && ch <= 'Z' && keys[ch-'A' + 'a'] == 0) {
out.print("NO");
return;
}
}
out.print("YES");
}
//-------------- Helper methods-------------------
public static int[] fillArray(int n) {
int[] array = new int[n];
for(int i = 0; i < n; i++) {
array[i] = in.nextInt();
}
return array;
}
public static char[] fillArray() {
char[] array = in.next().toCharArray();
return array;
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
public static MyScanner in;
//-----------MyScanner class for faster input----------
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 | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 95dec60884fb1d5b39e5ee71403c46e6 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
import java.io.*;
public class Codechef {
static boolean multipleTC = true;
final static int Mod = 1000000007;
final static int Mod2 = 998244353;
final double PI = 3.14159265358979323846;
int MAX = 1000000007;
void pre() throws Exception {
}
long cntBit(long n){
if (n == 0)
return 0;
else
return (n & 1) + cntBit(n >> 1);
}
void solve(int t) throws Exception {
char arr[] = n().toCharArray();
boolean rkey = false, bkey = false, gkey = false;
boolean flag = false;
for(int i=0;i<arr.length;i++) {
if(arr[i] == 'r')
rkey = true;
else if(arr[i] == 'b')
bkey = true;
else if(arr[i] == 'g')
gkey = true;
else if(arr[i] == 'R') {
if(!rkey) {
flag = true;
break;
}
}
else if(arr[i] == 'B') {
if(!bkey) {
flag = true;
break;
}
}
else {
if(!gkey) {
flag = true;
break;
}
}
}
if(!flag)
pn("YES");
else
pn("NO");
}
double dist(int x1, int y1, int x2, int y2) {
double a = x1 - x2, b = y1 - y2;
return Math.sqrt((a * a) + (b * b));
}
int[] readArr(int n) throws Exception {
int arr[] = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = ni();
}
return arr;
}
void sort(int arr[], int left, int right) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = left; i <= right; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = left; i <= right; i++)
arr[i] = list.get(i - left);
}
void sort(int arr[]) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 0; i < arr.length; i++)
list.add(arr[i]);
Collections.sort(list);
for (int i = 0; i < arr.length; i++)
arr[i] = list.get(i);
}
public long max(long... arr) {
long max = arr[0];
for (long itr : arr)
max = Math.max(max, itr);
return max;
}
public int max(int... arr) {
int max = arr[0];
for (int itr : arr)
max = Math.max(max, itr);
return max;
}
public long min(long... arr) {
long min = arr[0];
for (long itr : arr)
min = Math.min(min, itr);
return min;
}
public int min(int... arr) {
int min = arr[0];
for (int itr : arr)
min = Math.min(min, itr);
return min;
}
public long sum(long... arr) {
long sum = 0;
for (long itr : arr)
sum += itr;
return sum;
}
public long sum(int... arr) {
long sum = 0;
for (int itr : arr)
sum += itr;
return sum;
}
String bin(long n) {
return Long.toBinaryString(n);
}
String bin(int n) {
return Integer.toBinaryString(n);
}
static int bitCount(int x) {
return x == 0 ? 0 : (1 + bitCount(x & (x - 1)));
}
static void dbg(Object... o) {
System.err.println(Arrays.deepToString(o));
}
int bit(long n) {
return (n == 0) ? 0 : (1 + bit(n & (n - 1)));
}
int abs(int a) {
return (a < 0) ? -a : a;
}
long abs(long a) {
return (a < 0) ? -a : a;
}
void p(Object o) {
out.print(o);
}
void pn(Object o) {
out.println(o);
}
void pni(Object o) {
out.println(o);
out.flush();
}
void pn(int[] arr) {
int n = arr.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(arr[i] + " ");
}
pn(sb);
}
void pn(long[] arr) {
int n = arr.length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
sb.append(arr[i] + " ");
}
pn(sb);
}
String n() throws Exception {
return in.next();
}
String nln() throws Exception {
return in.nextLine();
}
char c() throws Exception{
return in.next().charAt(0);
}
int ni() throws Exception {
return Integer.parseInt(in.next());
}
long nl() throws Exception {
return Long.parseLong(in.next());
}
double nd() throws Exception {
return Double.parseDouble(in.next());
}
public static void main(String[] args) throws Exception {
new Codechef().run();
}
FastReader in;
PrintWriter out;
void run() throws Exception {
in = new FastReader();
out = new PrintWriter(System.out);
int T = (multipleTC) ? ni() : 1;
pre();
for (int t = 1; t <= T; t++)
solve(t);
out.flush();
out.close();
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception {
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
throw new Exception(e.toString());
}
return str;
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 71e6ac6050c508663689ab840da56b73 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.ArrayList;
import java.util.Locale;
import java.util.Scanner;
public class Dirver {
static Scanner input;
public static void main(String[] args) {
input = new Scanner(System.in);
int t = 1;
t = input.nextInt();
while (t-- > 0) {
solve();
}
}
public static void solve() {
String s1 = "";
String s = input.next();
ArrayList<Character> arr = new ArrayList<>();
for (int i = 0; i < s.length(); i++) {
String ch = String.valueOf(s.charAt(i));
if (ch.equals("r") || ch.equals("g") || ch.equals("b")) {
s1 = s1.concat(ch);
continue;
} else {
boolean flag = false;
for (int j = 0; j < s1.length(); j++) {
if (ch.equals(String.valueOf(s1.charAt(j)).toUpperCase(Locale.ROOT))) {
flag= true;
break;
}
}
if(flag==false){
System.out.println("NO");
return;
}
}
}
System.out.println("YES");
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 0f99fdd98f4afead628f88f149af601f | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class Jyu1644ADoorsKeys {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//Capture total # of test cases
int t = sc.nextInt();
String[] output = new String[t];
for (int i=0; i<t; i++) {
String input = sc.next();
boolean[] opened = new boolean[6];
for (int m=0; m<6;m++) {
opened[m]=false;
}
for (int k=0; k<6; k++) {
if (Character.isLowerCase(input.charAt(k))) { //It is a key
char A = Character.toUpperCase(input.charAt(k));
int l=k+1;
while ((Character.compare(A, input.charAt(l)) !=0) && l<=5) {
l=l+1;
}
if (l<=5) {
opened[l] = true; //For the key, Found the door, and opened door.
} else {
output[i]="NO";
break;
}
//System.out.print(k+" ");
//System.out.print(l+" ");
//System.out.print(opened[k]+" ");
//System.out.println(opened[l]);
} else if (!opened[k]) { //It is a door and it was never opened before
output[i]="NO";
break;
} else if (k==5){ //It is a door and it was opened before
output[i]="YES";
}
} //end of one testing case; checking the string
} // end of all testing cases
for (int i=0; i<t; i++) {
System.out.println(output[i]);
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | d0dbfb3803bbf3a37406c64e24460fa3 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class LockAndKey
{
public static void main(String[] args) {
Scanner inp=new Scanner(System.in);
int t=inp.nextInt();
inp.nextLine();
while(t>0)
{
int s=1;
String st=inp.nextLine();
char[] c=st.toCharArray();
String coll="";
for(int i=0;i<st.length();i++)
{
if(c[i]=='b' || c[i]=='r' || c[i]=='g')
{
coll=coll+c[i];
}
else
{
if(coll.indexOf((char)(c[i]+32))!=-1)
;
else
{
s=0;
break;
}
}
}
if(s==0)
System.out.println("NO");
else
System.out.println("YES");
t--;
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | e761010f8b14caf3c998f5ca343c4445 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
public class Q1644A {
static int mod = (int) (1e9 + 7);
static void solve() {
String str=s();
boolean chk=true;
HashSet<Character>set=new HashSet<>();
l:for(char ch:str.toCharArray()){
if(ch=='r' || ch=='g' || ch=='b'){
set.add(ch);
}else{
if(set.contains((char)(ch+32))==false){
chk=false;
break l;
}
}
}
if(chk){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
public static void main(String[] args) {
int test = i();
while (test-- > 0) {
solve();
}
}
// -----> POWER ---> long power(long x, long y) <---- power
// -----> LCM ---> long lcm(long x, long y) <---- lcm
// -----> GCD ---> long gcd(long x, long y) <---- gcd
// -----> NCR ---> long ncr(int n, int r) <---- ncr
// -----> (SORTING OF LONG, CHAR,INT) -->long[] sortLong(long[] a2)<--
// -----> (INPUT OF INT,LONG ,STRING) -> int i() long l() String s()<-
// tempstart
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int Int() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String String() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return String();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static InputReader in = new InputReader(System.in);
public static int i() {
return in.Int();
}
public static long l() {
String s = in.String();
return Long.parseLong(s);
}
public static String s() {
return in.String();
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 11 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 50811a327de710c9f9c0a7fce4acdc49 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int t=sc.nextInt();
Main m=new Main();
List<String> ans=new ArrayList<String>();
while(sc.hasNext()) {
t--;
String s=sc.next();;
ans.add(m.outPut(s));
if(t<=0) break;
}
for(String s:ans) {
System.out.println(s);
}
}
public String outPut(String s) {
boolean r=false, g=false, b=false;
for(int i=0;i<s.length();i++) {
char c=s.charAt(i);
switch(c) {
case 'r':{
r=true;
break;
}
case 'g':{
g=true;
break;
}
case 'b':{
b=true;
break;
}
case 'R':{
if(!r) {
return "NO";
}
break;
}
case 'G':{
if(!g) {
return "NO";
}
break;
}
case 'B':{
if(!b) {
return "NO";
}
break;
}
default:{
return "NO";
}
}
}
return "YES";
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 897d9b3f7a696ad05d1ff7b6fb1147f2 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | //package CodeForces;
import java.util.*;
public class Main {
public static void main(String[] arg) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
String s = sc.next();
if(Character.isUpperCase(s.charAt(0)))
System.out.println("NO");
else {
int cnt = 0;
for(int i = 0;i < 5;i++) {
for(int j = i + 1;j < 6;j++) {
char check = s.toLowerCase().charAt(j);
if(s.charAt(i) == check) {
cnt++;
break;
}
}
if(cnt == 3)
break;
}
if(cnt == 3)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 5c309569ef8bd3dec6b99d6f0a1bd958 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.util.Scanner;
public class prac
{
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t;
t=sc.nextInt();
for (int i = 1; i <=t; i++)
{
String str=sc.next();
if(str.indexOf('r')< str.indexOf('R') && str.indexOf('b')< str.indexOf('B') && str.indexOf('g')< str.indexOf('G'))
{
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
sc.close();
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 88fe72ea07e9223348d6bb42542c08ff | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | // package CodeForcesEduRound220222;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;
public class Did {
public static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static boolean findKey(String[] keys, String pat ){
boolean foundKey = false;
for(int i =0;i< keys.length;i++){
if(pat.equalsIgnoreCase(keys[i])){
foundKey = true;
break;
}
}
return foundKey;
}
public static String findResult( String map){
String ans = "YES";
String[] keys = new String[4];
String[] mapPattern = map.split("");
int keyCount = 0;
for(int i=0;i< mapPattern.length;i++){
if(mapPattern[i].equals("r")||
mapPattern[i].equals("g")||
mapPattern[i].equals("b")){
keys[keyCount++] = mapPattern[i];
} else {
if(!findKey(keys,mapPattern[i])){
ans = "NO";
break;
}
}
}
return ans;
}
public static void main(String args[]){
FastScanner fs = new FastScanner();
int t = fs.nextInt();
String[] result = new String[t+1];
for(int i =0;i< t;i++){
String mapStr = fs.next();
System.out.println(findResult(mapStr));
}
return;
// for(int i =0;i< t;i++){
// System.out.println(result[i]);
//
// }
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 7330fe947dd167c4afbed5a4aaed37eb | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Test {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int t = scan.nextInt();
while(t-->0) {
System.out.println(f(scan.next()));
}
}
public static String f(String a) {
boolean r=false;
boolean g=false;
boolean b=false;
for(int i=0;i<a.length();i++) {
if(a.charAt(i)=='r') r=true;
else if(a.charAt(i)=='g') g=true;
else if(a.charAt(i)=='b') b=true;
else if(a.charAt(i)=='R') {
if (!r) return "NO";
}else if(a.charAt(i)=='G') {
if (!g) return "NO";
}else if(a.charAt(i)=='B') {
if (b == false) return "NO";
}
}
return "YES";
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 3b34691b0fac4b60aae645da21808825 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.util.*;
public class NewClass_1644_A{
public static void main(String arg[]){
Scanner ob=new Scanner(System.in);
int tt=ob.nextInt();
out:
for(int t=0;t<tt;t++){
String s=ob.next();
HashSet<Character> hs=new HashSet();
for(int i=0;i<s.length();i++){
hs.add(s.charAt(i));
if(s.charAt(i)=='R'){
if(!hs.contains('r')){
System.out.println("NO");
continue out;
}
}
if(s.charAt(i)=='G'){
if(!hs.contains('g')){
System.out.println("NO");
continue out;
}
}
if(s.charAt(i)=='B'){
if(!hs.contains('b')){
System.out.println("NO");
continue out;
}
}
}
System.out.println("YES");
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 9e1820dc16c35f61d13d9c39dd2387fe | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class NewClass_1644_A{
public static void main(String arg[]){
Scanner ob=new Scanner(System.in);
int tt=ob.nextInt();
out:
for(int t=0;t<tt;t++){
String s=ob.next();
Map<Character,Integer> mp=new HashMap();
mp.put('r',0);
mp.put('b',0);
mp.put('g',0);
for(int i=0;i<s.length();i++){
mp.put(s.charAt(i),mp.getOrDefault(s.charAt(i),0)+1);
if(s.charAt(i)=='R'){
//System.out.println(mp.get(s.charAt(i)));
if(mp.get('r')>0){
mp.put('r',mp.getOrDefault('r',0)-1);
}else{
System.out.println("NO");
continue out;
}
}else if(s.charAt(i)=='G'){
if(mp.get('g')>0){
mp.put('g',mp.getOrDefault('g',0)-1);
}else{
System.out.println("NO");
continue out;
}
}else if(s.charAt(i)=='B'){
if(mp.get('b')>0){
mp.put('b',mp.getOrDefault('b',0)-1);
}else{
System.out.println("NO");
continue out;
}
}
}
System.out.println("YES");
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | c9b1ebf0c3091d2e51bd9bf70075dfe7 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.util.*;
public class NewClass_1644_A{
public static void main(String arg[]){
Scanner ob=new Scanner(System.in);
int tt=ob.nextInt();
out:for(int t=0;t<tt;t++){
String s=ob.next();
Vector<Character> v=new Vector();
//System.out.println(v);
for(int j=0;j<s.length();j++){
v.add(s.charAt(j));
//System.out.println(v);
char c=s.charAt(j);
if(c=='R'){
if(!v.contains('r')){
System.out.println("NO");
continue out;
}
}
else if(c=='B'){
if(!v.contains('b')){
System.out.println("NO");
continue out;
}
}
else if(c=='G'){
if(!v.contains('g')){
System.out.println("NO");
continue out;
}
}
}
System.out.println("YES");
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | e98748ed911c2406aebb8d50caf51baa | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class DoorsAndKeys {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int r=0;
int g=0;
int b=0;
int t=input.nextInt();
for (int i = 0; i < t; i++) {
String st= input.next();
if(st.indexOf("r")<st.indexOf("R"))
r++;
if(st.indexOf("g")<st.indexOf("G"))
g++;
if(st.indexOf("b")<st.indexOf("B"))
b++;
if(r>0&&g>0&&b>0)
System.out.println("YES");
else
System.out.println("NO");
r=0;
g=0;
b=0;
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 9905215158a0465169775196fd6a5654 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class DoorsAndKeys {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int r=0;
int g=0;
int b=0;
int t=input.nextInt();
for (int i = 0; i < t; i++) {
String st= input.next();
if(st.indexOf("r")<st.indexOf("R"))
r++;
else if(st.indexOf("r")>st.indexOf("R"))
r--;
if(st.indexOf("g")<st.indexOf("G"))
g++;
else if(st.indexOf("g")>st.indexOf("G"))
g--;
if(st.indexOf("b")<st.indexOf("B"))
b++;
else if(st.indexOf("b")>st.indexOf("B"))
b--;
if(r==g&&g==b&&r>0&&g>0&&b>0)
System.out.println("YES");
else
System.out.println("NO");
r=0;
g=0;
b=0;
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | f9d9edb6546d639bf25e537bf120aace | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
try {
FastReader sc= new FastReader();
int T=sc.nextInt();
while(T>0)
{
String s=sc.nextLine();
int[]k=new int[3];
int f=0;
for(char ch:s.toCharArray())
{
if(ch=='r')
{
k[0]=-1;
}
else if(ch=='g')
{
k[1]=-1;
}
else if(ch=='b')
{
k[2]=-1;
}
else if(ch=='R')
{
if(k[0]==0)
{
f=-1;
System.out.println("NO");
break;
}
}
else if(ch=='G')
{
if(k[1]==0)
{
f=-1;
System.out.println("NO");
break;
}
}
else{
if(k[2]==0)
{
f=-1;
System.out.println("NO");
break;
}
}
}
if(f==-1)
continue;
System.out.println("YES");
T--;
}
}
catch(Exception e)
{
return ;
}
}
}
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 | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 7d630814d40db9d6594108704a8c9ab5 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;
public class A_Doors_and_Keys
{
public static void main (String[] args) throws java.lang.Exception
{
try {
FastReader sc= new FastReader();
int T=sc.nextInt();
while(T>0)
{
String s=sc.nextLine();
int[]k=new int[3];
int f=0;
for(char ch:s.toCharArray())
{
if(ch=='r')
{
k[0]=-1;
}
else if(ch=='g')
{
k[1]=-1;
}
else if(ch=='b')
{
k[2]=-1;
}
else if(ch=='R')
{
if(k[0]==0)
{
f=-1;
System.out.println("NO");
break;
}
}
else if(ch=='G')
{
if(k[1]==0)
{
f=-1;
System.out.println("NO");
break;
}
}
else{
if(k[2]==0)
{
f=-1;
System.out.println("NO");
break;
}
}
}
if(f==-1)
continue;
System.out.println("YES");
T--;
}
}
catch(Exception e)
{
return ;
}
}
}
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 | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 906f0161f27ff17bcdbf07dde7cb5d72 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String[] args)throws java.lang.Exception {
Scanner sc=new Scanner(System.in);
int t;
t=sc.nextInt();
while(t-->0)
{
String s=sc.next();
if(s.indexOf('B')>s.indexOf('b')&&s.indexOf('G')>s.indexOf('g')&&s.indexOf('R')>s.indexOf('r'))
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | fd5b6f4c241c7a236ea694caf431723b | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class EDA {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Scanner sc1 = new Scanner(System.in);
int t = sc.nextInt();
// sc.close();
while(t-->0) {
String str = sc.next();
boolean isRed = false;
boolean isBlue= false;
boolean isGreen = false;
int ans = 0;
if(str.startsWith("R") || str.startsWith("G") || str.startsWith("B")){
System.out.println("NO");
}else{
int n = str.length();
int ind=0;
while(n-->0){
if(str.charAt(ind)=='r'){
isRed=true;
//System.out.println("red");
}
else if(str.charAt(ind)=='g'){
isGreen=true;
//System.out.println("green");
}
else if(str.charAt(ind)=='b'){
isBlue=true;
//System.out.println("blue");
}
else{
if(str.charAt(ind)=='R'){
// System.out.println("R");
if(isRed){
ans++;
}
}
else if(str.charAt(ind)=='G'){
if(isGreen){
ans++;
}
}else if(str.charAt(ind)=='B'){
//System.out.println("B");
if(isBlue){
ans++;
}
}
}
ind++;
}
if(ans==3){
System.out.println("YES");
}else{
System.out.println("No");
}
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 0b9be8811bc440ef0c6f4bb3d49e98ff | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class A {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
for( int i = 0; i < n; i++ ) {
Map<Character, Integer> map = new HashMap<>();
String temp = sc.next();
char[] list = temp.toCharArray();
for( int j = 0; j < list.length; j++ ) {
map.put(list[j], j);
}
if( map.get('R') < map.get('r') || map.get('G') < map.get('g') ||
map.get('B') < map.get('b')) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | e1e4bc7417773df2c99119c16bf7219a | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++){
String s = sc.next();
int a=0,b=0,c=0,d=0,e=0,f=0;
for(int j=0;j<s.length();j++){
if(s.charAt(j)=='r'){
a=j;
}
else if(s.charAt(j)=='R'){
b=j;
}
else if(s.charAt(j)=='b'){
c=j;
}
else if(s.charAt(j)=='B'){
d=j;
}
else if(s.charAt(j)=='g'){
e=j;
}
else{
f=j;
}
}
if((b-a)>0 && (d-c)>0 && (f-e)>0){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | da408697e90ae84eae6d0647ecb407ad | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int testCasesCount=s.nextInt();
for (int t = 0; t <testCasesCount ; t++) {
String input=s.next();
boolean isAllOpen=true;
for (int step = 0; step < input.length(); step++) {
String ch= String.valueOf(input.charAt(step));
if(ch.equals("R") ||ch.equals("B") ||ch.equals("G")){
//so we are in front of a door
String substr=input.substring(0,step);
if(!substr.contains(ch.toLowerCase())){
isAllOpen=false;
break;
}
}
}
System.out.println(isAllOpen?"YES":"NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 579a0fd63d0e8486ab7e12e2bd35d3b0 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
public class esep
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
while(n-->0)
{
String s = sc.nextLine();
System.out.println(is(s) ? "YES" : "NO");
}
}
public static boolean is(String s)
{
HashSet<Character> set = new HashSet<>();
for (int i = 0; i < s.length(); i++)
{
if(Character.isLowerCase(s.charAt(i))) set.add(s.charAt(i));
else if(!set.contains(Character.toLowerCase(s.charAt(i)))) return false;
}
return true;
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | d456dafb6b0e69a784740a4b3ac29f9d | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.math.BigInteger;
import java.util.*;
public class esep
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
while(n-->0)
{
String s = sc.nextLine();
System.out.println(is(s) ? "YES" : "NO");
}
}
public static boolean is(String s)
{
HashSet<Character> set = new HashSet<>();
for (int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == 'r' || s.charAt(i) == 'g' || s.charAt(i) == 'b') set.add(s.charAt(i));
else if(!set.contains(Character.toLowerCase(s.charAt(i)))) return false;
}
return true;
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 66fd0bbece1a64e8ad7712f90dc9e543 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int r = 0, g = 0, b = 0, R = 0, G = 0, B = 0;
for (int i = 0; i < n; i++) {
String str = in.next();
for (int j = 0; j < str.length(); j++) {
if (str.charAt(j) == 'R')
R = j;
if (str.charAt(j) == 'r')
r = j;
if (str.charAt(j) == 'G')
G = j;
if (str.charAt(j) == 'g')
g = j;
if (str.charAt(j) == 'B')
B = j;
if (str.charAt(j) == 'b')
b = j;
}
if (R > r && G > g && B > b)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 52a4b7291d2cc57166523d5161e2a014 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.util.Scanner;
public class DoorsAndKeys {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int testCase = Integer.parseInt(input.nextLine());
for(int i=0; i<testCase; i++){
String map = input.nextLine();
if(map.indexOf("R")<map.indexOf("r") || map.indexOf("G")<map.indexOf("g") || map.indexOf("B")<map.indexOf("b"))
System.out.println("NO");
else System.out.println("YES");
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 0353b57ee880efc2a50d5a0ee6aa6f03 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
while (t-- > 0)
{
String s = sc.nextLine();
int n = s.length();
if (calculate(s , n) == true)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
public static boolean calculate (String s , int n)
{
ArrayList<Character> list = new ArrayList<>();
for (int i=0; i<n; i++)
{
char ch = s.charAt(i);
if (ch == 'R' || ch == 'B' || ch == 'G')
{
if (!list.contains(Character.toLowerCase(ch)))
return false;
}
list.add(ch);
}
return true;
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 246179dccff02f794513ff482840bf67 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class DataStructure{
public static void main(String []args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String []arr=new String [n];
int i,j=0;
for(i=0;i<=n-1;i++){
arr[i]=sc.next();
}
for(i=0;i<=n-1;i++){
outer:
for(j=0;j<=5;j++){
for(int k=0;k<j;k++)
if(Character.toLowerCase(arr[i].charAt(k))==arr[i].charAt(j)){
System.out.println("NO");
break outer;
}
}
if(j==6)
System.out.println("YES");
sc.close();
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 1537a89bab24812de21ae254bad2e06a | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class tri {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num1=input.nextInt();
String[] aaa=new String[num1];
for (String x: aaa) {
x =input.next();
if (x.indexOf('r')<x.indexOf("R")&&x.indexOf('b')<x.indexOf("B")&&x.indexOf('g')<x.indexOf("G") ) {
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | d93b1132ce9e4ab6d02c13613f19e6cd | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.io.*;
import java.util.*;
public final class Main {
//int 2e9 - long 9e18
static PrintWriter out = new PrintWriter(System.out);
static FastReader in = new FastReader();
static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)};
static int mod = (int) (1e9 + 7);
static int mod2 = 998244353;
public static void main(String[] args) {
int tt = i();
while (tt-- > 0) {
solve();
}
out.flush();
}
public static void solve() {
String s = s();
if (s.indexOf('r') < s.indexOf('R') && s.indexOf('g') < s.indexOf('G') && s.indexOf('b') < s.indexOf('B')) {
out.println("YES");
} else {
out.println("NO");
}
}
// (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 int i() {
return in.nextInt();
}
static long l() {
return in.nextLong();
}
static double d() {
return in.nextDouble();
}
static String s() {
return in.nextLine();
}
static String c() {
return in.next();
}
static int[][] inputWithIdx(int N) {
int A[][] = new int[N][2];
for (int i = 0; i < N; i++) {
A[i] = new int[]{i, in.nextInt()};
}
return A;
}
static int[] input(int N) {
int A[] = new int[N];
for (int i = 0; i < N; i++) {
A[i] = in.nextInt();
}
return A;
}
static long[] inputLong(int N) {
long A[] = new long[N];
for (int i = 0; i < A.length; i++) {
A[i] = in.nextLong();
}
return A;
}
static int GCD(int a, int b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
static long GCD(long a, long b) {
if (b == 0) {
return a;
} else {
return GCD(b, a % b);
}
}
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) {
for (int i = 0; i < arr.length / 2; i++) {
int tmp = arr[i];
arr[arr.length - 1 - i] = tmp;
arr[i] = arr[arr.length - 1 - i];
}
}
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 | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | c562bfa8c427f8e5447c33832954abb2 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
public class I {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0) {
char[] a = sc.next().toCharArray();
int cnt = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 6; j++) {
if (a[j] - a[i] == -32) cnt++;
}
}
if (cnt == 3) out.println("YES");
else out.println("NO");
}
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public int[] readArr(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(next());
}
return arr;
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 45048adbdba9198df09da611e0336ba6 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
public class Main {
public static void main(String[]args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t-- > 0) {
String s = br.readLine();
if((s.indexOf('r') < s.indexOf('R'))&&(s.indexOf('g') < s.indexOf('G'))&&(s.indexOf('b') < s.indexOf('B')))
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 06d2692686a0c490b4576d553de503db | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
import java.io.*;
public class solution {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
try {
br = new BufferedReader(
new FileReader("input.txt"));
PrintStream out = new PrintStream(new FileOutputStream("output.txt"));
System.setOut(out);
} catch (Exception e) {
br = new BufferedReader(new InputStreamReader(System.in));
}
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static FastReader sc = new FastReader();
public static void main(String[] args) {
long t=sc.nextLong();
while(t--!=0) {
String s=sc.next();int flag=0;
Set<Character> set=new HashSet<>();
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='r' || s.charAt(i)=='b'||s.charAt(i)=='g') {
set.add(s.charAt(i));
}
else if(s.charAt(i)=='R') {
if(!set.contains('r')) {
flag=1;break;
}
}
else if(s.charAt(i)=='B') {
if(!set.contains('b')) {
flag=1;break;
}
}
else if(s.charAt(i)=='G') {
if(!set.contains('g')) {
flag=1;break;
}
}
}
if(flag==0) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}//END OF MAIN METHOD
}//END OF MAIN CLASS
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | f9ec758213529923679f04f4bacac2a8 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class cpSolutions {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static FastReader sc=new FastReader();
static Scanner in=new Scanner(System.in);
public static void main(String[] args) {
long t=sc.nextLong();
while(t--!=0) {
String s=sc.next();int flag=0;
Set<Character> set=new HashSet<>();
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='r' || s.charAt(i)=='b'||s.charAt(i)=='g') {
set.add(s.charAt(i));
}
else if(s.charAt(i)=='R') {
if(!set.contains('r')) {
flag=1;break;
}
}
else if(s.charAt(i)=='B') {
if(!set.contains('b')) {
flag=1;break;
}
}
else if(s.charAt(i)=='G') {
if(!set.contains('g')) {
flag=1;break;
}
}
}
if(flag==0) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
} //END OF MAIN MEHTOD
} //END OF MAIN CLASS
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 77e4a936a7d3abfa70d0147412f3684e | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class z1644a {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for(int i=0; i<t; i++) {
String s = br.readLine();
int j = 0;
boolean good = true;
while(good) {
if(j == s.length()) {
break;
}
char c = s.charAt(j);
if(Character.isUpperCase(c)) {
int k = j;
boolean find = false;
while(k>=0) {
if(s.charAt(k) == Character.toLowerCase(c)) {
find = true;
break;
}
k--;
}
if(find) {
j++;
}
else {
good = false;
}
}
else {
j++;
}
}
if(good) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | a7df2d016d37f6a207ff3f1d02bb5884 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class z1644a {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
for(int i=0; i<t; i++) {
String s = br.readLine();
int j = 0;
boolean good = true;
while(good) {
if(j == s.length()) {
break;
}
char c = s.charAt(j);
if(Character.isUpperCase(c)) {
int k = j;
boolean find = false;
while(k>=0) {
if(s.charAt(k) == Character.toLowerCase(c)) {
find = true;
break;
}
k--;
}
if(find) {
j++;
}
else {
good = false;
}
}
else {
j++;
}
}
if(good) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | e62dcf6cd2cd728ca2b36cfe156bba99 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class CF {
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
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;
}
}
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int test = sc.nextInt();
while (test-- > 0) {
String path = sc.next();
solve(path);
}
out.close();
}
private static void solve(String path) {
Set<Character> keys = new HashSet<>();
boolean flag = true;
for (int i = 0; i < path.length(); i++) {
char ch = path.charAt(i);
if (Character.isLowerCase(ch)) {
keys.add(ch);
} else {
if (!keys.contains(Character.toLowerCase(ch))) {
flag = false;
System.out.println("NO");
break;
}
}
}
if (flag) System.out.println("YES");
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 8916d24b8182a3cbba5da65d000672a5 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | /*package whatever //do not write package name here */
import java.util.*;
public class GFG {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int o=0;o<t;o++){
boolean flag=true;
String s=sc.next();
char[] ch=s.toCharArray();
int r=0,g=0,b=0;
for(int i=0;i<ch.length;i++){
if(ch[i]=='r') r++;
if(ch[i]=='g') g++;
if(ch[i]=='b') b++;
if(ch[i]=='R'){
if(r==0){
flag=false;
}
}
if(ch[i]=='G'){
if(g==0){
flag=false;
}
}
if(ch[i]=='B'){
if(b==0){
flag=false;
}
}
}
if(flag==false) System.out.println("NO");
else System.out.println("YES");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 77d1c86496514943d8b018621891ff73 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | /*package whatever //do not write package name here */
import java.util.*;
public class GFG {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int o=0;o<t;o++){
boolean flag=true;
String s=sc.next();
char[] ch=s.toCharArray();
int r=0,g=0,b=0;
for(int i=0;i<ch.length;i++){
if(ch[i]=='r') r++;
else if(ch[i]=='g') g++;
else if(ch[i]=='b') b++;
else if(ch[i]=='R'){
if(r==0){
flag=false;
}
}
else if(ch[i]=='G'){
if(g==0){
flag=false;
}
}
else if(ch[i]=='B'){
if(b==0){
flag=false;
}
}
}
if(flag==false) System.out.println("NO");
else System.out.println("YES");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | d68269dfb5115acf93dd270c2ca81da1 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.HashSet;
import java.util.Scanner;
public class DoorsAndKeys {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
String s = sc.next();
int charCount = 0;
HashSet<Character> hs = new HashSet();
for(int i = 0; i < s.length(); i++) {
hs.add(s.charAt(i));
if(s.charAt(i) == 'R' && hs.contains('r')) {
charCount++;
}
if(s.charAt(i) == 'G' && hs.contains('g')) {
charCount++;
}
if(s.charAt(i) == 'B' && hs.contains('b')) {
charCount++;
}
}
if(charCount == 3) System.out.println("YES");
else System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | f6cd91ded6546e4f62062dcb79e3b3b3 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class A {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
Stack res = new Stack<>();
Stack results = new Stack<>();
for(int i=0;i<n;i++){
String hm = s.next();
res.push(hm);
}
while(!res.isEmpty()){
results.push(res.pop());
}
while(!results.isEmpty()){
String a = (String) results.pop();
StringBuffer str = new StringBuffer();
Stack stk = new Stack<>();
for (int j = 0; j < a.length(); j++){
str.append(a.charAt(j));
}
for (int j = a.length()-1; j >= 0; j--){
stk.push(a.charAt(j));
}
// System.out.println(stk);
boolean r = false;
boolean g = false;
boolean b = false;
String x = "rgb";
while(!stk.isEmpty()){
char tmp = (char) stk.pop();
String gg = Character.toString(tmp);
// System.out.println(stk);
// System.out.println(x.contains(gg));
// System.out.println(stk.contains(Character.toUpperCase(gg.charAt(0))));
// System.out.println(Character.toUpperCase(gg.charAt(0)));
if(x.contains(gg) && stk.contains(Character.toUpperCase(gg.charAt(0)))){
if(tmp == 'r'){
r = true;
}else if(tmp == 'g'){
g = true;
}else if(tmp == 'b'){
b = true;
}
}
if (r && g && b){
System.out.println("YES");
break;
}
}
if(!r || !g || !b){
System.out.println("NO");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 0e103ad20ac780ec945cc27765f638f9 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | //package CodeForces;
import java.util.*;
public class Main {
public static void main(String[] arg) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
String s = sc.next();
if(Character.isUpperCase(s.charAt(0)))
System.out.println("NO");
else {
int cnt = 0;
for(int i = 0;i < 5;i++) {
for(int j = i + 1;j < 6;j++) {
char check = s.toLowerCase().charAt(j);
if(s.charAt(i) == check) {
cnt++;
break;
}
}
if(cnt == 3)
break;
}
if(cnt == 3)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 4126ff4ba66138abd739a5198b5ac53f | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String[] args)throws java.lang.Exception {
Scanner sc=new Scanner(System.in);
int t;
t=sc.nextInt();
while(t-->0)
{
String s=sc.next();
if(s.indexOf('B')>s.indexOf('b')&&s.indexOf('G')>s.indexOf('g')&&s.indexOf('R')>s.indexOf('r'))
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | a9e712f4748f04887093aca6bbc860ea | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.lang.*;
import java.io.InputStreamReader;
import static java.lang.Math.*;
import static java.lang.System.out;
import java.util.*;
import java.io.File;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.math.BigInteger;
public class Main {
/* 10^(7) = 1s.
* ceilVal = (a+b-1) / b */
static final int mod = 1000000007;
static final long temp = 998244353;
static final long MOD = 1000000007;
static final long M = (long)1e9+7;
static class Pair implements Comparable<Pair>
{
int first, second;
public Pair(int first, int second)
{
this.first = first;
this.second = second;
}
public int compareTo(Pair ob)
{
return (int)(first - ob.first);
}
}
static class Tuple implements Comparable<Tuple>
{
long first, second,third;
public Tuple(long first, long second, long third)
{
this.first = first;
this.second = second;
this.third = third;
}
public int compareTo(Tuple o)
{
return (int)(o.third - this.third);
}
}
public static class DSU
{
int count = 0;
int[] parent;
int[] rank;
public DSU(int n)
{
count = n;
parent = new int[n];
rank = new int[n];
Arrays.fill(parent, -1);
Arrays.fill(rank, 1);
}
public int find(int i)
{
return parent[i] < 0 ? i : (parent[i] = find(parent[i]));
}
public void union(int a, int b) //Union Find by Rank
{
a = find(a);
b = find(b);
if(a == b) return;
if(rank[a] < rank[b])
{
parent[a] = b;
}
else if(rank[a] > rank[b])
{
parent[b] = a;
}
else
{
parent[b] = a;
rank[a] = 1 + rank[a];
}
count--;
}
public int countConnected()
{
return count;
}
}
static class Reader
{
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) throws IOException {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long[] longReadArray(int n) throws IOException {
long[] a=new long[n];
for (int i=0; i<n; i++) a[i]=nextLong();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static int gcd(int a, int b)
{
if(b == 0)
return a;
else
return gcd(b,a%b);
}
public static long lcm(long a, long b)
{
return (a / LongGCD(a, b)) * b;
}
public static long LongGCD(long a, long b)
{
if(b == 0)
return a;
else
return LongGCD(b,a%b);
}
public static long LongLCM(long a, long b)
{
return (a / LongGCD(a, b)) * b;
}
//Count the number of coprime's upto N
public static long phi(long n) //euler totient/phi function
{
long ans = n;
// for(long i = 2;i*i<=n;i++)
// {
// if(n%i == 0)
// {
// while(n%i == 0) n/=i;
// ans -= (ans/i);
// }
// }
//
// if(n > 1)
// {
// ans -= (ans/n);
// }
for(long i = 2;i<=n;i++)
{
if(isPrime(i))
{
ans -= (ans/i);
}
}
return ans;
}
public static long fastPow(long x, long n)
{
if(n == 0)
return 1;
else if(n%2 == 0)
return fastPow(x*x,n/2);
else
return x*fastPow(x*x,(n-1)/2);
}
public static long powMod(long x, long y, long p)
{
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 modInverse(long n, long p)
{
return powMod(n, p - 2, p);
}
// Returns nCr % p using Fermat's little theorem.
public static long nCrModP(long n, long r,long p)
{
if (n<r)
return 0;
if (r == 0)
return 1;
long[] fac = new long[(int)(n) + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[(int)(n)] * modInverse(fac[(int)(r)], p)
% p * modInverse(fac[(int)(n - r)], p)
% p)
% p;
}
public static long fact(long n)
{
long[] fac = new long[(int)(n) + 1];
fac[0] = 1;
for (long i = 1; i <= n; i++)
fac[(int)(i)] = fac[(int)(i - 1)] * i;
return fac[(int)(n)];
}
public static long nCr(long n, long k)
{
long ans = 1;
for(long i = 0;i<k;i++)
{
ans *= (n-i);
ans /= (i+1);
}
return ans;
}
//Modular Operations for Addition and Multiplication.
public static long perfomMod(long x)
{
return ((x%M + M)%M);
}
public static long addMod(long a, long b)
{
return perfomMod(perfomMod(a)+perfomMod(b));
}
public static long subMod(long a, long b)
{
return perfomMod(perfomMod(a)-perfomMod(b));
}
public static long mulMod(long a, long b)
{
return perfomMod(perfomMod(a)*perfomMod(b));
}
public static boolean isPrime(long n)
{
if(n == 1)
{
return false;
}
//check only for sqrt of the number as the divisors
//keep repeating so only half of them are required. So,sqrt.
for(int i = 2;i*i<=n;i++)
{
if(n%i == 0)
{
return false;
}
}
return true;
}
public static List<Long> SieveList(int n)
{
boolean prime[] = new boolean[(int)(n+1)];
Arrays.fill(prime, true);
List<Long> l = new ArrayList<>();
for (long p = 2; p*p<=n; p++)
{
if (prime[(int)(p)] == true)
{
for(long i = p*p; i<=n; i += p)
{
prime[(int)(i)] = false;
}
}
}
for (long p = 2; p<=n; p++)
{
if (prime[(int)(p)] == true)
{
l.add(p);
}
}
return l;
}
public static int countDivisors(int x)
{
int c = 0;
for(int i = 1;i*i<=x;i++)
{
if(x%i == 0)
{
if(x/i != i)
{
c+=2;
}
else
{
c++;
}
}
}
return c;
}
public static long log2(long n)
{
long ans = (long)(log(n)/log(2));
return ans;
}
public static boolean isPow2(long n)
{
return (n != 0 && ((n & (n-1))) == 0);
}
public static boolean isSq(int x)
{
long s = (long)Math.round(Math.sqrt(x));
return s*s==x;
}
/*
*
* >= <=
0 1 2 3 4 5 6 7
5 5 5 6 6 6 7 7
lower_bound for 6 at index 3 (>=)
upper_bound for 6 at index 6(To get six reduce by one) (<=)
*/
public static int LowerBound(int a[], int x)
{
int l=-1,r=a.length;
while(l+1<r)
{
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
public static int UpperBound(int a[], int x)
{
int l=-1, r=a.length;
while(l+1<r)
{
int m=(l+r)>>>1;
if(a[m]<=x) l=m;
else r=m;
}
return l+1;
}
public static void Sort(int[] a)
{
List<Integer> l = new ArrayList<>();
for (int i : a) l.add(i);
Collections.sort(l);
Collections.reverse(l); //Use to Sort decreasingly
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
public static void ssort(char[] a)
{
List<Character> l = new ArrayList<>();
for (char i : a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
public static void main(String[] args) throws Exception
{
Reader sc = new Reader();
PrintWriter fout = new PrintWriter(System.out);
int tt = sc.nextInt();
while(tt-- > 0)
{
char[] s = sc.next().toCharArray();
int n = s.length;
boolean flag = true;
boolean[] seen = new boolean[3];
for(int i = 0;i<n;i++)
{
if(s[i] == 'R')
{
if(seen[0] == false)
{
flag = false;
}
}
else if(s[i] == 'G')
{
if(seen[1] == false)
{
flag = false;
}
}
else if(s[i] == 'B')
{
if(seen[2] == false)
{
flag = false;
}
}
else if(s[i] == 'r') seen[0] = true;
else if(s[i] == 'g') seen[1] = true;
else if(s[i] == 'b') seen[2] = true;
}
fout.println((flag == true) ? "YES" : "NO");
}
fout.close();
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 950a23d5ba14083d0e23bf584aec1c6f | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int test_case = scanner.nextInt();
for (int i = 0; i < test_case; i++) {
char[] cases = scanner.next().toCharArray();
int pass_door = 0;
boolean r= false,g = false,b = false;
for(char k :cases){
if(k == 'r'){
r = true;
}else if( k == 'g'){
g = true;
}else if(k == 'b'){
b = true;
}else if(k == 'R'){
if(r){
pass_door++;
}else{
break;
}
}else if(k == 'B'){
if(b){
pass_door++;
}else{
break;
}
}else if(k == 'G'){
if(g){
pass_door++;
}else{
break;
}
}
}
if(pass_door == 3){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 2f590fb5150c6b3649e9d5ef4559ba94 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class CoinChange {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0) {
String str = sc.next();
int r = 0, g= 0, b= 0;
boolean isPossible = true;
for(int i = 0; i < str.length(); i++) {
if(r == 0 && str.charAt(i) == 'R' || g == 0 && str.charAt(i) == 'G' || b == 0 && str.charAt(i) == 'B') {
isPossible = false;
break;
}
if(str.charAt(i) == 'r') r++;
else if(str.charAt(i) == 'g') g++;
else if(str.charAt(i) == 'b') b++;
}
if(isPossible) System.out.println("YES");
else System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 14a673d30a909ff35762d4ab43b5cf2e | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Doors{
public static boolean check(String s){
for(int j=0;j<6;j++){
if(Character.isLowerCase(s.charAt(j)) && s.indexOf(s.charAt(j))>s.indexOf(Character.toUpperCase(s.charAt(j)))){
return false;
}
}
return true;
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
boolean[] ans=new boolean[T];
for(int i=0;i<T;i++){
String s=sc.next();
ans[i]=check(s);
}
for(int i=0;i<T;i++){
if(ans[i])
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | bcf96073f42f716452141a8f3fe84206 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
scanner.nextLine();
for (int i = 0; i < n; i++) {
String s = scanner.nextLine();
boolean r = false;
boolean g = false;
boolean b = false;
boolean success = false;
for (int j = 0; j < s.length(); j++) {
char c = s.charAt(j);
if (c == 'r') r = true;
else if (c == 'g') g = true;
else if (c == 'b') b = true;
else if (c == 'R' && !r) break;
else if (c == 'G' && !g) break;
else if (c == 'B' && !b) break;
if (j == s.length() - 1) {
success = true;
}
}
if (success) System.out.println("YES");
else System.out.println("NO");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | d3fe2bc3eee1865492b47439c7b640fc | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.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();
}
}
static boolean isPalindrome(int arr[])
{
int i=0;int j=arr.length-1;
while(i<j)
{
if(arr[i]!=arr[j])
return false;
i++;j--;
}
return true;
}
static boolean isPrime(int n)
{
boolean bool[]=new boolean[n+1];
for(int i=0;i<bool.length;i++)
bool[i]=true;
for(int i=2;i<=Math.sqrt(n);i++)
{
for(int j=i*i;j<=n;j+=i)
bool[j]=false;
}
for(int i=2;i<bool.length;i++)
{
if(bool[i]==true)
{
if(i==n)
return true;
}
}
return false;
}
static long gcd(long a,long b)
{
if(a==0)
return b;
if(b==0)
return a;
return gcd(b%a,a);
}
static boolean isPowerOf2(int n)
{
if((n&(n-1))==0)
return true;
return false;
}
static int countSetBits(int n) //Brian Kernighan’s Algorithm
{
int cnt=0;
while(n>0)
{
n&=(n-1);
cnt++;
}
return cnt;
}
public static void main(String[] args) {
try {
FastReader sc=new FastReader();
FastWriter out = new FastWriter();
int testCases=sc.nextInt();
while(testCases-- > 0){
String s=sc.next();
HashMap<Character,Integer>map=new HashMap<>();
int flag=0;
for(int i=0;i<s.length();i++)
{
map.put(s.charAt(i),i);
}
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)=='r')
{
int x=map.get('R');
if(i>x)
{
flag=1;
out.println("No");
break;
}
}
else if(s.charAt(i)=='g')
{
int x=map.get('G');
if(i>x)
{
flag=1;
out.println("No");
break;
}
}
else if(s.charAt(i)=='b')
{
int x=map.get('B');
if(i>x)
{
flag=1;
out.println("No");
break;
}
}
}
if(flag==0)
out.println("Yes");
}
out.close();
} catch (Exception e) {
return;
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 76d52ba05199829d159a2fb67f94ba56 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class T1644A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = Integer.parseInt(in.nextLine());
for (int i = 0; i < t; i++) {
String line = in.nextLine();
if (line.indexOf("r") < line.indexOf("R") &&
line.indexOf("g") < line.indexOf("G") &&
line.indexOf("b") < line.indexOf("B")) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | d9432d74d0025dfc4fd5910520ec4e7a | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
public class Largest
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br=new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while(st==null || !st.hasMoreElements())
{
try
{
st=new StringTokenizer(br.readLine());
}
catch(IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
Double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str="";
try
{
str=br.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static int find_max(int[] arr)
{
int max=0;
int i=0;
while(i<arr.length)
{
if(arr[i]>arr[max]) max=i;
++i;
}
return max;
}
public static void main(String args[])
{
FastReader fr=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int T=fr.nextInt();
while(T-->0)
{
Set<Character> set=new HashSet<>();
String str=fr.nextLine();
int i=0;
boolean flag=false;
while(i<str.length())
{
if(str.charAt(i)=='R')
{
if(set.contains('r')==false)
{
flag=true;
out.println("NO");
break;
}
++i;
continue;
}
if(str.charAt(i)=='G')
{
if(set.contains('g')==false)
{
flag=true;
out.println("NO");
break;
}
++i;
continue;
}
if(str.charAt(i)=='B')
{
if(set.contains('b')==false)
{
flag=true;
out.println("NO");
break;
}
++i;
continue;
}
set.add(str.charAt(i));
++i;
}
if(flag==false)
out.println("YES");
}
out.close();
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 4d3e6967ed31bdd3d202fc3c61983124 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();
s.nextLine();
for(int i=0;i<t;i++){
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
String y=s.nextLine();
for(int j=0;j<6;j++){
if(y.charAt(j)=='r'){
a=j;
}
else if(y.charAt(j)=='b'){
b=j;
}
else if(y.charAt(j)=='g'){
c=j;
}
else if(y.charAt(j)=='R'){
d=j;
}
else if(y.charAt(j)=='B'){
e=j;
}
else if(y.charAt(j)=='G'){
f=j;
}
}
if((d>a)&&(e>b)&&(f>c)){
System.out.println("YES");
}
else{
System.out.println("NO");
}}}} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | ecbaf80272af3d0c2285452bdc01847e | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | //package r123div2;
import java.io.*;
public class Main {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in),30);
public static StreamTokenizer in = new StreamTokenizer(br);
public static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static int nextInt() throws IOException{ in.nextToken(); return (int)in.nval; }
public static String next() throws IOException{ in.nextToken(); return in.sval;}
public static void main(String[] args) throws IOException {
int N = nextInt();
while (N-->0){
String s = next();
char[] ch = s.toCharArray();
int[] hash = new int[3];
int[] res = new int[3];
for (char c : ch) {
if(c=='r'){
hash[0]++;
}else if(c=='b') {
hash[1]++;
}else if(c=='g'){
hash[2]++;
}
if(c=='R'){
if(hash[0]>0){
res[0]++;
}
}
if(c=='B'){
if(hash[1]>0){
res[1]++;
}
}
if(c=='G'){
if(hash[2]>0){
res[2]++;
}
}
}
if(res[0]>0&&res[1]>0&&res[2]>0){
out.println("YES");
}else {
out.println("NO");
}
}
out.flush();
out.close();
br.close();
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 0d3c23d28c4556f980659664d29e93f2 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | //package r123div2;
import java.io.*;
public final class Main {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in),30);
public static StreamTokenizer in = new StreamTokenizer(br);
public static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static int nextInt() throws IOException{ in.nextToken(); return (int)in.nval; }
public static String next() throws IOException{ in.nextToken(); return in.sval;}
public static void main(String[] args) throws IOException {
int N = nextInt();
while (N-->0){
String s = next();
char[] ch = s.toCharArray();
int[] hash = new int[3];
int[] res = new int[3];
for (char c : ch) {
if(c=='r'){
hash[0]++;
}else if(c=='b') {
hash[1]++;
}else if(c=='g'){
hash[2]++;
}
if(c=='R'){
if(hash[0]>0){
res[0]++;
}
}
if(c=='B'){
if(hash[1]>0){
res[1]++;
}
}
if(c=='G'){
if(hash[2]>0){
res[2]++;
}
}
}
if(res[0]>0&&res[1]>0&&res[2]>0){
out.println("YES");
}else {
out.println("NO");
}
}
out.flush();
out.close();
br.close();
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 9a2dc631b9016b6387ebf61994956946 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-->0){
String s = sc.next();
int doorR =0 ;
int doorG =0;
int doorB =0 ;
int keyR=0;
int keyG=0;
int keyB=0;
for( int i =0 ; i < s.length();i++){
char c = s.charAt(i);
if(c=='R')doorR=i;
else if(c=='G')doorG=i;
else if(c=='B')doorB=i;
else if(c=='r')keyR=i;
else if(c=='g')keyG=i;
else if(c=='b')keyB=i;
}
if(keyR>doorR){
System.out.println("NO");
continue;
}
else if(keyG>doorG){
System.out.println("NO");
continue;
}
if(keyB>doorB){
System.out.println("NO");
continue;
}
System.out.println("YES");
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | fdea65697d64d13e4b8979d8aaed48a0 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.IOException;
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t;
t = in.nextInt();
while (t != 0)
{
int n;
// n = in.nextInt();
ArrayList<Integer> a = new ArrayList<>(Arrays.asList(1, 3, 6, 7));
int r_small = 0, r_big = 0, g_small = 0, g_big = 0, b_small = 0, b_big = 0;
String s;
s = in.next();
String res = "YES";
for(int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == 'r')
{
r_small++;
} else if(s.charAt(i) == 'R')
{
r_small--;
if(r_small < 0 )
{
res = "NO";
break;
}
}
if(s.charAt(i) == 'g')
{
g_small++;
} else if(s.charAt(i) == 'G')
{
g_small--;
if(g_small < 0 )
{
res = "NO";
break;
}
}
if(s.charAt(i) == 'b')
{
b_small++;
} else if(s.charAt(i) == 'B')
{
b_small--;
if(b_small < 0 )
{
res = "NO";
break;
}
}
}
System.out.println(res);
t--;
}
}
}
/*
*
*
* public static int whatEverFunction(String hex)
{
int res = 0, pw = hex.length() - 1;
for (char ch: hex.toCharArray())
{
if(Character.isDigit(ch))
{
res += (ch - '0') * Math.pow(16, pw);
} else if (Character.isLetter(ch))
{
res += (ch - 'a' + 10) * Math.pow(16, pw);
}
pw--;
}
return res;
}
public static void testWhatEverFunction()
{
int res = whatEverFunction("aef56ff");
assert res == 183457535 : "Expected " + 183457535 + "but got " + res;
}
*
*
Scanner in = new Scanner(System.in);
int t;
t = in.nextInt();
while (t != 0)
{
int n;
n = in.nextInt();
ArrayList<Integer> a = new ArrayList<>(Arrays.asList(1, 3, 6, 7));
ArrayList<Integer> b = new ArrayList<>();
b = (ArrayList<Integer>) a.stream().map(number -> number * 3);
b.forEach(bE -> {
System.out.println(bE.toString());
});
t--;
}
* */
/*
UUID uuid = UUID.randomUUID();
System.out.println(uuid);*/
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | a7f79afba8edd4cf667aa30e350ccea7 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
public static void main(String args[]){
FScanner in = new FScanner();
PrintWriter out = new PrintWriter(System.out);
int t = in.nextInt();
m: while(t-->0) {
String s=in.next();
int r=0,g=0,b=0;
for(int i=0;i<s.length();i++)
{
char ch=s.charAt(i);
if(ch=='g')
g++;
else if(ch=='r')
r++;
else if(ch=='b')
b++;
else if(ch=='R'&&r==0)
{
out.println("NO");
continue m;
}
else if(ch=='G'&&g==0)
{
out.println("NO");
continue m;
}
else if(ch=='B'&&b==0)
{
out.println("NO");
continue m;
}
}
out.println("YES");
}
out.close();
}
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);
}
static boolean checkprime(int n1)
{
if(n1%2==0||n1%3==0)
return false;
else
{
for(int i=5;i*i<=n1;i+=6)
{
if(n1%i==0||n1%(i+2)==0)
return false;
}
return true;
}
}
static class FScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer sb = new StringTokenizer("");
String next(){
while(!sb.hasMoreTokens()){
try{
sb = new StringTokenizer(br.readLine());
} catch(IOException e){ }
}
return sb.nextToken();
}
String nextLine(){
try{ return br.readLine(); }
catch(IOException e) { } return "";
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
int[] readArray(int n) {
int a[] = new int[n];
for(int i=0;i<n;i++) a[i] = nextInt();
return a;
}
float nextFloat(){
return Float.parseFloat(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 7b709bea0fb67920a2b1f2ad103184cb | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigDecimal;
import java.math.*;
//
public class Main{
public static void main(String[] args) {
TaskA solver = new TaskA();
// boolean[]prime=seive(3*100001);
int t = in.nextInt();
for (int i = 1; i <= t ; i++) {
solver.solve(1, in, out);
}
// solver.solve(1, in, out);
out.flush();
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
String s= in.next();
if(s.indexOf('R')<s.indexOf('r')) {
println("NO");return;
}
else if(s.indexOf('G')<s.indexOf('g')){
println("NO");return;
}
else if(s.indexOf('B')<s.indexOf('b')){
println("NO");return;
}
println("YES");
}
}
static long ceil(long a,long b) {
return (a/b + Math.min(a%b, 1));
}
static char[] rev(char[]ans,int n) {
for(int i=ans.length-1;i>=n;i--) {
ans[i]=ans[ans.length-i-1];
}
return ans;
}
static int countStep(int[]arr,long sum,int k,int count1) {
int count=count1;
int index=arr.length-1;
while(sum>k&&index>0) {
sum-=(arr[index]-arr[0]);
count++;
if(sum<=k) {
break;
}
index--;
// println("c");
}
if(sum<=k) {
return count;
}
else {
return Integer.MAX_VALUE;
}
}
static long pow(long b, long e) {
long ans = 1;
while (e > 0) {
if (e % 2 == 1)
ans = ans * b % mod;
e >>= 1;
b = b * b % mod;
}
return ans;
}
static void sortDiff(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{ if(p1.first==p2.first) {
return (p1.second-p1.first)-(p2.second-p1.first);
}
return (p1.second-p1.first)-(p2.second-p2.first);
}
});
}
static void sortF(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{ if(p1.first==p2.first) {
return p1.second-p2.second;
}
return p1.first - p2.first;
}
});
}
static int[] shift (int[]inp,int i,int j){
int[]arr=new int[j-i+1];
int n=j-i+1;
for(int k=i;k<=j;k++) {
arr[(k-i+1)%n]=inp[k];
}
for(int k=0;k<n;k++ ) {
inp[k+i]=arr[k];
}
return inp;
}
static long[] fac;
static long mod = (long) 1000000007;
static void initFac(long n) {
fac = new long[(int)n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = (fac[i - 1] * i) % mod;
}
}
static long nck(int n, int k) {
if (n < k)
return 0;
long den = inv((int) (fac[k] * fac[n - k] % mod));
return fac[n] * den % mod;
}
static long inv(long x) {
return pow(x, mod - 2);
}
static void sort(int[] a) {
ArrayList<Integer> q = new ArrayList<>();
for (int i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
static void sort(long[] a) {
ArrayList<Long> q = new ArrayList<>();
for (long i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
public static int bfsSize(int source,LinkedList<Integer>[]a,boolean[]visited) {
Queue<Integer>q=new LinkedList<>();
q.add(source);
visited[source]=true;
int distance=0;
while(!q.isEmpty()) {
int curr=q.poll();
distance++;
for(int neighbour:a[curr]) {
if(!visited[neighbour]) {
visited[neighbour]=true;
q.add(neighbour);
}
}
}
return distance;
}
public static Set<Integer>factors(int n){
Set<Integer>ans=new HashSet<>();
ans.add(1);
for(int i=2;i*i<=n;i++) {
if(n%i==0) {
ans.add(i);
ans.add(n/i);
}
}
return ans;
}
public static int bfsSp(int source,int destination,ArrayList<Integer>[]a) {
boolean[]visited=new boolean[a.length];
int[]parent=new int[a.length];
Queue<Integer>q=new LinkedList<>();
int distance=0;
q.add(source);
visited[source]=true;
parent[source]=-1;
while(!q.isEmpty()) {
int curr=q.poll();
if(curr==destination) {
break;
}
for(int neighbour:a[curr]) {
if(neighbour!=-1&&!visited[neighbour]) {
visited[neighbour]=true;
q.add(neighbour);
parent[neighbour]=curr;
}
}
}
int cur=destination;
while(parent[cur]!=-1) {
distance++;
cur=parent[cur];
}
return distance;
}
static int bs(int size,int[]arr) {
int x = -1;
for (int b = size/2; b >= 1; b /= 2) {
while (!ok(arr));
}
int k = x+1;
return k;
}
static boolean ok(int[]x) {
return false;
}
public static int solve1(ArrayList<Integer> A) {
long[]arr =new long[A.size()+1];
int n=A.size();
for(int i=1;i<=A.size();i++) {
arr[i]=((i%2)*((n-i+1)%2))%2;
arr[i]%=2;
}
int ans=0;
for(int i=0;i<A.size();i++) {
if(arr[i+1]==1) {
ans^=A.get(i);
}
}
return ans;
}
public static String printBinary(long a) {
String str="";
for(int i=31;i>=0;i--) {
if((a&(1<<i))!=0) {
str+=1;
}
if((a&(1<<i))==0 && !str.isEmpty()) {
str+=0;
}
}
return str;
}
public static String reverse(long a) {
long rev=0;
String str="";
int x=(int)(Math.log(a)/Math.log(2))+1;
for(int i=0;i<32;i++) {
rev<<=1;
if((a&(1<<i))!=0) {
rev|=1;
str+=1;
}
else {
str+=0;
}
}
return str;
}
////////////////////////////////////////////////////////
static void sortS(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
return p1.second - p2.second;
}
});
}
static class Pair implements Comparable<Pair>
{
int first ;int second ;
public Pair(int x, int y)
{
this.first = x ;this.second = y ;
}
@Override
public boolean equals(Object obj)
{
if(obj == this)return true ;
if(obj == null)return false ;
if(this.getClass() != obj.getClass()) return false ;
Pair other = (Pair)(obj) ;
if(this.first != other.first)return false ;
if(this.second != other.second)return false ;
return true ;
}
@Override
public int hashCode()
{
return this.first^this.second ;
}
@Override
public String toString() {
String ans = "" ;ans += this.first ; ans += " "; ans += this.second ;
return ans ;
}
@Override
public int compareTo(Main.Pair o) {
{ if(this.first==o.first) {
return this.second-o.second;
}
return this.first - o.first;
}
}
}
//////////////////////////////////////////////////////////////////////////
static int nD(long num) {
String s=String.valueOf(num);
return s.length();
}
static int CommonDigits(int x,int y) {
String s=String.valueOf(x);
String s2=String.valueOf(y);
return 0;
}
static int lcs(String str1, String str2, int m, int n)
{
int L[][] = new int[m + 1][n + 1];
int i, j;
// Following steps build L[m+1][n+1] in
// bottom up fashion. Note that L[i][j]
// contains length of LCS of str1[0..i-1]
// and str2[0..j-1]
for (i = 0; i <= m; i++) {
for (j = 0; j <= n; j++) {
if (i == 0 || j == 0)
L[i][j] = 0;
else if (str1.charAt(i - 1)
== str2.charAt(j - 1))
L[i][j] = L[i - 1][j - 1] + 1;
else
L[i][j] = Math.max(L[i - 1][j],
L[i][j - 1]);
}
}
// L[m][n] contains length of LCS
// for X[0..n-1] and Y[0..m-1]
return L[m][n];
}
/////////////////////////////////
boolean IsPowerOfTwo(int x)
{
return (x != 0) && ((x & (x - 1)) == 0);
}
////////////////////////////////
static long power(long a,long b,long m ) {
long ans=1;
while(b>0) {
if(b%2==1) {
ans=((ans%m)*(a%m))%m; b--;
}
else {
a=(a*a)%m;b/=2;
}
}
return ans%m;
}
///////////////////////////////
public static boolean repeatedSubString(String string) {
return ((string + string).indexOf(string, 1) != string.length());
}
static int search(char[]c,int start,int end,char x) {
for(int i=start;i<end;i++) {
if(c[i]==x) {return i;}
}
return -2;
}
////////////////////////////////
static long gcd(long a, long b) {
while (b != 0) {
long t = b;
b = a % b;
a = t;
}
return a;
}
static long fac(long a)
{
if(a== 0L || a==1L)return 1L ;
return a*fac(a-1L) ;
}
static ArrayList al() {
ArrayList<Integer>a =new ArrayList<>();
return a;
}
static HashSet h() {
return new HashSet<Integer>();
}
static void debug(int[][]a) {
int n= a.length;
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
out.print(a[i][j]+" ");
}
out.print("\n");
}
}
static void debug(int[]a) {
out.println(Arrays.toString(a));
}
static void debug(ArrayList<Integer>a) {
out.println(a.toString());
}
static boolean[]seive(int n){
boolean[]b=new boolean[n+1];
for (int i = 2; i <= n; i++)
b[i] = true;
for(int i=2;i*i<=n;i++) {
if(b[i]) {
for(int j=i*i;j<=n;j+=i) {
b[j]=false;
}
}
}
return b;
}
static int longestIncreasingSubseq(int[]arr) {
int[]sizes=new int[arr.length];
Arrays.fill(sizes, 1);
int max=1;
for(int i=1;i<arr.length;i++) {
for(int j=0;j<i;j++) {
if(arr[j]<arr[i]) {
sizes[i]=Math.max(sizes[i],sizes[j]+1);
max=Math.max(max, sizes[i]);
}
}
}
return max;
}
public static ArrayList primeFactors(long n)
{
ArrayList<Long>h= new ArrayList<>();
// Print the number of 2s that divide n
if(n%2 ==0) {h.add(2L);}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (long i = 3; i <= Math.sqrt(n); i+= 2)
{
if(n%i==0) {h.add(i);}
}
if (n > 2)
h.add(n);
return h;
}
static boolean Divisors(long n){
if(n%2==1) {
return true;
}
for (long i=2; i<=Math.sqrt(n); i++){
if (n%i==0 && i%2==1){
return true;
}
}
return false;
}
static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static InputReader in = new InputReader(inputStream);
static PrintWriter out = new PrintWriter(outputStream);
public static void superSet(int[]a,ArrayList<String>al,int i,String s) {
if(i==a.length) {
al.add(s);
return;
}
superSet(a,al,i+1,s);
superSet(a,al,i+1,s+a[i]+" ");
}
public static long[] makeArr() {
long size=in.nextInt();
long []arr=new long[(int)size];
for(int i=0;i<size;i++) {
arr[i]=in.nextInt();
}
return arr;
}
public static long[] arr(int n) {
long []arr=new long[n+1];
for(int i=1;i<n+1;i++) {
arr[i]=in.nextLong();
}
return arr;
}
public static void sort(long arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
static void println(long x) {
out.println(x);
}
static void print(long c) {
out.print(c);
}
static void print(int c) {
out.print(c);
}
static void println(int x) {
out.println(x);
}
static void print(String s) {
out.print(s);
}
static void println(String s) {
out.println(s);
}
public static void merge(long arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
long L[] = new long[n1];
long R[] = new long[n2];
//Copy data to temp arrays
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
public static void reverse(int[] array)
{
int n = array.length;
for (int i = 0; i < n / 2; i++) {
int temp = array[i];
array[i] = array[n - i - 1];
array[n - i - 1] = temp;
}
}
public static long nCr(int n,int k)
{
long ans=1L;
k=k>n-k?n-k:k;
for( int j=1;j<=k;j++,n--)
{
if(n%j==0)
{
ans*=n/j;
}else
if(ans%j==0)
{
ans=ans/j*n;
}else
{
ans=(ans*n)/j;
}
}
return ans;
}
static int searchMax(int index,long[]inp) {
while(index+1<inp.length &&inp[index+1]>inp[index]) {
index+=1;
}
return index;
}
static int searchMin(int index,long[]inp) {
while(index+1<inp.length &&inp[index+1]<inp[index]) {
index+=1;
}
return index;
}
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
static class Pairr implements Comparable<Pairr>{
private int index;
private int cumsum;
private ArrayList<Integer>indices;
public Pairr(int index,int cumsum) {
this.index=index;
this.cumsum=cumsum;
indices=new ArrayList<Integer>();
}
public int compareTo(Pairr other) {
return Integer.compare(cumsum, other.cumsum);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | bc1121cfd308f046c8804f6db3db33f6 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigDecimal;
import java.math.*;
public class Main{
public static void main(String[] args) {
TaskA solver = new TaskA();
// boolean[]prime=seive(3*100001);
int t = in.nextInt();
for (int i = 1; i <= t ; i++) {
solver.solve(1, in, out);
}
// solver.solve(1, in, out);
out.flush();
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
String s= in.next();
if(s.indexOf('R')<s.indexOf('r')) {
println("NO");return;
}
else if(s.indexOf('G')<s.indexOf('g')){
println("NO");return;
}
else if(s.indexOf('B')<s.indexOf('b')){
println("NO");return;
}
println("YES");
}
}
static long ceil(long a,long b) {
return (a/b + Math.min(a%b, 1));
}
static char[] rev(char[]ans,int n) {
for(int i=ans.length-1;i>=n;i--) {
ans[i]=ans[ans.length-i-1];
}
return ans;
}
static int countStep(int[]arr,long sum,int k,int count1) {
int count=count1;
int index=arr.length-1;
while(sum>k&&index>0) {
sum-=(arr[index]-arr[0]);
count++;
if(sum<=k) {
break;
}
index--;
// println("c");
}
if(sum<=k) {
return count;
}
else {
return Integer.MAX_VALUE;
}
}
static long pow(long b, long e) {
long ans = 1;
while (e > 0) {
if (e % 2 == 1)
ans = ans * b % mod;
e >>= 1;
b = b * b % mod;
}
return ans;
}
static void sortDiff(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{ if(p1.first==p2.first) {
return (p1.second-p1.first)-(p2.second-p1.first);
}
return (p1.second-p1.first)-(p2.second-p2.first);
}
});
}
static void sortF(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{ if(p1.first==p2.first) {
return p1.second-p2.second;
}
return p1.first - p2.first;
}
});
}
static int[] shift (int[]inp,int i,int j){
int[]arr=new int[j-i+1];
int n=j-i+1;
for(int k=i;k<=j;k++) {
arr[(k-i+1)%n]=inp[k];
}
for(int k=0;k<n;k++ ) {
inp[k+i]=arr[k];
}
return inp;
}
static long[] fac;
static long mod = (long) 1000000007;
static void initFac(long n) {
fac = new long[(int)n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = (fac[i - 1] * i) % mod;
}
}
static long nck(int n, int k) {
if (n < k)
return 0;
long den = inv((int) (fac[k] * fac[n - k] % mod));
return fac[n] * den % mod;
}
static long inv(long x) {
return pow(x, mod - 2);
}
static void sort(int[] a) {
ArrayList<Integer> q = new ArrayList<>();
for (int i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
static void sort(long[] a) {
ArrayList<Long> q = new ArrayList<>();
for (long i : a) q.add(i);
Collections.sort(q);
for (int i = 0; i < a.length; i++) a[i] = q.get(i);
}
public static int bfsSize(int source,LinkedList<Integer>[]a,boolean[]visited) {
Queue<Integer>q=new LinkedList<>();
q.add(source);
visited[source]=true;
int distance=0;
while(!q.isEmpty()) {
int curr=q.poll();
distance++;
for(int neighbour:a[curr]) {
if(!visited[neighbour]) {
visited[neighbour]=true;
q.add(neighbour);
}
}
}
return distance;
}
public static Set<Integer>factors(int n){
Set<Integer>ans=new HashSet<>();
ans.add(1);
for(int i=2;i*i<=n;i++) {
if(n%i==0) {
ans.add(i);
ans.add(n/i);
}
}
return ans;
}
public static int bfsSp(int source,int destination,ArrayList<Integer>[]a) {
boolean[]visited=new boolean[a.length];
int[]parent=new int[a.length];
Queue<Integer>q=new LinkedList<>();
int distance=0;
q.add(source);
visited[source]=true;
parent[source]=-1;
while(!q.isEmpty()) {
int curr=q.poll();
if(curr==destination) {
break;
}
for(int neighbour:a[curr]) {
if(neighbour!=-1&&!visited[neighbour]) {
visited[neighbour]=true;
q.add(neighbour);
parent[neighbour]=curr;
}
}
}
int cur=destination;
while(parent[cur]!=-1) {
distance++;
cur=parent[cur];
}
return distance;
}
static int bs(int size,int[]arr) {
int x = -1;
for (int b = size/2; b >= 1; b /= 2) {
while (!ok(arr));
}
int k = x+1;
return k;
}
static boolean ok(int[]x) {
return false;
}
public static int solve1(ArrayList<Integer> A) {
long[]arr =new long[A.size()+1];
int n=A.size();
for(int i=1;i<=A.size();i++) {
arr[i]=((i%2)*((n-i+1)%2))%2;
arr[i]%=2;
}
int ans=0;
for(int i=0;i<A.size();i++) {
if(arr[i+1]==1) {
ans^=A.get(i);
}
}
return ans;
}
public static String printBinary(long a) {
String str="";
for(int i=31;i>=0;i--) {
if((a&(1<<i))!=0) {
str+=1;
}
if((a&(1<<i))==0 && !str.isEmpty()) {
str+=0;
}
}
return str;
}
public static String reverse(long a) {
long rev=0;
String str="";
int x=(int)(Math.log(a)/Math.log(2))+1;
for(int i=0;i<32;i++) {
rev<<=1;
if((a&(1<<i))!=0) {
rev|=1;
str+=1;
}
else {
str+=0;
}
}
return str;
}
////////////////////////////////////////////////////////
static void sortS(Pair arr[])
{
// Comparator to sort the pair according to second element
Arrays.sort(arr, new Comparator<Pair>() {
@Override public int compare(Pair p1, Pair p2)
{
return p1.second - p2.second;
}
});
}
static class Pair implements Comparable<Pair>
{
int first ;int second ;
public Pair(int x, int y)
{
this.first = x ;this.second = y ;
}
@Override
public boolean equals(Object obj)
{
if(obj == this)return true ;
if(obj == null)return false ;
if(this.getClass() != obj.getClass()) return false ;
Pair other = (Pair)(obj) ;
if(this.first != other.first)return false ;
if(this.second != other.second)return false ;
return true ;
}
@Override
public int hashCode()
{
return this.first^this.second ;
}
@Override
public String toString() {
String ans = "" ;ans += this.first ; ans += " "; ans += this.second ;
return ans ;
}
@Override
public int compareTo(Main.Pair o) {
{ if(this.first==o.first) {
return this.second-o.second;
}
return this.first - o.first;
}
}
}
//////////////////////////////////////////////////////////////////////////
static int nD(long num) {
String s=String.valueOf(num);
return s.length();
}
static int CommonDigits(int x,int y) {
String s=String.valueOf(x);
String s2=String.valueOf(y);
return 0;
}
static int lcs(String str1, String str2, int m, int n)
{
int L[][] = new int[m + 1][n + 1];
int i, j;
// Following steps build L[m+1][n+1] in
// bottom up fashion. Note that L[i][j]
// contains length of LCS of str1[0..i-1]
// and str2[0..j-1]
for (i = 0; i <= m; i++) {
for (j = 0; j <= n; j++) {
if (i == 0 || j == 0)
L[i][j] = 0;
else if (str1.charAt(i - 1)
== str2.charAt(j - 1))
L[i][j] = L[i - 1][j - 1] + 1;
else
L[i][j] = Math.max(L[i - 1][j],
L[i][j - 1]);
}
}
// L[m][n] contains length of LCS
// for X[0..n-1] and Y[0..m-1]
return L[m][n];
}
/////////////////////////////////
boolean IsPowerOfTwo(int x)
{
return (x != 0) && ((x & (x - 1)) == 0);
}
////////////////////////////////
static long power(long a,long b,long m ) {
long ans=1;
while(b>0) {
if(b%2==1) {
ans=((ans%m)*(a%m))%m; b--;
}
else {
a=(a*a)%m;b/=2;
}
}
return ans%m;
}
///////////////////////////////
public static boolean repeatedSubString(String string) {
return ((string + string).indexOf(string, 1) != string.length());
}
static int search(char[]c,int start,int end,char x) {
for(int i=start;i<end;i++) {
if(c[i]==x) {return i;}
}
return -2;
}
////////////////////////////////
static long gcd(long a, long b) {
while (b != 0) {
long t = b;
b = a % b;
a = t;
}
return a;
}
static long fac(long a)
{
if(a== 0L || a==1L)return 1L ;
return a*fac(a-1L) ;
}
static ArrayList al() {
ArrayList<Integer>a =new ArrayList<>();
return a;
}
static HashSet h() {
return new HashSet<Integer>();
}
static void debug(int[][]a) {
int n= a.length;
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
out.print(a[i][j]+" ");
}
out.print("\n");
}
}
static void debug(int[]a) {
out.println(Arrays.toString(a));
}
static void debug(ArrayList<Integer>a) {
out.println(a.toString());
}
static boolean[]seive(int n){
boolean[]b=new boolean[n+1];
for (int i = 2; i <= n; i++)
b[i] = true;
for(int i=2;i*i<=n;i++) {
if(b[i]) {
for(int j=i*i;j<=n;j+=i) {
b[j]=false;
}
}
}
return b;
}
static int longestIncreasingSubseq(int[]arr) {
int[]sizes=new int[arr.length];
Arrays.fill(sizes, 1);
int max=1;
for(int i=1;i<arr.length;i++) {
for(int j=0;j<i;j++) {
if(arr[j]<arr[i]) {
sizes[i]=Math.max(sizes[i],sizes[j]+1);
max=Math.max(max, sizes[i]);
}
}
}
return max;
}
public static ArrayList primeFactors(long n)
{
ArrayList<Long>h= new ArrayList<>();
// Print the number of 2s that divide n
if(n%2 ==0) {h.add(2L);}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (long i = 3; i <= Math.sqrt(n); i+= 2)
{
if(n%i==0) {h.add(i);}
}
if (n > 2)
h.add(n);
return h;
}
static boolean Divisors(long n){
if(n%2==1) {
return true;
}
for (long i=2; i<=Math.sqrt(n); i++){
if (n%i==0 && i%2==1){
return true;
}
}
return false;
}
static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static InputReader in = new InputReader(inputStream);
static PrintWriter out = new PrintWriter(outputStream);
public static void superSet(int[]a,ArrayList<String>al,int i,String s) {
if(i==a.length) {
al.add(s);
return;
}
superSet(a,al,i+1,s);
superSet(a,al,i+1,s+a[i]+" ");
}
public static long[] makeArr() {
long size=in.nextInt();
long []arr=new long[(int)size];
for(int i=0;i<size;i++) {
arr[i]=in.nextInt();
}
return arr;
}
public static long[] arr(int n) {
long []arr=new long[n+1];
for(int i=1;i<n+1;i++) {
arr[i]=in.nextLong();
}
return arr;
}
public static void sort(long arr[], int l, int r)
{
if (l < r)
{
// Find the middle point
int m = (l+r)/2;
// Sort first and second halves
sort(arr, l, m);
sort(arr , m+1, r);
// Merge the sorted halves
merge(arr, l, m, r);
}
}
static void println(long x) {
out.println(x);
}
static void print(long c) {
out.print(c);
}
static void print(int c) {
out.print(c);
}
static void println(int x) {
out.println(x);
}
static void print(String s) {
out.print(s);
}
static void println(String s) {
out.println(s);
}
public static void merge(long arr[], int l, int m, int r)
{
// Find sizes of two subarrays to be merged
int n1 = m - l + 1;
int n2 = r - m;
/* Create temp arrays */
long L[] = new long[n1];
long R[] = new long[n2];
//Copy data to temp arrays
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays */
// Initial indexes of first and second subarrays
int i = 0, j = 0;
// Initial index of merged subarry array
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy remaining elements of L[] if any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy remaining elements of R[] if any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
public static void reverse(int[] array)
{
int n = array.length;
for (int i = 0; i < n / 2; i++) {
int temp = array[i];
array[i] = array[n - i - 1];
array[n - i - 1] = temp;
}
}
public static long nCr(int n,int k)
{
long ans=1L;
k=k>n-k?n-k:k;
for( int j=1;j<=k;j++,n--)
{
if(n%j==0)
{
ans*=n/j;
}else
if(ans%j==0)
{
ans=ans/j*n;
}else
{
ans=(ans*n)/j;
}
}
return ans;
}
static int searchMax(int index,long[]inp) {
while(index+1<inp.length &&inp[index+1]>inp[index]) {
index+=1;
}
return index;
}
static int searchMin(int index,long[]inp) {
while(index+1<inp.length &&inp[index+1]<inp[index]) {
index+=1;
}
return index;
}
public class ListNode {
int val;
ListNode next;
ListNode() {}
ListNode(int val) { this.val = val; }
ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
static class Pairr implements Comparable<Pairr>{
private int index;
private int cumsum;
private ArrayList<Integer>indices;
public Pairr(int index,int cumsum) {
this.index=index;
this.cumsum=cumsum;
indices=new ArrayList<Integer>();
}
public int compareTo(Pairr other) {
return Integer.compare(cumsum, other.cumsum);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 26857ad2eb13468a26f5d6b0e4a1ab4d | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class p
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int t=scan.nextInt();
String temp=scan.nextLine();
for(int z=0;z<t;z++)
{
String s=scan.nextLine();
int r=0,g=0,b=0;
boolean x=true;
for(int i=0;i<s.length();i++)
{
char c=s.charAt(i);
if(c=='R' && r!=1 || c=='G' && g!=1 || c=='B' && b!=1)
x=false;
else if(c=='r')
r=1;
else if(c=='b')
b=1;
else if(c=='g')
g=1;
}
if(x)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 142c5aca4ecf474d947f51789e91b095 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
//Gaurav......
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import java.io.*;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.math.*;
public class Main {
//start
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int t=sc.nextInt();
while(t-->0){
String s=sc.next();
HashSet<Character> small = new HashSet<>();
boolean bool=false;
for(int i=0;i<s.length();i++){
char ch=s.charAt(i);
if(isUpper(ch)==true){
if(small.contains(toLower(ch))==false){
bool=true;}
}
else{
small.add(ch);
}
}
if(bool==true){
System.out.println("NO");
}else{
System.out.println("YES");
}
}
}
public static boolean isUpper(char ch){
if(ch>='A'&&ch<='Z'){
return true;
}
return false;
}
public static char toLower(char ch){
int val=(int)ch;
val+=32;
return (char)val;
}
//end
public static boolean funtion(String s1,String s2,int m,int n){
if(m==0){
return true;
}
if(n==0){
return false;
}
if(s1.charAt(m-1)==s2.charAt(n-1)){
return funtion(s1,s2,m-1,n-1);
}
return funtion(s1,s2,m,n-1);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | ad13b88a45125e4b158c6689754e8269 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
public class E123A {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int t = Integer.parseInt(st.nextToken());
while (t-- > 0) {
st = new StringTokenizer(br.readLine());
String hall = st.nextToken();
System.out.println(solve(hall) ? "YES" : "NO");
}
}
private static boolean solve(String hall) {
Set<Character> set = new HashSet<>();
for (int i = 0; i < hall.length(); i++) {
Character c = hall.charAt(i);
Character lower = Character.toLowerCase(c);
if (!lower.equals(c)) {
if (!set.contains(Character.toLowerCase(c)))
return false;
}
else {
set.add(Character.toLowerCase(c));
}
}
return true;
}
}
/*
1 1 0 1 0
1 1 0 0 0
1
*/
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | cf911bbbbdcc2b97c581eb7900664794 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class first {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
String result="";
for(int j=0;j<t;j++)
{
int k=0;
String s=sc.next();
for(int i=0;i<s.length();i++)
{
String sub=s.substring(0, i);
if(s.charAt(i)=='R')
{
if(sub.contains("r")) {
k++;
}
}
if(s.charAt(i)=='G')
{
if(sub.contains("g")) {
k++;
}
}
if(s.charAt(i)=='B')
{
if(sub.contains("b")) {
k++;
}
}
}
if(k==3)
result=result+"YES"+"\n";
else
result=result+"NO"+"\n";
}
System.out.println(result);
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 4f84b8bcdcac1827a05791f80ce85dbd | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class first {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
String result="";
for(int j=0;j<t;j++)
{
int k=0;
String s=sc.next();
for(int i=0;i<s.length();i++)
{
String sub=s.substring(0, i);
if(s.charAt(i)=='R')
{
if(sub.contains("r")) {
k++;
}
}
if(s.charAt(i)=='G')
{
if(sub.contains("g")) {
k++;
}
}
if(s.charAt(i)=='B')
{
if(sub.contains("b")) {
k++;
}
}
}
if(k==3)
result=result+"YES"+"\n";
else
result=result+"NO"+"\n";
}
System.out.println(result);
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 3e9662674f08031b92fa820ca2125a95 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes |
import java.util.*;
public class _1644A_DoorsANdKEys {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int test = input.nextInt();
while (test-- > 0) {
String str = input.next();
boolean flag = true;
LinkedList<Character> keys = new LinkedList<>();
for (char c : str.toCharArray()) {
if (Character.isLowerCase(c)) {
keys.add(Character.toUpperCase(c));
} else if (!keys.contains(c)) {
flag = false;
break;
}
}
System.out.println(flag ? "YES" : "NO");
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | f2380828bddd32f3bf38858f835164aa | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public class Decode {
public static void main(String[] args) {
Scanner st = new Scanner(System.in);
int t = st.nextInt();
while (t-- > 0) {
String[] arr = st.next().split("");
Stack<String> stack = new Stack<>();
if (arr[0].equals("R") || arr[0].equals("G") || arr[0].equals("B")) {
System.out.println("NO");
continue;
}
for (int i = 0; i < arr.length; i++) {
if (arr[i].equals("R") || arr[i].equals("G") || arr[i].equals("B")) {
if (!stack.contains(arr[i].toLowerCase())) {
System.out.println("NO");
break;
}
else {
stack.removeElement(arr[i].toLowerCase());
}
}
else {
stack.add(arr[i]);
}
if (i == arr.length - 1 && stack.size() == 0) {
System.out.println("YES");
}
}
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 19c4b6422c16e3f8879f2f967d9ac87d | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static int gcd(int a, int b) {
if (a < 0 || b < 0) { //求最大公因数
return -1; // 数学上不考虑负数的约数
}
if (b == 0) {
return a;
}
return a % b == 0 ? b : gcd(b, a % b);
}
public static int lcm(int m, int n) { //求最小公倍数
int mn = m * n;
return mn / gcd(m, n);
}
static PrintWriter out = new PrintWriter(System.out);
static Scanner in = new Scanner(System.in);
static BufferedReader re = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
//String[] strs = re.readLine().split(" "); int a = Integer.parseInt(strs[0]);
public static void main(String[] args) throws IOException {
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
//String[] strs = re.readLine().split(" ");
//int T=Integer.parseInt(strs[0]);
int T=in.nextInt();
//int T=1;
while(T>0){
//String[] strs1 = re.readLine().split(" ");
//int n=Integer.parseInt(strs1[0]);
//String s=re.readLine();
//char arr[]=s.toCharArray();
//Set<Integer>set=new HashSet<>();
//Map<Long,Integer>map=new HashMap<>();26
//abcdefghijklmnopqrstuvwxyz
//Map<Integer,List<Integer>>map=new HashMap<>();
//TreeSet<Integer> set = new TreeSet<>();
//int max=0;int min=2100000000;
//int n=in.nextInt();
//int arr[]=new int [n+1];
//for(int i=1;i<=n;i++)arr[i]=in.nextInt();
Map<Character,Integer>map=new HashMap<>();
String s=in.next();
char arr[]=s.toCharArray();
int t=0;
for(int i=0;i<arr.length;i++){
map.put(arr[i],1);
if(arr[i]=='R'){
char c='r';
if(map.getOrDefault(c,0)==0)t++;
}
if(arr[i]=='B'){
char c='b';
if(map.getOrDefault(c,0)==0)t++;
}
if(arr[i]=='G'){
char c='g';
if(map.getOrDefault(c,0)==0)t++;
}
}
if(t==0)out.println("YES");
else out.println("NO");
//out.println();
T--;
}
out.flush();
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | de1712caf1a5b8f435dc7eeda87a23a4 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
import java.lang.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 1; i <= t; i++) {
String a = sc.next();
if (a.indexOf('r') > a.indexOf('R') || a.indexOf('b') > a.indexOf('B') || a.indexOf('g') > a.indexOf('G')) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | fb7737474095e161660fe4a22ee46b7a | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
String text = scanner.nextLine();
while(t-- != 0){
text = scanner.nextLine();
List<Character> list = new ArrayList<>();
int count = 0;
for(int j =0; j < 6; j++){
char jch = text.charAt(j);
if(jch >='a' && jch <= 'z'){
list.add(jch);
}
if(jch >= 'A' && jch <= 'Z'){
if(list.contains((char)(jch + 32))){
count++;
}
}
}
if(count == 3){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 854d75e3186114a44622148a05b9fc40 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class test265 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t=in.nextInt();
for(int j=0;j<t;j++) {
boolean a[]=new boolean[3];
boolean y=false;
char x[]=in.next().toCharArray();
for(int i=0;i<6;i++) {
switch(x[i]) {
case 'r':a[0]=true;
break;
case 'g':a[1]=true;
break;
case 'b':a[2]=true;
break;
case 'R':if(!a[0]) {y=true;}
break;
case 'G':if(!a[1]) {y=true;}
break;
default:if(!a[2]) {y=true;}
}
if(y) {
break;
}
}
if(y) {
System.out.println("NO");
}
else {
System.out.println("YES");
}
}
in.close();
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 56cd6123d9c0601e37eeeb74181f140c | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.Scanner;
public class Doors {
int number;
public Doors(int number){
this.number=number;
}
public void input(String s){
boolean ba=true;
for (int i=0;i<s.length();i++){
boolean b=false;
if(s.charAt(i)>97){
continue;
}else {
int str=s.charAt(i);
b=true;
for (int k=i;k>=0;k--){
int strCheck=s.charAt(k);
if (str==strCheck-32){
b=false;
break;
}
}
}
if (b == true) {
ba=false;
break;
}
}
if(ba==false){
System.out.println("NO");
}else {
System.out.println("YES");
}
}
public int getNumber() {
return number;
}
public static void main(String[] a){
Scanner input=new Scanner(System.in);
int number=input.nextInt();
Doors instance=new Doors(number);
for (int i=0;i<instance.getNumber();i++){
String s=input.next();
instance.input(s);
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 377176483295eebc3a3a16d9712f2f54 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
import java.io.*;
public class Codeforces{
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int t = sc.nextInt();
while (t-- > 0)
{
String s = sc.next();
// has keys r g b
boolean[] haskeys = {false, false, false};
char[] keys = {'r', 'g', 'b'};
boolean pass = true;
for (int i = 0; i < 6 && pass; i++)
{
for (int j = 0; j < 3; j++)
if(s.charAt(i) == keys[j])
{
haskeys[j] = true;
}
for (int j = 0; j < 3; j++)
if(s.charAt(i) == keys[j] - 32)
pass = haskeys[j];
}
if (pass)
pw.println("YES");
else
pw.println("NO");
}
pw.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 804f41e2c4472900fe94972fab63e791 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 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();
Scanner in = new Scanner(System.in);
PrintWriter out=new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
int t = fs.nextInt();
while (t-- > 0) {
Set<Character> set = new HashSet<>();
String s = fs.next();
boolean res = true;
for (int i = 0; i < 6; i++) {
if(s.charAt(i) == 'b' || s.charAt(i) == 'g' || s.charAt(i) == 'r') set.add(s.charAt(i));
else {
char ch =Character.toLowerCase(s.charAt(i));
if(!set.contains(ch)) {
res = false;
break;
}
}
}
sb.append(res?"YES":"NO").append("\n");
}
out.print(sb);
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 | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 13afc1478f32bc519c0ea42d70ae31b2 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.util.*;
public final class DoorKeys {
public static void solve(String s) {
String ans = "";
int g = 0, r = 0, b = 0;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == 'r')
r = 1;
else if (c == 'b')
b = 1;
else if (c == 'g')
g = 1;
if (c == 'R' && r == 0) {
ans = "NO";
break;
} else if (c == 'G' && g == 0) {
ans = "NO";
break;
} else if (c == 'B' && b == 0) {
ans = "NO";
break;
}
}
if (ans == "NO")
System.out.println("NO");
else
System.out.println("YES");
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
String temp = sc.next();
solve(temp);
}
sc.close();
}
} | Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 9c9dfb8148ec5049e839f2ac5f80bb6c | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
FastScanner scanner = new FastScanner();
int t = scanner.nextInt();
for (int p = 0; p < t; p++) {
String s = scanner.next();
boolean b1 = false, b2 = false, b3 = false;
boolean b = true;
for (char c : s.toCharArray()) {
if (c == 'r') {
b1 = true;
}
if (c == 'b') {
b2 = true;
}
if (c == 'g') {
b3 = true;
}
if (c == 'R' && !b1) {
b = false;
break;
}
if (c == 'B' && !b2) {
b = false;
break;
}
if (c == 'G' && !b3) {
b = false;
break;
}
}
if (b) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
private static class Pair {
long l;
long r;
public Pair(long l, long r) {
this.l = l;
this.r = r;
}
}
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 | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output | |
PASSED | 2cf5ffbd3edb8698133fa64a5b5346f2 | train_108.jsonl | 1645540500 | The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters: R, G, B — denoting red, green and blue doors, respectively; r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway. | 256 megabytes | // package com.sameer;
import java.util.*;
public class Main {
private static void solve() {
String s = sc.next();
Set<Character> keysList = new HashSet<>();
for (Character ch:
s.toCharArray()) {
if (Character.isUpperCase(ch)) {
if (!keysList.contains(Character.toLowerCase(ch))) {
System.out.println("NO");
return;
}
} else {
keysList.add(ch);
}
}
System.out.println("YES");
}
private static final Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int testCases = sc.nextInt();
while (testCases-- > 0) {
solve();
}
}
}
| Java | ["4\n\nrgbBRG\n\nRgbrBG\n\nbBrRgG\n\nrgRGBb"] | 2 seconds | ["YES\nNO\nYES\nNO"] | NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door. | Java 8 | standard input | [
"implementation"
] | 60eb29b2dfb4d6b136c58b33dbd2558e | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once. | 800 | For each testcase, print YES if the knight can open all doors. Otherwise, print NO. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.