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 | 24220c82b1b636bb681c08f61efef010 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class OmNomAndSpiders {
public static void main(String[] args) {
InputReader r = new InputReader(System.in);
int n = r.nextInt();
int m = r.nextInt();
int k = r.nextInt();
char[][] arr = new char[n][m];
for (int i = 0; i < arr.length; i++) {
arr[i] = r.next().toCharArray();
}
PrintWriter out = new PrintWriter(System.out);
for (int j = 0; j < m; j++) {
int seen = 0;
for (int i = 1; i < n; i++) {
if (j - i >= 0 && arr[i][j - i] == 'R')
seen++;
if (j + i < m && arr[i][j + i] == 'L')
seen++;
if (i + i < n && arr[i + i][j] == 'U')
seen++;
}
out.println(seen);
}
out.close();
}
static class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public InputReader(FileReader stream) {
reader = new BufferedReader(stream);
tokenizer = null;
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return 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 | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 9e5e539c092ecf44fdf34df731d6e193 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.util.Scanner;
public class Test1{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int k=sc.nextInt();
int[] no=new int[m];
for(int i=0;i<n;i++){
String str=sc.next();
//System.out.println(str);
for(int j=0;j<m;j++){
char c=str.charAt(j);
if(c=='L'){
if(j-i>=0){
no[j-i]++;
}
}else if(c=='R'){
if(i+j<m){
no[j+i]++;
}
}else if(c=='U'){
if(i%2==0)
no[j]++;
}
}
}
for(int i=0;i<m;i++){
System.out.print(no[i]+" ");
}
}
} | Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 2c371d48a7c9c1321fa92fa77b8cd5a1 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class CF_ZCR14_B {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] line = br.readLine().split("\\s+");
int n = Integer.parseInt(line[0]);
int m = Integer.parseInt(line[1]);
char[][] field = new char[n][m];
for (int i = 0; i < n; i++) {
line[0] = br.readLine();
for (int j = 0; j < m; j++)
field[i] = line[0].toCharArray();
}
int[] pos = new int[m];
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
if (2 * i < n && field[2 * i][j] == 'U')
pos[j]++;
if (j + i < m && field[i][j + i] == 'L')
pos[j]++;
if (j - i >= 0 && field[i][j - i] == 'R')
pos[j]++;
}
}
PrintWriter out = new PrintWriter(System.out);
for (int i = 0; i < m; i++)
out.print(pos[i] + " ");
out.close();
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | b3b1f2fb34c773ac51446a4c28cfaff6 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.*;
import java.util.*;
public class Spider
{
public static void main(String []av) {
Scanner s = new Scanner();
int n = s.nextInt();
int m = s.nextInt();
int k = s.nextInt();
char [][]p = new char[n][];
for (int i = 0; i < n; i++) {
p[i] = s.readNextLine().toCharArray();
}
int [] M = new int[m]; // see spider in column j
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
switch (p[i][j]) {
case 'R':
if (i + j < m)
M[i+j] += 1;
break;
case 'L':
if (j - i >= 0)
M[j-i] += 1;
break;
case 'U':
if (i % 2 == 0)
M[j] += 1;
break;
case 'D':
break;
}
}
}
StringBuilder o = new StringBuilder();
for (int j = 0; j < m; j++) {
o.append(Integer.toString(M[j]));
if (j < m - 1)
o.append(' ');
}
System.out.println(o.toString());
}
//-----------Scanner class for faster input----------
/* Provides similar API as java.util.Scanner but does not
* use regular expression engine.
*/
public static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner(Reader in) {
br = new BufferedReader(in);
}
public Scanner() { this(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()); }
// Slightly different from java.util.Scanner.nextLine(),
// which returns any remaining characters in current line,
// if any.
String readNextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | c32e610bb43a9e4bcbc6c2a863af83bb | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.*;
import java.util.Arrays;
import java.util.*;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
PrintWriter out;
BufferedReader input;
Main() {
try {
input = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"), true);
solver();
} catch (Exception ex) {
ex.printStackTrace();
input = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out, true);
solver();
} finally {
out.close();
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
StringTokenizer st = new StringTokenizer("");
private String nextToken() {
while (!st.hasMoreElements()) {
try {
st = new StringTokenizer(input.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
private int nextInt() {
return Integer.parseInt(nextToken());
}
private long nextLong() {
return Long.parseLong(nextToken());
}
private double nextDouble() {
return Double.parseDouble(nextToken());
}
void solver() {
int n = nextInt();
int m = nextInt();
int k = nextInt();
char[][] mt = new char[n][m];
for (int i = 0; i < n; i++) {
String str = nextToken();
for (int j = 0; j < m; j++) {
mt[i][j] = str.charAt(j);
}
}
int[] res = new int[m];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (i-j >= 0 && mt[j][i-j] == 'R')
res[i]++;
if (i+j < m && mt[j][i+j] == 'L')
res[i]++;
if (j+j < n && mt[j+j][i] == 'U')
res[i]++;
}
}
for (int i = 0; i < m; i++) {
out.print(res[i] + " ");
}
}
public static void main(String[] args) {
new Main();
}
} | Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 8a10a7dfe8ae8e9f17c17d99fa723d53 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Stack;
import java.util.StringTokenizer;
public class OmNomAndSpiders {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[] ans = new int[m];
char[][]a = new char[n][m];
for (int i = 0; i < n; i++) {
String s = br.readLine();
for (int j = 0; j < m; j++) {
a[i][j] = s.charAt(j);
}
}
for(int i = 0; i < m; i++) {
for(int j = 1; j < n; j++) {
if(2*j < n && a[2*j][i]=='U')
ans[i]++;
if(i-j>=0&& a[j][i-j]=='R')
ans[i]++;
if(i+j<m&& a[j][i+j]=='L')
ans[i]++;
}
}
out.print(ans[0]);
for(int i = 1; i < m; i++) {
out.print(" " + ans[i]);
}
out.flush();
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | a953931fcf7186dd4035bfad25751ab4 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class B {
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter out;
public void solve() throws IOException {
int N = nextInt();
int M = nextInt();
int K = nextInt();
char[][] map = new char[N][M];
for (int i = 0; i < N; i++) {
map[i] = reader.readLine().toCharArray();
}
int[] cnt = new int[M];
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (map[i][j] == 'R') {
if (j+i < M) cnt[j+i]++;
} else if (map[i][j] == 'L') {
if (j-i >= 0) cnt[j-i]++;
} else if (map[i][j] == 'U') {
if (i % 2 == 0) {
cnt[j]++;
}
}
}
}
for (int j = 0; j < M; j++) {
out.print(cnt[j] + " ");
}
out.println();
}
/**
* @param args
*/
public static void main(String[] args) {
new B().run();
}
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
out = new PrintWriter(System.out);
solve();
reader.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 61a95f1c39c3bb3e95e97bdb1fa3abe6 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
* Created by Vadim
*/
public class B1 {
static int n;
static int m;
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(reader.readLine());
n = Integer.parseInt(st.nextToken());
m = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
char[][] a= new char[n][m];
for (int i = 0; i < n; i++) {
String s = reader.readLine();
for (int j = 0; j < m; j++) {
a[i][j] = s.charAt(j);
}
}
int [] occ = new int[m];
for (int i = 1; i < n; i++) {
for (int j = 0; j < m; j++) {
if(j-i>=0 && a[i][j-i] == 'R') {
occ[j]++;
}
if(j+i < m && a[i][j+i] == 'L') {
occ[j]++;
}
if(i+i <n && a[i+i][j] == 'U') {
occ[j]++;
}
}
}
for (int i = 0; i < m; i++) {
System.out.print(occ[i] + " ");
}
System.out.println();
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 9b762d653183fec471d5cf2fcbc2c22a | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.*;
import java.util.*;
public class Spider {
static public class FastScanner {
java.io.BufferedReader br;
StringTokenizer st;
public FastScanner() {
init();
}
public FastScanner(String name) {
init(name);
}
public FastScanner(boolean isOnlineJudge) {
if (!isOnlineJudge || System.getProperty("ONLINE_JUDGE") != null) {
init();
} else {
init("input.txt");
}
}
private void init() {
br = new java.io.BufferedReader(new java.io.InputStreamReader(
System.in));
}
private void init(String name) {
try {
br = new java.io.BufferedReader(new java.io.FileReader(name));
} catch (java.io.FileNotFoundException e) {
e.printStackTrace();
}
}
public String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
public static void main(String[] args) throws IOException {
FastScanner s = new FastScanner();
// FastScanner s = new FastScanner("input.txt");
int N = s.nextInt();
int M = s.nextInt();
int K = s.nextInt();
char[][] arr = new char[N][M];
int count[] = new int[M];
for (int i = 0; i < N; i++) {
arr[i] = s.nextToken().toCharArray();
}
// _(arr);
for (int m = 0; m < M; m++) {
for (int n = 1; n < N; n++) {
char ch = arr[n][m];
// if(n > 1 && ch == 'U'){
// count[m]++;
// }else if(ch == 'R' && m + n < M){
// count[m + n]++;
// }else if(ch == 'L' && m - n >= 0){
// count[m - n]++;
// }
switch(ch){
case 'U':
if(n % 2 == 0) count[m]++;
break;
case 'R':
if(m + n < M) count[m + n]++;
break;
case 'L':
if(m - n >= 0) count[m - n]++;
break;
}
}
}
for(int i : count){
System.out.print(i + " ");
}
System.out.println();
}
static void _(Object... objs) {
System.err.println(Arrays.deepToString(objs));
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 31434c8107ee467f7e9c1ec73fd739d4 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int m = in.nextInt();
int k = in.nextInt();
String []s = new String[n];
for (int i = 0; i < n; i++) {
s[i] = in.next();
}
int []res = new int[m];
for (int i = 0; i < m; i++) {
for (int j = 1; j < n; j++) {
if (i + j < m && s[j].charAt(i + j) == 'L'){
res[i]++;
}
if (i - j > -1 && s[j].charAt(i - j) == 'R'){
res[i]++;
}
if (j + j < n && s[j + j].charAt(i) == 'U'){
res[i]++;
}
if (s[0].charAt(i) == 'D'){
res[i]++;
}
}
}
for (int i = 0; i < m; i++) {
out.print(res[i]+" ");
}
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 0474297a5317614df2525d8747cf52a1 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.util.*;
import java.math.*;
import java.io.*;
public class B {
public static long time = 0;
public static void main(String[] args) throws Exception {
time = System.currentTimeMillis();
IN = System.in;
OUT = System.out;
in = new BufferedReader(new InputStreamReader(IN));
out = new PrintWriter(OUT, FLUSH);
solveOne();
out.flush();
}
public static void solveOne() throws Exception {
int n = nextInt();
int m = nextInt();
int k = nextInt();
char[][] grid = new char[n][];
for (int i = 0 ; i < n; i++){
grid[i] = nextString().toCharArray();
}
int[] count = new int[m];
int[] rightSum = new int[m];
for (int i = 0 ; i < n; i++){
for (int j = 0 ; j < m; j++){
char cur = grid[i][j];
if (cur == 'R'){
if (i + j < m){
count[i + j]++;
}
}
else if (cur == 'L'){
if (j - i >= 0 && j - i < m){
count[j- i ]++;
}
}
else if (cur == 'U' && i % 2 == 0){
count[j]++;
}
}
}
for (int e: count) p(e + " ");
pn();
}
public static void solveTwo() throws Exception {
}
public static void solveThree() throws Exception {
}
public static BufferedReader in;
public static StringTokenizer st;
public static InputStream IN;
public static OutputStream OUT;
public static String nextString() throws Exception {
for (;st == null || !st.hasMoreTokens();){
String k1 = in.readLine();
if (k1 == null) return null;
st = new StringTokenizer(k1);
}
return st.nextToken();
}
public static int nextInt () throws Exception {
return Integer.parseInt(nextString());
}
public static long nextLong() throws Exception{
return Long.parseLong(nextString());
}
public static double nextDouble() throws Exception{
return Double.parseDouble(nextString());
}
private static int[] nextIntArray(int n1) throws Exception {
int[] l1 = new int[n1];
for (int i = 0 ;i < n1; i++){
l1[i] = nextInt();
}
return l1;
}
private static long[] nextLongArray(int n1) throws Exception {
long[] l1 = new long[n1];
for (int i = 0 ;i < n1; i++){
l1[i] = nextLong();
}
return l1;
}
private static int[][] nextIntGrid(int x, int y) throws Exception {
int[][] l1 = new int[x][y];
for (int i =0; i < x; i++){
for (int j = 0; j < y; j++){
l1[i][j] = nextInt();
}
}
return l1;
}
public static void px(Object ... l1){
System.out.println(Arrays.deepToString(l1));
}
public static boolean FLUSH = false;
public static PrintWriter out;
public static void p(Object ... l1){
for (int i = 0; i < l1.length; i++){
if (i != 0) out.print(' ');
out.print(l1[i].toString());
}
}
public static void pn(Object ... l1){
for (int i = 0; i < l1.length; i++){
if (i != 0) out.print(' ');
out.print(l1[i].toString());
}
out.println();
}
public static void pn(Collection l1){
boolean first = true;
for (Object e: l1){
if (first) first = false;
else out.print(' ');
out.print(e.toString());
}
out.println();
}
private static BigInteger bi(long n1){
return BigInteger.valueOf(n1);
}
private static double usedTime(){
return (System.currentTimeMillis()-time)*0.001;
}
private static Random usingRandomGenerator = new Random(System.currentTimeMillis());
private static void sort(double[] l1){
for (int i = 0 ; i< l1.length; i++){
int q = i + usingRandomGenerator.nextInt(l1.length - i);
double t = l1[i];
l1[i] = l1[q];
l1[q] = t;
}
Arrays.sort(l1);
}
private static void sort(int[] l1){
for (int i = 0 ; i< l1.length; i++){
int q = i + usingRandomGenerator.nextInt(l1.length - i);
int t = l1[i];
l1[i] = l1[q];
l1[q] = t;
}
Arrays.sort(l1);
}
private static void sort(long[] l1){
for (int i = 0 ; i< l1.length; i++){
int q = i + usingRandomGenerator.nextInt(l1.length - i);
long t = l1[i];
l1[i] = l1[q];
l1[q] = t;
}
Arrays.sort(l1);
}
} | Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | dd198db0bb14dd2bd90e7988aa6c5f61 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main implements Runnable {
char[][] map;
int N, M, K;
public void solve() throws IOException {
N = nextInt(); M = nextInt(); K = nextInt();
map = new char[N][M];
for(int i = 0; i < N; i++) map[i] = nextToken().toCharArray();
for(int col = 0; col < M; col++){
int count = 0;
for(int row = 0; row < N; row++){
count += spiders(row, col);
}
System.out.print(count + " ");
}
System.out.println();
}
private int spiders(int r, int c){
int t = r;
int ret = 0;
if(ok(r+t, c) && map[r + t][c] == 'U') ret++;
if(ok(r-t, c) && map[r - t][c] == 'D') ret++;
if(ok(r, c-t) && map[r][c - t] == 'R') ret++;
if(ok(r, c+t) && map[r][c + t] == 'L') ret++;
return ret;
}
private boolean ok(int r, int c){
if(r >= 0 && r < N && c >= 0 && c < M) return true;
return false;
}
//-----------------------------------------------------------
public static void main(String[] args) {
new Main().run();
}
public void print1Int(int[] a){
for(int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
}
public void print2Int(int[][] a){
for(int i = 0; i < a.length; i++){
for(int j = 0; j < a[0].length; j++){
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
tok = null;
solve();
in.close();
} catch (IOException e) {
System.exit(0);
}
}
public String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
BufferedReader in;
StringTokenizer tok;
} | Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | b17a1430a4783b4a22747e95c770b51e | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int R = in.nextInt();
int C = in.nextInt();
int k = in.nextInt();
int[] res = new int[C];
for (int r = 0; r < R; r++) {
char[] s = in.next().toCharArray();
for (int c = 0; c < C; c++) {
if (s[c] == 'R') {
if (c + r < C)
++res[c + r];
} else if (s[c] == 'L') {
if (c - r >= 0)
++res[c - r];
} else if (s[c] == 'U') {
res[c] += 1 - r % 2;
}
}
}
for (int i = 0; i < C; i++) {
if (i > 0)
out.print(' ');
out.print(res[i]);
}
out.println();
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | b3827169bfd68b5803fac8cf574157fb | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class B implements Runnable {
void solve() {
int n = nextInt(), m = nextInt(), k = nextInt();
int[] ans = new int[m];
for (int i = 0; i < n; i++) {
char[] c = nextString().toCharArray();
for (int j = 0; j < m; j++) {
if (c[j] == 'U' && i % 2 == 0)
ans[j]++;
if (c[j] == 'L' && j - i >= 0)
ans[j - i]++;
if (c[j] == 'R' && j + i < m)
ans[j + i]++;
}
}
printArray(ans);
}
public static void main(String[] args) throws IOException {
new B().run();
}
B() {
this.stream = System.in;
this.writer = new PrintWriter(System.out);
}
B(String input, String output) throws IOException {
File inputFile = new File(input);
inputFile.createNewFile();
stream = new FileInputStream(inputFile);
File outputFile = new File(output);
outputFile.createNewFile();
writer = new PrintWriter(outputFile);
}
public void run() {
solve();
writer.close();
}
void halt() {
writer.close();
System.exit(0);
}
PrintWriter writer;;
void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
void println(Object... objects) {
print(objects);
writer.println();
}
void printArray(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) writer.print(' ');
writer.print(array[i]);
}
writer.println();
}
void printArray(long[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) writer.print(' ');
writer.print(array[i]);
}
writer.println();
}
void printMatrix(int[][] matrix) {
for (int i = 0; i < matrix.length; i++)
printArray(matrix[i]);
}
void printMatrix(long[][] matrix) {
for (int i = 0; i < matrix.length; i++)
printArray(matrix[i]);
}
/**
* Pure Egor's code is straight ahead.
*/
InputStream stream;
byte[] buf = new byte[1024];
int curChar, numChars;
int nextInt() {
int c = next();
while (isWhitespace(c))
c = next();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = next();
} while (!isWhitespace(c));
return res * sgn;
}
long nextLong() {
int c = next();
while (isWhitespace(c))
c = next();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = next();
} while (!isWhitespace(c));
return res * sgn;
}
double nextDouble() {
int c = next();
while (isWhitespace(c))
c = next();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
double res = 0;
while (!isWhitespace(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = next();
}
if (c == '.') {
c = next();
double m = 1;
while (!isWhitespace(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = next();
}
}
return res * sgn;
}
BigInteger nextBigInteger() {
try {
return new BigInteger(nextString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
int next() {
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++];
}
String nextString() {
int c = next();
while (isWhitespace(c))
c = next();
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c))
res.appendCodePoint(c);
c = next();
} while (!isWhitespace(c));
return res.toString();
}
String nextLine() {
StringBuilder buf = new StringBuilder();
int c = next();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = next();
}
return buf.toString();
}
boolean EOF() {
int value;
while (isWhitespace(value = peek()) && value != -1)
next();
return value == -1;
}
int peek() {
if (numChars == -1)
return -1;
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0)
return -1;
}
return buf[curChar];
}
boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
} | Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | c10b8b70ce349d87b1760acb4979d0a1 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.util.Scanner;
public class A {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
scanner.nextLine();
String s[] = new String[n];
for (int i = 0; i < n; i++)
s[i] = scanner.nextLine();
int a[] = new int[m];
for (int j = 0; j < m; j++) {
int ans = 0;
for (int i = 1; i < n; i++) {
if (i + i < n && s[i + i].charAt(j) == 'U')
ans++;
if (j + i < m && s[i].charAt(j + i) == 'L')
ans++;
if (j - i >= 0 && s[i].charAt(j - i) == 'R')
ans++;
}
a[j] = ans;
}
System.out.print(a[0]);
for (int i = 1; i < m; i++)
System.out.print(" " + a[i]);
System.out.println();
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | ba3c2fe5be6593c793442da5ce01b1f5 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.util.*;
import java.io.*;
public class A {
FastScanner in;
PrintWriter out;
public void solve() throws IOException {
int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
char[][] c = new char[n][m];
for (int i = 0; i < n; i++)
c[i] = in.next().toCharArray();
int[] res = new int[m];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (c[j][i] == 'U') {
if (j % 2 == 0)
res[i]++;
} else if (c[j][i] == 'R') {
if (i + j < m)
res[i + j]++;
} else if (c[j][i] == 'L') {
if (i - j >= 0)
res[i - j]++;
}
}
}
for (int i = 0; i < m; i++)
out.print(res[i] + " ");
}
public void run() {
try {
in = new FastScanner();
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() {
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());
}
}
public static void main(String[] arg) {
new A().run();
}
} | Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | da7027d56a57afd911573522a6ae5684 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException{
return Long.parseLong(nextToken());
}
void solve() throws IOException {
int n = nextInt();
int m = nextInt();
int k = nextInt();
int[] res = new int[m];
for (int i = 0; i < n; i++) {
String s = nextToken();
for (int j = 0; j < m; j++) {
char c = s.charAt(j);
switch (c) {
case 'D':
break;
case 'U':
if (i % 2 == 0) res[j]++;
break;
case 'L':
if (j - i >= 0) res[j - i]++;
break;
case 'R':
if (j + i < m) res[j + i]++;
break;
}
}
}
for (int i : res) out.print(i + " ");
}
public void run() {
try {
// in = new BufferedReader(new FileReader("input.txt"));
// out = new PrintWriter("output.txt");
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
Locale.setDefault(Locale.UK);
solve();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
out.close();
}
}
public static void main(String Args[]) {
new Thread(null, new Main(), "1", 1 << 28).start();
}
} | Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 2c910b0aa8f4e8dc9a4a4ed5880f9537 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
/**
*
* @author Mbt
*/
public class B {
public static void main(String[] args) throws IOException {
new Solver().solve();
}
}
class Solver{
final int MAXN= 2001;
char[][] field= new char[MAXN][];
int[] seenSpiders= new int[MAXN]; // seen spiders from each start
void solve() throws IOException{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
StringTokenizer reader= new StringTokenizer(br.readLine());
int n= Integer.parseInt(reader.nextToken());
int m= Integer.parseInt(reader.nextToken());
int k= Integer.parseInt(reader.nextToken());
for (int i = 0; i < n; i++)
field[i]= br.readLine().toCharArray();
// check all spiders
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++){
if (field[i][j]!='.'){ // there is a spider
switch(field[i][j]){
case 'R':
int diffUntilEndOfRight= m-j-1;
if (i<=diffUntilEndOfRight)
seenSpiders[j+i+1]++;
break;
case 'L':
int diffUntilEndOfLeft= j;
if (i<=diffUntilEndOfLeft)
seenSpiders[j-i+1]++;
break;
case 'U':
if ((i%2)==0)
seenSpiders[j+1]++;
break;
}
}
}
System.out.print(seenSpiders[1]);
for (int i = 2; i <= m; i++)
System.out.print(" " + seenSpiders[i]);
}
} | Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 8ffad5d381853a7c35d316736233321a | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.util.Scanner;
public class OmNomB {
/**
* @param args
*/
static char[][]grid;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int k=sc.nextInt();
grid=new char[n][m];
for(int i=0;i<n;i++){
String s=sc.next();
for(int j=0;j<m;j++){
grid[i][j]=s.charAt(j);
}
}
StringBuilder sb=new StringBuilder();
for(int i=0;i<m;i++){
int rslt=0;
for(int j=1;j<n;j++){
rslt+=check(j,i);
}
sb.append(rslt+" ");
}
System.out.println(sb);
}
private static int check(int j, int i) {
int n=grid.length;
int m=grid[0].length;
int rslt=0;
//up
if(j+j<n){
if(grid[j+j][i]=='U')
rslt++;
}
if(i+j<m){
if(grid[j][i+j]=='L')
rslt++;
}
if(i-j>=0){
if(grid[j][i-j]=='R')
rslt++;
}
return rslt;
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | b50a09c140bbb4b163352f3faadfe10b | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.util.Scanner;
public class pa63 {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int k=sc.nextInt();
int[] no=new int[m];
for(int i=0;i<n;i++){
String str=sc.next();
//System.out.println(str);
for(int j=0;j<m;j++){
char c=str.charAt(j);
if(c=='L'){
if(j-i>=0){
no[j-i]++;
}
}else if(c=='R'){
if(i+j<m){
no[j+i]++;
}
}else if(c=='U'){
if(i%2==0)
no[j]++;
}
}
}
for(int i=0;i<m;i++){
System.out.print(no[i]+" ");
}
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 27e5209b16353105937300907bc3b4e2 | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.IOException;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.util.HashMap;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.TreeSet;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Zyflair Griffane
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
JoltyScanner in = new JoltyScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, JoltyScanner in, PrintWriter out) {
int rows = in.nextInt();
int cols = in.nextInt();
int k = in.nextInt();
int[] spiders = new int[cols];
for (int i = 0; i < rows; i++) {
char[] arr = in.next().toCharArray();
for (int j = 0; j < cols; j++) {
if (arr[j] == 'U') {
if (i % 2 == 0) {
spiders[j]++;
}
}
else if (arr[j] == 'R') {
int col = i + j;
if (col < cols) {
spiders[col]++;
}
}
else if (arr[j] == 'L') {
if (j >= i) {
spiders[j - i]++;
}
}
}
}
out.println(IntArrayUtil.toString(spiders));
}
}
class JoltyScanner {
public static final int BUFFER_SIZE = 1 << 16;
public static final char NULL_CHAR = (char) -1;
StringBuilder str = new StringBuilder();
byte[] buffer = new byte[BUFFER_SIZE];
boolean EOF_FLAG = false;
int bufferIdx = 0, size = 0;
char c = (char) -1;
BufferedInputStream in = new BufferedInputStream(System.in, BUFFER_SIZE);
public JoltyScanner(InputStream in) {
this.in = new BufferedInputStream(in);
}
public int nextInt() {
long x = nextLong();
if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) {
throw new ArithmeticException("Scanned value overflows integer");
}
return (int) x;
}
public long nextLong() {
boolean negative = false;
if (c == NULL_CHAR) {
c = nextChar();
}
while (!EOF_FLAG && (c < '0' || c > '9')) {
if (c == '-') {
negative = true;
}
c = nextChar();
}
if (EOF_FLAG) {
throw new EndOfFileException();
}
long res = 0;
while (c >= '0' && c <= '9') {
res = (res << 3) + (res << 1) + c - '0';
c = nextChar();
}
return negative ? -res : res;
}
public String next() {
if (EOF_FLAG) {
throw new EndOfFileException();
}
if (c == NULL_CHAR) {
c = nextChar();
}
while (!EOF_FLAG && Character.isWhitespace(c)) {
c = nextChar();
}
str.setLength(0);
while (!EOF_FLAG && !Character.isWhitespace(c)) {
str.append(c);
c = nextChar();
}
return str.toString();
}
public char nextChar() {
if (EOF_FLAG) {
return NULL_CHAR;
}
while (bufferIdx == size) {
try {
size = in.read(buffer);
if (size == -1) {
throw new Exception();
}
}
catch (Exception e) {
EOF_FLAG = true;
return (char) -1;
}
if (size == -1) {
size = BUFFER_SIZE;
}
bufferIdx = 0;
}
return (char) buffer[bufferIdx++];
}
public class EndOfFileException extends RuntimeException {}
}
class IntArrayUtil {
public static String toString(int[] arr) {
return toString(arr, " ");
}
public static String toString(int[] arr, String delimiter) {
StringBuilder res = new StringBuilder();
for (int i: arr) {
res.append(i);
res.append(delimiter);
}
res.setLength(res.length() - delimiter.length());
return res.toString();
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 8e3140d61f6e99d7602f1eb2796ab2ca | train_002.jsonl | 1402673400 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants: to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class ZeptoB {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
String[] map = new String[n];
for(int i=0; i<n; i++){
map[i] = br.readLine();
}
for(int j=0; j<m; j++){
int total=0;
for(int i=1; i<n; i++){
int count = (j-i>=0&&map[i].charAt(j-i)=='R'?1:0)
+(j+i<m &&map[i].charAt(j+i)=='L'?1:0)
+(i+i<n &&map[i+i].charAt(j)=='U'?1:0);
total+=count;
}
if(j==m-1) System.out.println(total); else System.out.print(total+" ");
}
}
}
| Java | ["3 3 4\n...\nR.L\nR.U", "2 2 2\n..\nRL", "2 2 2\n..\nLR", "3 4 8\n....\nRRLL\nUUUU", "2 2 2\n..\nUU"] | 3 seconds | ["0 2 2", "1 1", "0 0", "1 3 3 1", "0 0"] | NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:... ... ..U ...R.L -> .*U -> L.R -> ...R.U .R. ..R ...Character "*" represents a cell that contains two spiders at the same time. If Om Nom starts from the first cell of the first row, he won't see any spiders. If he starts from the second cell, he will see two spiders at time 1. If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2. | Java 7 | standard input | [
"implementation",
"math"
] | d8c89bb83592a1ff1b639f7d53056d67 | The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)). Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders. | 1,400 | Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right. | standard output | |
PASSED | 907d075397d9dab7350dd3be290fe3b8 | train_002.jsonl | 1351783800 | You have n friends and you want to take m pictures of them. Exactly two of your friends should appear in each picture and no two pictures should contain the same pair of your friends. So if you have n = 3 friends you can take 3 different pictures, each containing a pair of your friends.Each of your friends has an attractiveness level which is specified by the integer number ai for the i-th friend. You know that the attractiveness of a picture containing the i-th and the j-th friends is equal to the exclusive-or (xor operation) of integers ai and aj.You want to take pictures in a way that the total sum of attractiveness of your pictures is maximized. You have to calculate this value. Since the result may not fit in a 32-bit integer number, print it modulo 1000000007 (109 + 7). | 256 megabytes | import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.util.Map;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Set;
import java.util.AbstractMap;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Egor Kulikov (egor@egork.net)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int count = in.readInt();
int pairCount = in.readInt();
int[] attractiveness = IOUtils.readIntArray(in, count);
Arrays.sort(attractiveness);
int threshold = 0;
int remaining = pairCount;
for (int i = 29; i >= 0; i--) {
threshold *= 2;
Counter<Integer> counter = new Counter<Integer>();
for (int j : attractiveness)
counter.add(j >> i);
int different = 0;
for (int j : counter.keySet()) {
int k = j ^ (threshold + 1);
if (k > j)
different += counter.get(j) * counter.get(k);
}
if (different >= remaining)
threshold++;
else
remaining -= different;
}
long answer = 0;
// int total = 0;
// int totalMore = 0;
for (int i = 0; i < count; i++) {
for (int j = i + 1; j < count; j++) {
int current = attractiveness[i] ^ attractiveness[j];
if (current > threshold) {
answer += current;
// total++;
}
// if (current > threshold)
// totalMore++;
}
}
// if (total < pairCount || totalMore > pairCount)
// throw new RuntimeException();
answer += (long)remaining * threshold;
out.printLine(answer % ((long)(1e9 + 7)));
}
}
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 readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.readInt();
return array;
}
}
class Counter<K> extends EHashMap<K, Long> {
public Counter() {
super();
}
public void add(K key) {
put(key, get(key) + 1);
}
public Long get(Object key) {
if (containsKey(key))
return super.get(key);
return 0L;
}
}
class EHashMap<E, V> extends AbstractMap<E, V> {
private static final int[] shifts = new int[10];
private int size;
private Object[] keys;
private Object[] values;
private int capacity;
private int shift;
private int[] indices;
private Set<Entry<E, V>> entrySet;
static {
Random random = new Random(System.currentTimeMillis());
for (int i = 0; i < 10; i++)
shifts[i] = 1 + 3 * i + random.nextInt(3);
}
public EHashMap() {
this(4);
}
private void setCapacity(int size) {
capacity = Integer.highestOneBit(10 * size);
keys = new Object[capacity];
values = new Object[capacity];
shift = capacity / 3 - 1;
shift -= 1 - (shift & 1);
indices = new int[capacity];
}
public EHashMap(int maxSize) {
setCapacity(maxSize);
entrySet = new AbstractSet<Entry<E, V>>() {
@Override
public Iterator<Entry<E, V>> iterator() {
return new Iterator<Entry<E, V>>() {
private HashEntry entry = new HashEntry();
int index = 0;
public boolean hasNext() {
while (index < capacity && keys[index] == null)
index++;
return index < capacity;
}
public Entry<E, V> next() {
if (!hasNext())
throw new NoSuchElementException();
entry.key = (E) keys[index];
entry.value = (V) values[index++];
return entry;
}
public void remove() {
if (entry.key == null)
throw new IllegalStateException();
EHashMap.this.remove(entry.key);
entry.key = null;
entry.value = null;
}
};
}
@Override
public int size() {
return size;
}
};
}
public EHashMap(Map<E, V> map) {
this(map.size());
putAll(map);
}
public Set<Entry<E, V>> entrySet() {
return entrySet;
}
public void clear() {
Arrays.fill(keys, null);
Arrays.fill(values, null);
size = 0;
}
private int index(Object o) {
return getHash(o.hashCode()) & (capacity - 1);
}
private int getHash(int h) {
int result = h;
for (int i : shifts)
result ^= h >>> i;
return result;
}
public V remove(Object o) {
if (o == null)
return null;
int index = index(o);
int indicesSize = 0;
while (keys[index] != null && !keys[index].equals(o)) {
indices[indicesSize++] = index;
index = (index + shift) & (capacity - 1);
}
if (keys[index] == null)
return null;
size--;
int lastIndex = indicesSize;
indices[indicesSize++] = index;
keys[index] = null;
V result = (V) values[index];
values[index] = null;
index = (index + shift) & (capacity - 1);
while (keys[index] != null) {
int curKey = index(keys[index]);
for (int i = 0; i <= lastIndex; i++) {
if (indices[i] == curKey) {
keys[indices[lastIndex]] = keys[index];
values[indices[lastIndex]] = values[index];
keys[index] = null;
values[index] = null;
lastIndex = indicesSize;
}
}
indices[indicesSize++] = index;
index = (index + shift) & (capacity - 1);
}
return result;
}
public V put(E e, V value) {
if (e == null)
return null;
int index = index(e);
while (keys[index] != null && !keys[index].equals(e))
index = (index + shift) & (capacity - 1);
if (keys[index] == null)
size++;
keys[index] = e;
values[index] = value;
if (size * 2 > capacity) {
Object[] oldKeys = keys;
Object[] oldValues = values;
setCapacity(size);
size = 0;
for (int i = 0; i < oldKeys.length; i++) {
if (oldKeys[i] != null)
put((E) oldKeys[i], (V) oldValues[i]);
}
}
return value;
}
public V get(Object o) {
if (o == null)
return null;
int index = index(o);
while (keys[index] != null && !keys[index].equals(o))
index = (index + shift) & (capacity - 1);
return (V) values[index];
}
public boolean containsKey(Object o) {
if (o == null)
return false;
int index = index(o);
while (keys[index] != null && !keys[index].equals(o))
index = (index + shift) & (capacity - 1);
return keys[index] != null;
}
public int size() {
return size;
}
private class HashEntry implements Entry<E, V> {
private E key;
private V value;
public E getKey() {
return key;
}
public V getValue() {
return value;
}
public V setValue(V value) {
put(key, value);
return this.value = value;
}
}
}
| Java | ["3 1\n1 2 3", "3 2\n1 2 3", "3 3\n1 2 3"] | 6 seconds | ["3", "5", "6"] | null | Java 6 | standard input | [
"data structures",
"binary search",
"bitmasks",
"math"
] | 37f144cbbc722910abb7b23f6c0d471b | The first line of input contains two integers n and m — the number of friends and the number of pictures that you want to take. Next line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the values of attractiveness of the friends. | 2,700 | The only line of output should contain an integer — the optimal total sum of attractiveness of your pictures. | standard output | |
PASSED | 99cd8af9f9a15c77eab9bf832c5313bd | train_002.jsonl | 1351783800 | You have n friends and you want to take m pictures of them. Exactly two of your friends should appear in each picture and no two pictures should contain the same pair of your friends. So if you have n = 3 friends you can take 3 different pictures, each containing a pair of your friends.Each of your friends has an attractiveness level which is specified by the integer number ai for the i-th friend. You know that the attractiveness of a picture containing the i-th and the j-th friends is equal to the exclusive-or (xor operation) of integers ai and aj.You want to take pictures in a way that the total sum of attractiveness of your pictures is maximized. You have to calculate this value. Since the result may not fit in a 32-bit integer number, print it modulo 1000000007 (109 + 7). | 256 megabytes | //package bayan2012;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
public class B {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni();
long m = nl();
long[] a = new long[n];
for(int i = 0;i < n;i++)a[i] = ni()*2;
Arrays.sort(a);
int[][] ct = new int[31][n+1];
for(int i = 31-1;i >= 0;i--){
for(int j = 1;j <= n;j++){
ct[i][j] = ct[i][j-1] + (int)(a[j-1]>>>i+1&1);
}
}
long b = 0;
long sum = 0;
long mod = 1000000007;
for(int i = 30;i >= 0;i--){
long one = 0;
long cum = 0;
for(int j = 0;j < n;j++){
long v = (a[j]>>>i+1<<i)^b;
long v1 = v^(1L<<i);
int from = -Arrays.binarySearch(a, v1*2-1)-1;
int to = -Arrays.binarySearch(a, (v1+(1L<<i))*2-1)-1;
// [from,to)
one += to - from;
if(from <= j && j < to)one--;
long lcum = 0;
for(int k = 30;k >= 0;k--){
int lct = ct[k][to] - ct[k][from];
if(a[j]<<63-(k+1)<0)lct = to-from-lct;
lcum = (lcum * 2 + lct) % mod;
}
cum += lcum;
}
cum = cum%mod*invl(2,mod)%mod;
one /= 2;
if(m >= one){
sum += cum;
m -= one;
}else{
b |= 1L<<i;
}
}
sum = (sum + (m%mod) * b) % mod;
out.println(sum);
}
public static long invl(long a, long mod)
{
long b = mod;
long p = 1, q = 0;
while(b > 0){
long c = a / b;
long d;
d = a; a = b; b = d % b;
d = p; p = q; q = d - c * q;
}
return p < 0 ? p + mod : p;
}
long sum(int a, int b, int c, int d, int[] x)
{
int n = x.length;
long ret = 0;
for(int i = 30;i >= 0;i--){
long one1 = 0, one2 = 0;
for(int j = a;j <= b;j++)one1 += x[j]>>>i&1;
for(int j = c;j <= d;j++)one2 += x[j]>>>i&1;
long one = one1*(d-c+1-one2)+one2*(b-a+1-one1);
ret = ret * 2 + one;
}
return ret;
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception
{
new B().run();
}
public int ni()
{
try {
int num = 0;
boolean minus = false;
while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
if(num == '-'){
num = 0;
minus = true;
}else{
num -= '0';
}
while(true){
int b = is.read();
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
}
} catch (IOException e) {
}
return -1;
}
public long nl()
{
try {
long num = 0;
boolean minus = false;
while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
if(num == '-'){
num = 0;
minus = true;
}else{
num -= '0';
}
while(true){
int b = is.read();
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
}
} catch (IOException e) {
}
return -1;
}
public String ns()
{
try{
int b = 0;
StringBuilder sb = new StringBuilder();
while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
if(b == -1)return "";
sb.append((char)b);
while(true){
b = is.read();
if(b == -1)return sb.toString();
if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
sb.append((char)b);
}
} catch (IOException e) {
}
return "";
}
public char[] ns(int n)
{
char[] buf = new char[n];
try{
int b = 0, p = 0;
while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
if(b == -1)return null;
buf[p++] = (char)b;
while(p < n){
b = is.read();
if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
buf[p++] = (char)b;
}
return Arrays.copyOf(buf, p);
} catch (IOException e) {
}
return null;
}
double nd() { return Double.parseDouble(ns()); }
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["3 1\n1 2 3", "3 2\n1 2 3", "3 3\n1 2 3"] | 6 seconds | ["3", "5", "6"] | null | Java 6 | standard input | [
"data structures",
"binary search",
"bitmasks",
"math"
] | 37f144cbbc722910abb7b23f6c0d471b | The first line of input contains two integers n and m — the number of friends and the number of pictures that you want to take. Next line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the values of attractiveness of the friends. | 2,700 | The only line of output should contain an integer — the optimal total sum of attractiveness of your pictures. | standard output | |
PASSED | cc3651ed8da2e98193bdb592528aa3e9 | train_002.jsonl | 1351783800 | You have n friends and you want to take m pictures of them. Exactly two of your friends should appear in each picture and no two pictures should contain the same pair of your friends. So if you have n = 3 friends you can take 3 different pictures, each containing a pair of your friends.Each of your friends has an attractiveness level which is specified by the integer number ai for the i-th friend. You know that the attractiveness of a picture containing the i-th and the j-th friends is equal to the exclusive-or (xor operation) of integers ai and aj.You want to take pictures in a way that the total sum of attractiveness of your pictures is maximized. You have to calculate this value. Since the result may not fit in a 32-bit integer number, print it modulo 1000000007 (109 + 7). | 256 megabytes | //package prac;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class BayanB2 {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int D = 30;
int n = ni(), m = ni();
int[] a = na(n);
Arrays.sort(a);
for(int i = 0;i < n;i++){
a[i] *= 2;
}
int mod = 1000000007;
int[][] window = new int[n][];
for(int i = 0;i < n;i++){
window[i] = new int[]{i+1, n, -1};
}
int[][] one = new int[n+1][D+1];
for(int d = D;d >= 1;d--){
for(int i = 0;i < n;i++){
one[i+1][d] = one[i][d] + (a[i]>>>d&1);
}
}
int base = 0;
long sum = 0;
for(int d = D;d >= 1;d--){
int count = 0;
for(int i = 0;i < n;i++){
int ind = -Arrays.binarySearch(a, window[i][0], window[i][1], (base^(a[i]>>>d+1<<d+1))|(1<<d)-1)-1;
window[i][2] = ind;
// a[i]と組み合わせるとd桁目が1になる個数
if(a[i]<<31-d>=0){
count += window[i][1]-ind;
}else{
count += ind-window[i][0];
}
// tr(window[i]);
}
// tr("count", d, base, count, m, sum);
if(count > m){
// おばーの場合1 (1が飽和してしまう)
for(int i = 0;i < n;i++){
if(a[i]<<31-d>=0){
window[i][0] = window[i][2];
}else{
window[i][1] = window[i][2];
}
}
base |= 1<<d;
}else{
// さふぁーの場合0 (1が足りない場合)
m -= count;
// 1の分を合計
for(int i = 0;i < n;i++){
if(a[i]<<31-d>=0){
for(int j = D;j >= 1;j--){
if(a[i]<<31-j>=0){
sum += ((long)one[window[i][1]][j]-one[window[i][2]][j]<<j-1)%mod;
}else{
sum += ((long)window[i][1]-window[i][2]-one[window[i][1]][j]+one[window[i][2]][j]<<j-1)%mod;
}
}
}else{
for(int j = D;j >= 1;j--){
if(a[i]<<31-j>=0){
sum += ((long)one[window[i][2]][j]-one[window[i][0]][j]<<j-1)%mod;
}else{
sum += ((long)window[i][2]-window[i][0]-one[window[i][2]][j]+one[window[i][0]][j]<<j-1)%mod;
}
}
}
}
for(int i = 0;i < n;i++){
if(a[i]<<31-d>=0){
window[i][1] = window[i][2];
}else{
window[i][0] = window[i][2];
}
}
}
}
sum += m * (base / 2) % mod;
out.println(sum % mod);
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new BayanB2().run(); }
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
private 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 int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
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 boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["3 1\n1 2 3", "3 2\n1 2 3", "3 3\n1 2 3"] | 6 seconds | ["3", "5", "6"] | null | Java 6 | standard input | [
"data structures",
"binary search",
"bitmasks",
"math"
] | 37f144cbbc722910abb7b23f6c0d471b | The first line of input contains two integers n and m — the number of friends and the number of pictures that you want to take. Next line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the values of attractiveness of the friends. | 2,700 | The only line of output should contain an integer — the optimal total sum of attractiveness of your pictures. | standard output | |
PASSED | eae4e3d2f4567fef7dfbf78f7780e412 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
import java.io.*;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String line = sc.nextLine();
//System.out.println(line);
if (line.startsWith("miao.") && !line.endsWith("lala."))
System.out.println("Rainbow's");
else if (!line.startsWith("miao.") && line.endsWith("lala."))
System.out.println("Freda's");
else
System.out.println("OMG>.< I don't know!");
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 7ebd00778ab38afea3e62c29ac87959c | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
import java.io.*;
public class a {
static long mod = 1000000000l;
public static void main(String[] args) throws IOException
{
input.init(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = input.nextInt();
for(int t = 0; t<T; t++)
{
String s = input.nextLine();
int res = 0, n = s.length();
if(n>=5 && s.substring(n-5,n).equals("lala.")) res |= 1;
if(n>=5 && s.substring(0,5).equals("miao.")) res |= 2;
if(res ==0) res = 3;
String[] st = {"Freda's", "Rainbow's", "OMG>.< I don't know!"};
out.println(st[res-1]);
}
out.close();
}
static class input {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
static String nextLine() throws IOException {
return reader.readLine();
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 19e6649ba3f01823bddc62f421b0d1a0 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes |
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class A {
public static void main(String... strinh) {
List<String> strList = new ArrayList<String>();
Scanner cin = new Scanner(System.in);
int n = 5;
int i = 0;
if (cin.hasNextInt()) {
n = cin.nextInt();
};
cin.nextLine();
while (i < n) {
strList.add(cin.nextLine());
i++;
}
for (String line : strList) {
if (line.startsWith("miao.")) {
if (!line.endsWith("lala.")) {
System.out.println("Rainbow's");
} else {
System.out.println("OMG>.< I don't know!");
}
} else if (line.endsWith("lala.")) {
System.out.println("Freda's");
} else {
System.out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 90309af8d88cc404aabb958c7b7d5ca1 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
public class palin {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(System.out);
Scanner scan = new Scanner(System.in);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, InputReader in, PrintWriter out) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.nextLine();
for (int i = 0; i < n; i++) {
boolean ok = true;
String str = scan.nextLine();
if (str.length() > 4 && str.substring(0, 5).equals("miao.")
&& str.substring(str.length() - 5).equals("lala.")) {
out.println("OMG>.< I don't know!");
continue;
}
if (str.length() > 4) {
if (str.substring(str.length() - 5).equals("lala.")) {
out.println("Freda's");
ok = false;
} else {
if (str.substring(0, 5).equals("miao.")) {
out.println("Rainbow's");
ok = false;
}
}
}
if (ok)
out.println("OMG>.< I don't know!");
}
}
}
class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream in) {
br = new BufferedReader(new InputStreamReader(in));
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | d78f0a70e682af6151cfebeb45602ce3 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
public class A implements Runnable {
private void solve() throws IOException {
int n = nextInt();
while (n-- > 0) {
String s = reader.readLine();
boolean f = false, r = false;
r = s.startsWith("miao.");
f = s.endsWith("lala.");
if (f && r) {
pl("OMG>.< I don't know!");
} else if (f) {
pl("Freda's");
} else if (r) {
pl("Rainbow's");
} else {
pl("OMG>.< I don't know!");
}
}
}
public static void main(String[] args) {
new A().run();
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter writer;
public void run() {
try {
reader = new BufferedReader(new BufferedReader(new InputStreamReader(System.in)));
writer = new PrintWriter(System.out);
tokenizer = null;
solve();
reader.close();
writer.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
BigInteger nextBigInteger() throws IOException {
return new BigInteger(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
void p(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
void pl(Object... objects) {
p(objects);
writer.println();
}
int cc;
void pf() {
writer.printf("Case #%d: ", ++cc);
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | c597db1f7aa5c29129060ed91d3aa4f2 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
import java.io.*;
public class d2_185_A {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(System.out);
String s=br.readLine();
int n=Integer.parseInt(s);
for(int i=0;i<n;i++)
{
s=br.readLine();
int l=s.length();
//System.out.println(s.substring(0, 5));
//System.out.println(s.substring(l-5, l));
if(l<=4)
{
pw.println("OMG>.< I don't know!");
//break;
//return;
continue;
}
if(s.substring(0, 5).equals("miao.") && !s.substring(l-5).equals("lala."))
{
pw.println("Rainbow's");
continue;
}
if(!s.substring(0, 5).equals("miao.") && s.substring(l-5).equals("lala."))
{
pw.println("Freda's");
continue;
}
pw.println("OMG>.< I don't know!");
}
pw.flush();
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 6c1c48aade333bcf25f9a5dc8e038f41 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {
static class Scanner{
BufferedReader br=null;
StringTokenizer tk=null;
public Scanner(){
br=new BufferedReader(new InputStreamReader(System.in));
}
public String next() throws IOException{
while(tk==null || !tk.hasMoreTokens())
tk=new StringTokenizer(br.readLine());
return tk.nextToken();
}
public int nextInt() throws NumberFormatException, IOException{
return Integer.valueOf(next());
}
public double nextDouble() throws NumberFormatException, IOException{
return Double.valueOf(next());
}
}
public static void main(String args[]) throws NumberFormatException, IOException{
Scanner sc = new Scanner();
int T = sc.nextInt();
for(int i = 0; i < T; i++){
String cad = sc.br.readLine();
boolean miao = cad.startsWith("miao.");
boolean lala = cad.endsWith("lala.");
if (miao && lala)
System.out.println("OMG>.< I don't know!");
else if (miao)
System.out.println("Rainbow's");
else if (lala)
System.out.println("Freda's");
else
System.out.println("OMG>.< I don't know!");
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | ba38dc8ea70dd3ba86f4f3abce7f3a2a | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.Scanner;
public class Prob312A {
public static void main(String[] Args) {
Scanner scan = new Scanner(System.in);
int x = scan.nextInt();
scan.nextLine();
for (int i = 0; i < x; i++) {
String s = scan.nextLine();
if (s.length() < 5)
System.out.println("OMG>.< I don't know!");
else {
String start = s.substring(0, 5);
String end = s.substring(s.length() - 5);
if (end.equals("lala.") && !start.equals("miao."))
System.out.println("Freda's");
else if (start.equals("miao.") && !end.equals("lala."))
System.out.println("Rainbow's");
else
System.out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | c6e86c875426f352c416e50fbf8207d3 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes |
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Scanner;
public class Main implements Runnable {
StreamTokenizer ST;
PrintWriter out;
BufferedReader br;
Scanner in;
public static void main(String[] args) throws IOException {
new Thread(new Main()).start();
}
@Override
public void run() {
try {
out = new PrintWriter(new BufferedOutputStream(System.out));
in = new Scanner(System.in);
solve();
out.close();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
public void solve() throws IOException {
int n = in.nextInt();
String nextLine = in.nextLine();
for (int i = 0; i < n; ++i) {
String str = in.nextLine();
boolean isA = false;
boolean isB = false;
if (str.startsWith("miao.")) {
isA = true;
}
if (str.endsWith("lala.")) {
isB = true;
}
if (isA && isB) {
out.println("OMG>.< I don't know!");
} else if (isA) {
out.println("Rainbow's");
} else if (isB) {
out.println("Freda's");
} else {
out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | e2a7a6a6b03b3a84bbe6a9ccaf35308d | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes |
import java.util.Scanner;
/**
*
* @author satinder
*/
public class nmakamm
{
public static void main(String[] args)
{
Scanner obj=new Scanner(System.in);
int num=obj.nextInt();
String iarr[]=new String[15];
String aarr[]=new String[15];
for(int i=0;i<=num;i++)
{
iarr[0]=null;
aarr[0]=null;
iarr[i]=obj.nextLine();
}
for(int i=1;i<=num;i++)
{
if(iarr[i].startsWith("miao."))
{
if(iarr[i].endsWith("lala."))
{
System.out.println("OMG>.< I don't know!");
}
else
{
System.out.println("Rainbow's");
}
}
else if(iarr[i].endsWith("lala."))
{
if(iarr[i].startsWith("miao."))
{
System.out.println("OMG>.< I don't know!");
}
else
{
System.out.println("Freda's");
}
}
else
{
System.out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 37b9f61a6dcb04c8cc496f976c808f04 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import javax.print.attribute.standard.MediaSize.ISO;
public class Codeforces2 implements Runnable {
private BufferedReader br = null;
private PrintWriter pw = null;
private StringTokenizer stk = new StringTokenizer("");
public static void main(String[] args) {
new Thread(new Codeforces2()).run();
}
public void run() {
/*
* try { br = new BufferedReader(new FileReader("/home/user/freshdb.sql")); pw = new PrintWriter("/home/user/freshdb_fix.sql"); } catch
* (FileNotFoundException e) { e.printStackTrace(); }
*/
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
solver();
pw.close();
}
private void nline() {
try {
if (!stk.hasMoreTokens())
stk = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException("KaVaBUnGO!!!", e);
}
}
private String nstr() {
while (!stk.hasMoreTokens())
nline();
return stk.nextToken();
}
private int ni() {
return Integer.valueOf(nstr());
}
private long nl() {
return Long.valueOf(nstr());
}
private double nd() {
return Double.valueOf(nstr());
}
String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
}
return null;
}
class Point {
int x;
int y;
Point(int x, int y){
this.x = x;
this.y = y;
}
}
private void bfs(int t, boolean[] using, int[][] g){
Stack<Integer> st = new Stack<Integer>();
int n = using.length;
st.add(t);
while(!st.empty()){
int p = st.pop();
for(int i=0; i<n; i++){
if (g[p][i]==1 && !using[i]){
st.add(i);
using[i] = true;
}
}
}
}
private void solver() {
int n = ni();
String F = "lala.", R = "miao.";
ArrayList<ArrayList<Integer>> ar = new ArrayList<ArrayList<Integer>>();
try {
while (br.ready()){
String s = br.readLine();
ar.add(new ArrayList<Integer>());
if (s.length() >= 5){
if (s.substring(0, 5).equals(R)){
ar.get(ar.size()-1).add(2);
}
if (s.substring(s.length()-5, s.length()).equals(F)){
ar.get(ar.size()-1).add(1);
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i=0; i<ar.size(); i++){
if (ar.get(i).size()==1){
System.out.println(ar.get(i).get(0)==1?"Freda's":"Rainbow's");
}else {
System.out.println("OMG>.< I don't know!");
}
}
}
private BigInteger nbi() {
return new BigInteger(nstr());
}
void exit() {
pw.close();
System.exit(0);
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 5a2fbbd890191ad33915b2ca8432cb72 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
public class main
{
public static void main(String args[]) throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int N;
boolean st, end;
String line;
N=Integer.parseInt(br.readLine());
while(N-->0){
line=br.readLine();
st=line.startsWith("miao.");
end=line.endsWith("lala.");
if(st && end){
System.out.println("OMG>.< I don't know!");
}else if(st && !end){
System.out.println("Rainbow's");
}else if(!st && end){
System.out.println("Freda's");
}else{
System.out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 6f2b03d2825fce8bbbd5addcf0b05719 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class Solver {
public static void main(String[] Args) throws NumberFormatException,
IOException {
new Solver().Run();
}
PrintWriter pw;
StringTokenizer Stok;
BufferedReader br;
public String nextToken() throws IOException {
while (Stok == null || !Stok.hasMoreTokens()) {
Stok = new StringTokenizer(br.readLine());
}
return Stok.nextToken();
}
public int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextToken());
}
public double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextToken());
}
public long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(nextToken());
}
public void Run() throws NumberFormatException, IOException {
//br = new BufferedReader(new FileReader("input.txt"));
//pw = new PrintWriter("output.txt");
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new OutputStreamWriter(System.out));
int n = nextInt();
String cur;
for (int i = 0; i<n; i++){
cur = br.readLine();
if (cur.startsWith("miao."))
if (cur.endsWith("lala."))
pw.println("OMG>.< I don't know!");
else
pw.println("Rainbow's");
else
if (cur.endsWith("lala."))
pw.println("Freda's");
else
pw.println("OMG>.< I don't know!");
}
pw.flush();
pw.close();
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | f135a3bda93d345293c5851777fdb40c | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
String Line = scn.nextLine();
for (int i = 0; i < n; i++) {
Line = scn.nextLine();
//System.out.println(Line.substring(0, 4));
if (Line.length()<5 || (Line.substring(0, 5).equals("miao.")
&& Line.substring(Line.length() - 5, Line.length())
.equals("lala."))) {
System.out.println("OMG>.< I don't know!");
} else if (Line.substring(0, 5).equals("miao.")) {
System.out.println("Rainbow's");
}
else if(Line.substring(Line.length() - 5, Line.length())
.equals("lala."))
{
System.out.println("Freda's");
}
else
{
System.out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 7a475203d9d8f68c09ce728d4039b180 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
BufferedReader in;
StringTokenizer str;
PrintWriter out;
String SK;
String next() throws IOException {
while ((str == null) || (!str.hasMoreTokens())) {
SK = in.readLine();
if (SK == null)
return null;
str = new StringTokenizer(SK);
}
return str.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
char[] charArray() throws IOException{
return next().toCharArray();
}
public static void main(String[] args) throws IOException {
new Solution().run();
}
void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
//in = new BufferedReader(new FileReader("input.txt"));
//out = new PrintWriter("output.txt");
solve();
out.close();
}
void solve() throws IOException {
int n = nextInt();
for (int i = 0; i < n; i++) {
String str=in.readLine();
if(str.startsWith("miao.") && str.endsWith("lala.")){
out.println("OMG>.< I don't know!");
}
else if(str.endsWith("lala."))
{
out.println("Freda's");
}
else if(str.startsWith("miao.")){
out.println("Rainbow's");
}
else out.println("OMG>.< I don't know!");
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | d6d27d61811e63665ca3e2acb05565ee | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
import java.math.*;
public class Main
{
static Input in;
static Output out;
static final boolean OJ = System.getProperty("ONLINE_JUDGE") != null;
public static void main(String[] args) throws IOException
{
in = new Input(OJ ? System.in : new FileInputStream("in.txt"));
out = new Output(OJ ? System.out : new FileOutputStream("out.txt"));
solve();
out.close();
System.exit(0);
}
private static void solve() throws IOException
{
int n = in.nextInt();
for (int i = 0; i < n; i++)
{
String line = in.nextLine();
if (line.startsWith("miao.") && line.endsWith("lala."))
out.println("OMG>.< I don't know!");
else if (line.startsWith("miao."))
out.println("Rainbow's");
else if (line.endsWith("lala."))
out.println("Freda's");
else out.println("OMG>.< I don't know!");
}
}
}
class Input
{
final int SIZE = 8192; //4096; 8192; 65536;
InputStream in;
byte[] buf = new byte[SIZE];
int last, current, total;
public Input(InputStream stream) throws IOException
{
in = stream; last = read();
}
int read() throws IOException
{
if (total == -1) return -1;
if (current >= total)
{
current = 0; total = in.read(buf);
if (total <= 0) return -1;
}
return buf[current++];
}
void advance() throws IOException
{
while (true)
{
if (last == -1) return;
if (!isValidChar(last)) last = read();
else break;
}
}
boolean isValidChar(int c) { return c > 32 && c < 127; }
public boolean endOfFile() throws IOException { advance(); return last == -1; }
public String nextString() throws IOException
{
advance();
if (last == -1) throw new EOFException();
StringBuilder s = new StringBuilder();
while (true)
{
s.appendCodePoint(last); last = read();
if (!isValidChar(last)) break;
}
return s.toString();
}
public String nextLine() throws IOException
{
if (last == -1) throw new EOFException();
StringBuilder s = new StringBuilder();
while (last != '\n') last = read(); // go to end of current line
last = read(); // go to next line
while (true)
{
s.appendCodePoint(last); last = read();
if (last == '\n' || last == '\r' || last == -1) break;
}
return s.toString();
}
public String nextLine(boolean ignoreIfEmpty) throws IOException
{
if (!ignoreIfEmpty) return nextLine();
String s = nextLine();
while (s.trim().length() == 0) s = nextLine();
return s;
}
public int nextInt() throws IOException
{
advance();
if (last == -1) throw new EOFException();
int n = 0, s = 1;
if (last == '-')
{
s = -1; last = read();
if (last == -1) throw new EOFException();
}
while (true)
{
n = n * 10 + last - '0'; last = read();
if (!isValidChar(last)) break;
}
return n * s;
}
public long nextLong() throws IOException
{
advance();
if (last == -1) throw new EOFException();
int s = 1;
if (last == '-')
{
s = -1; last = read();
if (last == -1) throw new EOFException();
}
long n = 0;
while (true)
{
n = n * 10 + last - '0'; last = read();
if (!isValidChar(last)) break;
}
return n * s;
}
public BigInteger nextBigInt() throws IOException { return new BigInteger(nextString()); }
public char nextChar() throws IOException { advance(); return (char) last; }
public double nextDouble() throws IOException
{
advance();
if (last == -1) throw new EOFException();
int s = 1;
if (last == '-')
{
s = -1; last = read();
if (last == -1) throw new EOFException();
}
double n = 0;
while (true)
{
n = n * 10 + last - '0'; last = read();
if (!isValidChar(last) || last == '.') break;
}
if (last == '.')
{
last = read();
if (last == -1) throw new EOFException();
double m = 1;
while (true)
{
m = m / 10;
n = n + (last - '0') * m; last = read();
if (!isValidChar(last)) break;
}
}
return n * s;
}
public BigDecimal nextBigDecimal() throws IOException { return new BigDecimal(nextString()); }
public int[] nextIntArray(int len) throws IOException
{
int[] A = new int[len];
for (int i = 0; i < len; i++) A[i] = nextInt();
return A;
}
public long[] nextLongArray(int len) throws IOException
{
long[] A = new long[len];
for (int i = 0; i < len; i++) A[i] = nextLong();
return A;
}
public int[][] nextIntTable(int rows, int cols) throws IOException
{
int[][] T = new int[rows][];
for (int i = 0; i < rows; i++) T[i] = nextIntArray(cols);
return T;
}
}
class Output
{
final int SIZE = 4096; // 4096; 8192
Writer out;
char[] cb = new char[SIZE];
int nChars = SIZE, nextChar = 0;
char lineSeparator = '\n';
public Output(OutputStream stream) { out = new OutputStreamWriter(stream); }
void flushBuffer() throws IOException
{
if (nextChar == 0) return;
out.write(cb, 0, nextChar);
nextChar = 0;
}
void write(int c) throws IOException
{
if (nextChar >= nChars) flushBuffer();
cb[nextChar++] = (char) c;
}
void write(String s, int off, int len) throws IOException
{
int b = off, t = off + len;
while (b < t)
{
int a = nChars - nextChar, a1 = t - b;
int d = a < a1 ? a : a1;
s.getChars(b, b + d, cb, nextChar);
b += d;
nextChar += d;
if (nextChar >= nChars) flushBuffer();
}
}
void write(String s) throws IOException { write(s, 0, s.length()); }
public void print(Object obj) throws IOException { write(String.valueOf(obj)); }
public void println(Object obj) throws IOException
{
write(String.valueOf(obj));
write(lineSeparator);
}
public void printf(String format, Object... obj) throws IOException { write(String.format(format, obj)); }
public void printElements(Object... obj) throws IOException
{
for (int i = 0; i < obj.length; i++)
{
if (i > 0) print(" ");
print(obj[i]);
}
print(lineSeparator);
}
public void close() throws IOException
{
flushBuffer();
out.close();
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 779e0586716b5707faac940de4e2c92e | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.File;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n=Integer.parseInt(in.nextLine());
String[] arr= new String[n];
int arr2[]= new int[n];
for (int i = 0; i < n; i++) {
arr[i]=in.nextLine();
if(arr[i].endsWith("lala."))arr2[i]+=1;
if(arr[i].startsWith("miao."))arr2[i]+=2;
}
for (int i = 0; i < arr2.length; i++) {
if(arr2[i]==1)System.out.println("Freda's");
else if(arr2[i]==2)System.out.println("Rainbow's");
else System.out.println("OMG>.< I don't know!");
}
}
private static void print(Object... rs) {
System.err.println(Arrays.deepToString(rs).replace("],", "]\n"));
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 8e7800a0f7a2e5e807cdc20728821796 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.Scanner;
public class Whosesentenceisit
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int n = input.nextInt();
input.nextLine();
String s;
boolean start, end;
for (int i = 0; i < n; ++i)
{
s = input.nextLine();
start = s.startsWith("miao.");
end = s.endsWith("lala.");
if (end && !start)
{
System.out.println("Freda's");
}
else if (start && !end)
{
System.out.println("Rainbow's");
}
else
{
System.out.println("OMG>.< I don't know!");
}
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | f369e2aa81f1cea6c17cc5a0e5ec35d0 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
public class A312 {
public static void main(String[] args){
Scanner br = new Scanner(System.in);
int n = br.nextInt();
br.nextLine();
for(int i = 0;i<n;i++){
String line = br.nextLine();
if(line.startsWith("miao.") && line.endsWith("lala.")){
System.out.println("OMG>.< I don't know!");
}
else if(line.startsWith("miao.")){
System.out.println("Rainbow's");
}
else if(line.endsWith("lala.")){
System.out.println("Freda's");
}
else{
System.out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 4ac48e62e37a4c225e4b159650789b24 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | //in the name of god
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args)throws IOException{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
String f=s.nextLine();
for(int i=0;i<n;i++){
String g=s.nextLine();
if(g.startsWith("miao.")&&!g.endsWith("lala."))
System.out.println("Rainbow's");
else if(!g.startsWith("miao.")&&g.endsWith("lala."))
System.out.println("Freda's");
else
System.out.println("OMG>.< I don't know!");
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 9b78ded86de308671a5bed7cc2f386b5 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | // in the name fo god
import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args)throws IOException{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(b.readLine());
for(int i=0;i<n;i++){
String g=b.readLine();
if(g.startsWith("miao.")&&!g.endsWith("lala."))
System.out.println("Rainbow's");
else if(!g.startsWith("miao.")&&g.endsWith("lala."))
System.out.println("Freda's");
else
System.out.println("OMG>.< I don't know!");
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | f5f3769191f21db85f3642d55863bf38 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
private static String chekLalaOrMiao(String l) {
if (l.length() < 5) {
return "OMG>.< I don't know!";
} else if (l.startsWith("miao.") && !(l.endsWith("lala."))) {
return "Rainbow's";
} else if (l.endsWith("lala.") && !(l.startsWith("miao."))) {
return "Freda's";
} else {
return "OMG>.< I don't know!";
}
}
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String n = bf.readLine();
int counter = Integer.parseInt(n);
while (counter != 0) {
String l = bf.readLine();
String res = chekLalaOrMiao(l);
System.out.println(res);
counter--;
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | ae482081962c7043819bc2995063c9c0 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.Scanner;
/**
*
* @author Javi
*/
public class WhoseSentence {
private static String LALA = "lala.";
private static String MIAO = "miao.";
private static String FREDA = "Freda's";
private static String RAINBOW = "Rainbow's";
private static String OMG = "OMG>.< I don't know!";
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] input = in.nextLine().split(" ");
int n = Integer.parseInt(input[0]);
for (int i = 0; i < n; i++) {
String nextLine = in.nextLine();
int lalaIndex = nextLine.lastIndexOf(LALA);
int miaoIndex = nextLine.indexOf(MIAO);
if(lalaIndex == (nextLine.length() - LALA.length()) && miaoIndex != 0) {
System.out.println(FREDA);
} else if (miaoIndex == 0 && lalaIndex != (nextLine.length() - LALA.length())) {
System.out.println(RAINBOW);
} else {
System.out.println(OMG);
}
}
in.close();
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 188023e47d863e5a5339e2f14fe5f0d0 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
while(n-->0){
String cadena = sc.nextLine();
int leng = cadena.length();
boolean rainbow = false;
boolean freeda = false;
if(leng<5){
System.out.println("OMG>.< I don't know!");
}else{
rainbow = cadena.substring(0,5).equals("miao.");
freeda = cadena.substring(leng-5).equals("lala.");
if(rainbow && freeda){
System.out.println("OMG>.< I don't know!");
}else{
if(rainbow){
System.out.println("Rainbow's");
}else{
if(freeda){
System.out.println("Freda's");
}else{
System.out.println("OMG>.< I don't know!");
}
}
}
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | d6df5b224759b7cf241bf3ae4cbab23c | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
public class HelloWorld {
InputReader input;
PrintWriter output;
void run(){
output = new PrintWriter(new OutputStreamWriter(System.out));
input = new InputReader(System.in);
solve();
output.flush();
}
public static void main(String[] args){
new HelloWorld().run();
}
void solve() {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
try {
int t = Integer.parseInt(read.readLine());
while(t-- > 0) {
String sentence = read.readLine();
if(sentence.startsWith("miao.") && !sentence.endsWith("lala.")) {
output.println("Rainbow's");
}
else if(sentence.endsWith("lala.") && !sentence.startsWith("miao.")) {
output.println("Freda's");
}
else {
output.println("OMG>.< I don't know!");
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public Long readLong() {
return Long.parseLong(readString());
}
public Double readDouble() {
return Double.parseDouble(readString());
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | c71332213207736de231bdb6d67080fe | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class sentence{
public static void main(String[]args)throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
byte x=Byte.parseByte(br.readLine());boolean flag;
for(int i=0; i<x; i++){
flag=true;
String s=br.readLine();
if(s.length()<5) {System.out.println("OMG>.< I don't know!"); flag=false;}
if(flag){
if (s.substring(0, 5).equals("miao."))
if (s.substring(s.length()-5).equals("lala."))
{System.out.println("OMG>.< I don't know!"); flag=false;}
else {System.out.println("Rainbow's"); flag=false;}
else if(s.substring(s.length()-5).equals("lala.") && flag) {
System.out.println("Freda's"); flag=false;}
if(flag) System.out.println("OMG>.< I don't know!");
}
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 91619f7f378a7e70d7cf4f5e61aeb3fa | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.DataInputStream;
public class Main {
public static void main(String args[])throws Exception
{
int nt,n,c;
String a;
//scanf("%d",&nt);
DataInputStream dis=new DataInputStream(System.in);
nt=Integer.parseInt(dis.readLine());
while(nt-->0)
{
//scanf("%c",&c);
a=dis.readLine();
n=a.length();
if(n>=5)
{
if(a.charAt(n-5)=='l' && a.charAt(n-4)=='a' && a.charAt(n-3)=='l' && a.charAt(n-2)=='a' && a.charAt(n-1)=='.'&&a.charAt(0)=='m' && a.charAt(1)=='i' && a.charAt(2)=='a' && a.charAt(3)=='o' && a.charAt(4)=='.')
{
System.out.println("OMG>.< I don't know!");
}
else if (a.charAt(n-5)=='l' && a.charAt(n-4)=='a' && a.charAt(n-3)=='l' && a.charAt(n-2)=='a' && a.charAt(n-1)=='.')
{
System.out.println("Freda's");
}
else if(a.charAt(0)=='m' && a.charAt(1)=='i' && a.charAt(2)=='a' && a.charAt(3)=='o' && a.charAt(4)=='.')
{
System.out.println("Rainbow's");
}
else
{
System.out.println("OMG>.< I don't know!");
//printf("2");
}
}
else
{
System.out.println("OMG>.< I don't know!");
// printf("3");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 81e49bc2edab267afd7ed5fe8e6d01ec | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
String x = "";
Scanner k = new Scanner(System.in);
int n = Integer.parseInt(k.nextLine());
for ( int i = 0 ; i<n ; i++)
{
x = k.nextLine();
if (x.length() < 5)
System.out.println("OMG>.< I don't know!");
else
{
boolean one = (x.charAt(0)=='m') && (x.charAt(1)=='i') && (x.charAt(2)=='a') && (x.charAt(3)=='o') && (x.charAt(4)=='.') ;
boolean two = (x.charAt(x.length()-1)=='.') && (x.charAt(x.length()-2)=='a') && (x.charAt(x.length()-3)=='l') && (x.charAt(x.length()-4)=='a') && (x.charAt(x.length()-5)=='l') ;
if (one && !two)
System.out.println("Rainbow's");
else
if (!one && two)
System.out.println("Freda's");
else
System.out.println("OMG>.< I don't know!");
}
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | fc007d14d011de52087a84978577bbc3 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String args[]) throws Exception {
BufferedReader stdin = new BufferedReader(new InputStreamReader(
System.in));
int y = Integer.parseInt(new StringTokenizer(stdin.readLine())
.nextToken());
for (int i = 0; i < y; i++) {
String x = stdin.readLine();
if(x.length() > 4 ){
boolean miao = x.substring(0, 5).equals("miao.");
boolean lala = x.substring(x.length() - 5, x.length()).equals("lala.");
if (miao && !lala)
System.out.println("Rainbow's");
else if (lala && !miao)
System.out.println("Freda's");
else
System.out.println("OMG>.< I don't know!");
}
else
System.out.println("OMG>.< I don't know!");
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | f60f24e93bab3e0289c57d099d88fbe3 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
sc.nextLine();
for (; x > 0; x--) {
String s = sc.nextLine();
if (s.startsWith("miao.") && s.endsWith("lala."))
System.out.println("OMG>.< I don't know!");
else {
if (s.startsWith("miao."))
System.out.println("Rainbow's");
else if (s.endsWith("lala."))
System.out.println("Freda's");
else
System.out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 3ffa72d1d9867d8574df73329deafc7b | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
public class sentence {
public static void main(String[] args)throws IOException {
BufferedReader bf = new BufferedReader (new InputStreamReader (System.in));
int tests = Integer.parseInt(bf.readLine());
for(int i = 0; i<tests; i++){
boolean rainbow = false;
boolean freda = false;
String line = bf.readLine();
if(line.length()<5)System.out.println("OMG>.< I don't know!");
else{
if(line.substring(0,5).equals("miao."))rainbow = true;
if(line.substring(line.length()-5).equals("lala."))freda = true;
if(freda&&rainbow)System.out.println("OMG>.< I don't know!");
else{if(!(freda||rainbow))System.out.println("OMG>.< I don't know!");
else{
if(freda){System.out.println("Freda's");}
else{System.out.println("Rainbow's");}
}
}
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 92aaaecd486d9f489400e2ea1d90067d | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.InputMismatchException;
public class Solution {
/**
* @param args
* @throws IOException
*/
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.endsWith("lala.") && !s.startsWith("miao."))
System.out.println("Freda's");
else if(!s.endsWith("lala.") && s.startsWith("miao."))
System.out.println("Rainbow's");
else
System.out.println("OMG>.< I don't know!");
}
}
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 readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
public void flush() {
writer.flush();
}
}
static class IOUtils {
public static int[] readIntArray(InputReader in, int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++)
array[i] = in.readInt();
return array;
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 2dac7293557f45dd93aeb374c6788a0f | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;
public class ProblemA {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = Integer.parseInt(s.nextLine());
for (int i = 0; i < n; i++) {
String a = s.nextLine();
int f = 0;
int r = 0;
if(a.startsWith("miao.")) r = 1;
if(a.endsWith("lala.")) f = 1;
if(f == 0 && r == 1){
System.out.println("Rainbow's");
}
else if(f == 1 && r == 0){
System.out.println("Freda's");
}
else System.out.println("OMG>.< I don't know!");
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 366295c2107e98993ca05718c87f8608 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.nextLine());
for(int i = 0; i < n; i++) {
String line = scan.nextLine();
boolean f = line.endsWith("lala.");
boolean r = line.startsWith("miao.");
if(f ^ r) {
System.out.printf("%s\n", f? "Freda's" : "Rainbow's");
} else {
System.out.println("OMG>.< I don't know!");
}
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | ee099182ed39c1a887530eaedfc3d87e | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int TC = Integer.parseInt(in.nextLine());
for(int i = 0; i < TC; i++) {
String line = in.nextLine();
boolean fred = false;
boolean rainbow = false;
rainbow = line.startsWith("miao.");
fred = line.endsWith("lala.");
if(fred ^ rainbow) {
System.out.printf("%s's\n", fred? "Freda":"Rainbow" );
} else {
System.out.println("OMG>.< I don't know!");
}
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 9d6827630c2bd859f1181d234e95d4f6 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.Scanner;
public class r185d2a {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
scan.nextLine();
for(int i=0; i < N; i++){
String line = scan.nextLine();
boolean lala = line.endsWith("lala.");
boolean miao = line.startsWith("miao.");
if(!(lala ^ miao)){
System.out.println("OMG>.< I don't know!");
} else if (lala){
System.out.println("Freda's");
} else if(miao){
System.out.println("Rainbow's");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | f1ab2d63fd5292a664917a00cbad59e3 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws NumberFormatException , IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String s[] = new String[n];
for(int i=0 ;i<n;i++){
s[i] = br.readLine();
}
for(int i=0;i<n;i++) {
if(s[i].startsWith("miao.") && s[i].endsWith("lala."))
System.out.println("OMG>.< I don't know!");
else if (s[i].endsWith("lala."))
System.out.println("Freda's");
else if(s[i].startsWith("miao."))
System.out.println("Rainbow's");
else System.out.println("OMG>.< I don't know!");
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | b4fb89096152c994710d952b9d65b9b8 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class A
{
String line;
StringTokenizer inputParser;
BufferedReader is;
FileInputStream fstream;
DataInputStream in;
String FInput="";
void openInput(String file)
{
if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
else
{
try{
fstream = new FileInputStream(file);
in = new DataInputStream(fstream);
is = new BufferedReader(new InputStreamReader(in));
}catch(Exception e)
{
System.err.println(e);
}
}
}
void readNextLine()
{
try {
line = is.readLine();
inputParser = new StringTokenizer(line, " ");
//System.err.println("Input: " + line);
} catch (IOException e) {
System.err.println("Unexpected IO ERROR: " + e);
}
catch (NullPointerException e)
{
line=null;
}
}
int NextInt()
{
String n = inputParser.nextToken();
int val = Integer.parseInt(n);
//System.out.println("I read this number: " + val);
return val;
}
long NextLong()
{
String n = inputParser.nextToken();
long val = Long.parseLong(n);
//System.out.println("I read this number: " + val);
return val;
}
String NextString()
{
String n = inputParser.nextToken();
return n;
}
void closeInput()
{
try {
is.close();
} catch (IOException e) {
System.err.println("Unexpected IO ERROR: " + e);
}
}
public static void main(String [] argv)
{
String filePath=null;
if(argv.length>0)filePath=argv[0];
new A(filePath);
}
public void readFInput()
{
for(;;)
{
try
{
readNextLine();
FInput+=line+" ";
}
catch(Exception e)
{
break;
}
}
inputParser = new StringTokenizer(FInput, " ");
}
public A(String inputFile)
{
openInput(inputFile);
readNextLine();
int n=NextInt();
for(int i=0; i<n; i++)
{
readNextLine();
boolean a=false, b=false;
if(line.length()>=5)
{
if(line.lastIndexOf("lala.")==line.length()-5)a=true;
if(line.indexOf("miao.")==0)b=true;
}
if(a==b)
{
System.out.println("OMG>.< I don't know!");
}
else
{
if(a)System.out.println("Freda's");
else System.out.println("Rainbow's");
}
}
closeInput();
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 3c5e47bf9f73def5ed22527e240749ef | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.regex.*;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import static java.lang.System.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class P312A{
static PrintStream ps;
public static void main(String[] args)throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(in));
ps = new PrintStream(new BufferedOutputStream(out));
StringTokenizer st;
String freda = "lala.";
String rbow = "miao.";
int t = Integer.valueOf(br.readLine());
while(t-->0){
String s = br.readLine();
if(s.length()<5){
ps.println("OMG>.< I don't know!");
}else{
String first = s.substring(0, 5);
String last = s.substring(s.length()-5, s.length());
boolean r = first.compareTo("miao.")==0;
boolean f = last.compareTo("lala.")==0;
if((r && f) || (!r && !f)){
ps.println("OMG>.< I don't know!");
}else if(r){
ps.println("Rainbow's");
}else if(f){
ps.println("Freda's");
}
}
}
ps.flush();
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 1e59910002fc145adb99802d1e7f49ce | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
public class sentance
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int numOfSen=Integer.parseInt(input.nextLine());
String[] arr=new String[numOfSen];
for(int i=0;i<=numOfSen-1;i++)
{
String str=input.nextLine();
if (str.endsWith("lala.") && str.startsWith("miao.") )
arr[i]="OMG>.< I don't know!";
else if (str.endsWith("lala."))
arr[i]="Freda's";
else if (str.startsWith("miao."))
arr[i]="Rainbow's";
else
arr[i]="OMG>.< I don't know!";
}//end for
for(int j=0; j <= arr.length-1;j++)
System.out.println(arr[j]);
}//end main
}//end of class | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | f19187b3ee236ad6be5c06e524a3c8b1 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.math.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int tc = in.nextInt();
String str = in.nextLine();
for(int t = 0;t<tc;t++)
{
str = in.nextLine();
if(str.startsWith("miao.") && str.endsWith("lala."))
System.out.println("OMG>.< I don't know!");
else if(str.endsWith("lala."))
System.out.println("Freda's");
else if(str.startsWith("miao."))
System.out.println("Rainbow's");
else
System.out.println("OMG>.< I don't know!");
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | fc8125ee1871803936b075fb28a68e23 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
public class Main{
public static void main (String[] args) throws IOException
{
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(buffer.readLine());
while(n-- > 0)
{
String line = buffer.readLine();
if(line.startsWith("miao.") && line.endsWith("lala."))
System.out.println("OMG>.< I don't know!");
else if(line.startsWith("miao."))
System.out.println("Rainbow's");
else if(line.endsWith("lala."))
System.out.println("Freda's");
else
System.out.println("OMG>.< I don't know!");
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 10aa9973c655f8ae22b809c3defc5a19 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class ProblemA {
void run() {
FastScanner sc = new FastScanner(System.in);
int N = Integer.parseInt(sc.nextLine());
for (int i = 0; i < N; ++i) {
String line = sc.nextLine();
boolean f = line.endsWith("lala.");
boolean r = line.startsWith("miao.");
String ans;
if (f ^ r) {
if (f) {
ans = "Freda's";
}
else {
ans = "Rainbow's";
}
}
else {
ans = "OMG>.< I don't know!";
}
p("%s\n", ans);
}
}
boolean debug = false;
void p(String f, Object...params) {
System.out.printf(f, params);
}
void d(Object...params) {
if (debug) {
p("DEBUG: %s\n", Arrays.deepToString(params));
}
}
static void die() {
throw new RuntimeException();
}
void timeout() {
for (int x = 0; ; ++x);
}
String join(Collection<?> s, String delimiter) {
StringBuilder builder = new StringBuilder();
Iterator<?> iter = s.iterator();
while (iter.hasNext()) {
builder.append(iter.next());
if (iter.hasNext()) {
builder.append(delimiter);
}
}
return builder.toString();
}
public ProblemA(String[] args) {
if (args.length > 0 && args[0].equals("debug")) {
debug = true;
}
}
public static void main(String[] args) {
new ProblemA(args).run();
}
private static class FastScanner {
private BufferedReader in;
private StringTokenizer tok;
public FastScanner(InputStream inputstream) {
in = new BufferedReader(new InputStreamReader(inputstream));
tok = null;
}
private void tokenizeLine() {
try {
String line = in.readLine();
if (line == null) die();
tok = new StringTokenizer(line);
} catch (IOException e) {
die();
}
}
public String next() {
while (tok == null || !tok.hasMoreTokens()) {
tokenizeLine();
}
return tok.nextToken();
}
public boolean hasNextLine() {
if (tok == null) {
try {
tokenizeLine();
}
catch (Exception e) {
return false;
}
}
return true;
}
public String nextLine() {
if (tok == null) {
tokenizeLine();
}
String ret = tok.hasMoreTokens() ? tok.nextToken("\n"): "";
tok = null;
return ret;
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 943e4dff242ec1cb5f22aa26043b4d5a | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
public class A {
public static void main(String[] Args) throws IOException {
new A().solve();
}
int o = -INF;
void solve() throws IOException {
int n=Integer.parseInt(rline());
String[] ss = new String[n];
for (int i = 0; i < ss.length; i++){
ss[i]=rline();
}
for(String s: ss){
if (begin(s) && end(s)) System.out.println("OMG>.< I don't know!");
else if (begin(s)) System.out.println("Rainbow's");
else if (end(s)) System.out.println("Freda's");
else System.out.println("OMG>.< I don't know!");
}
}
boolean begin(String s){
String l="miao.";
if (s.length() < l.length()) return false;
for (int i = 0; i < s.length() && i < l.length(); i++) {
if(s.charAt(i)!=l.charAt(i)) return false;
}
return true;
}
boolean end(String s){
String l="lala.";
if (s.length() < l.length()) return false;
for (int i = s.length()-1, j=l.length()-1;i>=0 && j>=0; i--, j--) {
if(s.charAt(i)!=l.charAt(j)) return false;
}
return true;
}
// ----------------------- Library ------------------------
void initSystem() throws IOException {
if (br != null)
br.close();
br = new BufferedReader(new InputStreamReader(System.in));
}
void initFile() throws IOException {
if (br != null)
br.close();
br = new BufferedReader(new InputStreamReader(new FileInputStream(
"input.txt")));
}
void printWriter() {
try {
PrintWriter pr = new PrintWriter("output.txt");
pr.println("hello world");
pr.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void comparator() {
Point[] v = new Point[10];
Arrays.sort(v, new Comparator<Point>() {
@Override
public int compare(Point a, Point b) {
if (a.x != b.x)
return -(a.x - b.x);
return a.y - b.y;
}
});
}
double distance(Point a, Point b) {
double dx = a.x - b.x, dy = a.y - b.y;
return Math.sqrt(dx * dx + dy * dy);
}
Scanner in = new Scanner(System.in);
String ss() {
return in.next();
}
String sline() {
return in.nextLine();
}
int si() {
return in.nextInt();
}
int[] sai(int n) {
int[] a = new int[n];
for (int i = 0; i < a.length; i++) {
a[i] = in.nextInt();
}
return a;
}
int[] sai_(int n) {
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = in.nextInt();
}
return a;
}
BufferedReader br;
StringTokenizer tokenizer;
{
br = new BufferedReader(new InputStreamReader(System.in));
}
void tok() throws IOException {
tokenizer = new StringTokenizer(br.readLine());
}
int toki() throws IOException {
return Integer.parseInt(tokenizer.nextToken());
}
int[] rint(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < a.length; i++)
a[i] = Integer.parseInt(tokenizer.nextToken());
return a;
}
int[] rint_(int n) throws IOException {
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++)
a[i] = Integer.parseInt(tokenizer.nextToken());
return a;
}
String[] rstrlines(int n) throws IOException {
String[] a = new String[n];
for (int i = 0; i < n; i++) {
a[i] = br.readLine();
}
return a;
}
long tokl() {
return Long.parseLong(tokenizer.nextToken());
}
double tokd() {
return Double.parseDouble(tokenizer.nextToken());
}
String toks() {
return tokenizer.nextToken();
}
String rline() throws IOException {
return br.readLine();
}
List<Integer> toList(int[] a) {
List<Integer> v = new ArrayList<Integer>();
for (int i : a)
v.add(i);
return v;
}
static void pai(int[] a) {
System.out.println(Arrays.toString(a));
}
static int toi(Object s) {
return Integer.parseInt(s.toString());
}
static int[] dx_ = { 0, 0, 1, -1 };
static int[] dy_ = { 1, -1, 0, 0 };
static int[] dx3 = { 1, -1, 0, 0, 0, 0 };
static int[] dy3 = { 0, 0, 1, -1, 0, 0 };
static int[] dz3 = { 0, 0, 0, 0, 1, -1 };
static int[] dx = { 1, 0, -1, 1, -1, 1, 0, -1 }, dy = { 1, 1, 1, 0, 0, -1,
-1, -1 };
static int INF = 2147483647; // =2^31-1 // -8
static long LINF = 922337203854775807L; // -8
static short SINF = 32767; // -32768
// finds GCD of a and b using Euclidian algorithm
public int GCD(int a, int b) {
if (b == 0)
return a;
return GCD(b, a % b);
}
static List<String> toList(String[] a) {
return Arrays.asList(a);
}
static String[] toArray(List<String> a) {
String[] o = new String[a.size()];
a.toArray(o);
return o;
}
static int[] pair(int... a) {
return a;
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 4a1c61f3dbab0b5d4e75fdd8199ad417 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main (String [] args) throws IOException {
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
int n = Integer.parseInt(br.readLine());
int check[] = new int [n];
for(int i=0 ; i<n ; i++){
String str = br.readLine();
if(str.endsWith("lala.")){
if(!(str.startsWith("miao.")))
check[i]=1;}
else
if(str.startsWith("miao."))
check[i]=2;
}
for(int x:check)
switch(x){
case 0 : System.out.println("OMG>.< I don't know!");break;
case 1 : System.out.println("Freda's") ;break;
case 2 : System.out.println("Rainbow's") ;break;
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | ce0a812598dc7d9aedc8c4d3b52a1846 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created with IntelliJ IDEA.
* User: Alexander Shchegolev
* Date: 26.05.13
* Time: 17:40
* To change this template use File | Settings | File Templates.
*/
public class One {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(reader.readLine());
for (int i = 0; i < n; i++) {
String s = reader.readLine();
boolean c1 = s.matches(".*lala\\.$");
boolean c2 = s.matches("^miao\\..*");
if ((c1 && c2) || (!c1 && !c2)){
System.out.println("OMG>.< I don't know!");
}else if (c1){
System.out.println("Freda's");
} else {
System.out.println("Rainbow's");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | e6d3e15c1be14f13762274157156310c | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.*;
public class whose {
public static void main(String[]args)throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr = new PrintWriter(System.out,true);
int n = Integer.parseInt(in.readLine());
for(int i = 0 ; i < n; i++)
{
boolean freda = false;
boolean rainbow = false;
String message = in.readLine();
int l = message.length();
if(l < 5);
else
{
if( message.substring(0,5).equals("miao.") )
rainbow = true;
if( message.substring(l-5,l).equals("lala."))
freda = true;
}
if(freda && rainbow)
pr.println("OMG>.< I don't know!");
else if(freda)
pr.println("Freda's");
else if(rainbow)
pr.println("Rainbow's");
else
pr.println("OMG>.< I don't know!");
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | ade20a805a13df5579f2069cd4ed7e92 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int N[] = new int[n];
scan.nextLine();
for(int i = 0;i<n;i++)
{
String s = scan.nextLine();
N[i] = 0;
if(s.lastIndexOf("lala.")==s.length()-5)
{
N[i] = 1;
}
if(s.indexOf("miao.")==0)
{
N[i] = 2;
}
if(s.lastIndexOf("lala.")==s.length()-5&&s.indexOf("miao.")==0)
{
N[i] = 0;
}
}
for(int i = 0;i<n;i++)
{
if(N[i]==0)
{
System.out.println("OMG>.< I don't know!");
}
if(N[i]==1)
{
System.out.println("Freda's");
}
if(N[i]==2)
{
System.out.println("Rainbow's");
}
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | c76200dae7b0e3dd6ce2b12181e11f9f | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class CF {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
PrintWriter out = new PrintWriter(outputStream);
int n = Integer.parseInt(reader.readLine());
for (int i = 0; i < n; i++) {
String s = reader.readLine();
if (s.endsWith("lala.") && !s.startsWith("miao.")) {
out.println("Freda's");
} else if (!s.endsWith("lala.") && s.startsWith("miao.")) {
out.println("Rainbow's");
} else {
out.println("OMG>.< I don't know!");
}
}
out.close();
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | d7732b66a8c29402be58df2db2b02b96 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;
import static java.lang.Math.*;
public class Codeforces_Solution_A implements Runnable{
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throws FileNotFoundException{
if (ONLINE_JUDGE){
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}else{
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
}
String readString() throws IOException{
while(!tok.hasMoreTokens()){
try{
tok = new StringTokenizer(in.readLine());
}catch (Exception e){
return null;
}
}
return tok.nextToken();
}
int readInt() throws IOException{
return Integer.parseInt(readString());
}
long readLong() throws IOException{
return Long.parseLong(readString());
}
double readDouble() throws IOException{
return Double.parseDouble(readString());
}
public static void main(String[] args){
new Thread(null, new Codeforces_Solution_A(), "", 128 * (1L << 20)).start();
}
long timeBegin, timeEnd;
void time(){
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
long memoryTotal, memoryFree;
void memory(){
memoryFree = Runtime.getRuntime().freeMemory();
System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
}
void debug(Object... objects){
if (DEBUG){
for (Object o: objects){
System.err.println(o.toString());
}
}
}
public void run(){
try{
timeBegin = System.currentTimeMillis();
memoryTotal = Runtime.getRuntime().freeMemory();
init();
solve();
out.close();
time();
memory();
}catch (Exception e){
e.printStackTrace(System.err);
System.exit(-1);
}
}
boolean DEBUG = false;
void solve() throws IOException{
int n = readInt();
for (int i=0; i<n; i++) {
String s = in.readLine();
boolean f1 = false;
boolean f2 = false;
if (s.endsWith("lala.")) f1=true;
if (s.startsWith("miao.")) f2=true;
if (f1&f2) {
out.println("OMG>.< I don't know!");
continue;
}
if (f1) {
out.println("Freda's");
continue;
}
if (f2) {
out.println("Rainbow's");
continue;
}
out.println("OMG>.< I don't know!");
}
}
} | Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | eacdb6bcce4ce8037df52f66380cc402 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
private static String chekLalaOrMiao(String l) {
if (l.length() < 5) {
return "OMG>.< I don't know!";
} else if (l.startsWith("miao.") && !(l.endsWith("lala."))) {
return "Rainbow's";
} else if (l.endsWith("lala.") && !(l.startsWith("miao."))) {
return "Freda's";
} else {
return "OMG>.< I don't know!";
}
}
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String n = bf.readLine();
int counter = Integer.parseInt(n);
while (counter != 0) {
String l = bf.readLine();
String res = chekLalaOrMiao(l);
System.out.println(res);
counter--;
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | bca5dab9011fd46e74a23808cf322ee5 | train_002.jsonl | 1369582200 | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of his sentences. For each sentence in the chat record, help liouzhou_101 find whose sentence it is. | 256 megabytes | import java.util.*;
public class WhoseSentence312A
{
public static void main(String[] args)
{
// Set up scanner
Scanner sc = new Scanner(System.in);
// System.out.println("Enter n");
String num = sc.nextLine();
int n = Integer.valueOf(num);
for (int i=0; i<n; i++)
{
// System.out.println("Enter next sentence");
String st = sc.nextLine();
if (st.length() < 5) // Too short to find the substrings
{
System.out.println("OMG>.< I don't know!");
continue;
}
String first = st.substring(0,5);
String last = st.substring(st.length()-5);
if (first.equals("miao.") && (last.equals("lala.")))
{
System.out.println("OMG>.< I don't know!");
}
else if (first.equals("miao."))
{
System.out.println("Rainbow's");
}
else if (last.equals("lala."))
{
System.out.println("Freda's");
}
else
{
System.out.println("OMG>.< I don't know!");
}
}
}
}
| Java | ["5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao ."] | 2 seconds | ["Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"] | null | Java 6 | standard input | [
"implementation",
"strings"
] | ee9ba877dee1a2843e885a18823cbff0 | The first line of the input contains an integer n (1 ≤ n ≤ 10), number of sentences in the chat record. Each of the next n lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | 1,100 | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditions. | standard output | |
PASSED | 0086de9e1760db5448b013b6895f50b0 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;
public class Problem172E {
private static BhtmlNode rootNode = new BhtmlNode(null);
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<String> tokens = new ArrayList<>();
Stack<BhtmlNode> pathStack = new Stack<>();
BhtmlNode currentNode = rootNode;
for (String token: sc.nextLine().split("<|>")) {
if (token.isEmpty()) {
continue;
}
if (token.startsWith("/")) {
currentNode = pathStack.pop();
continue;
}
if ( ! token.endsWith("/")) {
currentNode.children.add(new BhtmlNode(token));
pathStack.push(currentNode);
currentNode = currentNode.children.get(currentNode.children.size() - 1);
} else {
currentNode.children.add(new BhtmlNode(token.substring(0, token.length() - 1)));
}
}
int m = Integer.parseInt(sc.nextLine());
for (int i = 0; i < m; ++i) {
System.out.println(rootNode.search(sc.nextLine().split("\\s"), 0));
}
sc.close();
}
private static class BhtmlNode {
private String tag;
public List<BhtmlNode> children = new ArrayList<>();
public BhtmlNode(String tag) {
this.tag = tag;
}
public int search(String[] query, int position) {
int found = 0;
if (this.tag != null && this.tag.equals(query[position])) {
if (position + 1 == query.length) {
++found;
} else {
++position;
}
}
for (BhtmlNode child: this.children) {
found += child.search(query, position);
}
return found;
}
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 8 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | 2b7bd02288a0724fa4d0dd64053fe550 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.util.Scanner;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
public class e {
private static BhtmlNode rootNode = new BhtmlNode(null);
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<String> tokens = new ArrayList<>();
Stack<BhtmlNode> pathStack = new Stack<>();
BhtmlNode currentNode = rootNode;
for (String token: sc.nextLine().split("<|>")) {
if (token.isEmpty()) {
continue;
}
if (token.startsWith("/")) {
currentNode = pathStack.pop();
continue;
}
if ( ! token.endsWith("/")) {
currentNode.children.add(new BhtmlNode(token));
pathStack.push(currentNode);
currentNode = currentNode.children.get(currentNode.children.size() - 1);
} else {
currentNode.children.add(new BhtmlNode(token.substring(0, token.length() - 1)));
}
}
int m = Integer.parseInt(sc.nextLine());
for (int i = 0; i < m; ++i) {
System.out.println(rootNode.search(sc.nextLine().split("\\s"), 0));
}
sc.close();
}
private static class BhtmlNode {
private String tag;
public List<BhtmlNode> children = new ArrayList<>();
public BhtmlNode(String tag) {
this.tag = tag;
}
public int search(String[] query, int position) {
int found = 0;
if (this.tag != null && this.tag.equals(query[position])) {
if (position + 1 == query.length) {
++found;
} else {
++position;
}
}
for (BhtmlNode child: this.children) {
found += child.search(query, position);
}
return found;
}
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 8 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | f29414ee3ecf2586c7efa22edd2905aa | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.util.Scanner;
import java.util.Stack;
import java.util.ArrayList;
public class e {
private final static BhtmlNode rootNode = new BhtmlNode(null);
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<String> tokens = new ArrayList<>();
Stack<BhtmlNode> pathStack = new Stack<>();
BhtmlNode currentNode = rootNode;
for (String token: sc.nextLine().split("<|>")) {
if (token.isEmpty()) {
continue;
}
if (token.startsWith("/")) {
currentNode = pathStack.pop();
continue;
}
if ( ! token.endsWith("/")) {
currentNode.children.add(new BhtmlNode(token));
pathStack.push(currentNode);
currentNode = currentNode.children.get(currentNode.children.size() - 1);
} else {
currentNode.children.add(
new BhtmlNode(token.substring(0, token.length() - 1))
);
}
}
int m = Integer.parseInt(sc.nextLine());
for (int i = 0; i < m; i++) {
System.out.println(rootNode.search(sc.nextLine().split("\\s"), 0));
}
sc.close();
}
}
class BhtmlNode {
private final String tag;
public final ArrayList<BhtmlNode> children = new ArrayList<>();
public BhtmlNode(final String tag) {
this.tag = tag;
}
public int search(final String[] query, int position) {
int found = 0;
if (this.tag != null && this.tag.equals(query[position])) {
if (position + 1 == query.length) {
found++;
} else {
position++;
}
}
for (BhtmlNode child: this.children) {
found += child.search(query, position);
}
return found;
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 8 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | e96c1c511d33ada2a0b54a08e7ce2638 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.util.Scanner;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
public class e {
private static BhtmlNode rootNode = new BhtmlNode(null);
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<String> tokens = new ArrayList<>();
Stack<BhtmlNode> pathStack = new Stack<>();
BhtmlNode currentNode = rootNode;
for (String token: sc.nextLine().split("<|>")) {
if (token.isEmpty()) {
continue;
}
if (token.startsWith("/")) {
currentNode = pathStack.pop();
continue;
}
if ( ! token.endsWith("/")) {
currentNode.children.add(new BhtmlNode(token));
pathStack.push(currentNode);
currentNode = currentNode.children.get(currentNode.children.size() - 1);
} else {
currentNode.children.add(new BhtmlNode(token.substring(0, token.length() - 1)));
}
}
int m = Integer.parseInt(sc.nextLine());
for (int i = 0; i < m; ++i) {
System.out.println(rootNode.search(sc.nextLine().split("\\s"), 0));
}
sc.close();
}
private static class BhtmlNode {
private String tag;
public List<BhtmlNode> children = new ArrayList<>();
public BhtmlNode(String tag) {
this.tag = tag;
}
public int search(String[] query, int position) {
int found = 0;
if (this.tag != null && this.tag.equals(query[position])) {
if (position + 1 == query.length) {
++found;
} else {
++position;
}
}
for (BhtmlNode child: this.children) {
found += child.search(query, position);
}
return found;
}
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 8 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | ea49f88bba24abc786bcfdf27a4abce8 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.*;
import java.util.*;
public class E implements Runnable {
private MyScanner in;
private PrintWriter out;
private String getName(String s, int from, int to) {
while (s.charAt(from) < 'a' || s.charAt(from) > 'z') {
++from;
}
while (s.charAt(to) < 'a' || s.charAt(to) > 'z') {
--to;
}
return s.substring(from, to + 1);
}
private List<Token> parse(String s) {
List<Token> result = new ArrayList<Token>();
int first = 0;
while (first < s.length()) {
int last = first;
while (s.charAt(last) != '>') {
++last;
}
Token newToken = new Token(s.charAt(first + 1) != '/', s
.charAt(first + 1) == '/'
|| s.charAt(last - 1) == '/', getName(s, first, last),
result.size());
result.add(newToken);
first = last + 1;
}
return result;
}
private void formPairs(List<Token> tokens) {
Map<String, Stack<Token>> openingTags = new HashMap<String, Stack<Token>>();
for (Token t : tokens) {
if (t.opening) {
if (t.closing) {
t.pair = t;
} else {
Stack<Token> already = openingTags.get(t.name);
if (already == null) {
already = new Stack<Token>();
already.push(t);
openingTags.put(t.name, already);
} else {
already.push(t);
}
}
} else {
if (t.closing) {
Stack<Token> already = openingTags.get(t.name);
Token curPair = already.pop();
t.pair = curPair;
curPair.pair = t;
} else {
throw new RuntimeException();
}
}
}
}
private Node makeTree(List<Token> tokens, int from, int to) {
if (from > to) {
return new Node(null);
}
List<Edge> children = new ArrayList<Edge>();
while (from <= to) {
int hi = tokens.get(from).pair.id;
Node child = makeTree(tokens, from + 1, hi - 1);
children.add(new Edge(child, tokens.get(from).name));
from = hi + 1;
}
return new Node(children);
}
private int countRules(Node v, String[] query, int pos) {
if (v.children == null) {
return 0;
}
int ans = 0;
for (Edge e : v.children) {
boolean eq = pos < query.length && query[pos].equals(e.name);
if (pos >= query.length - 1
&& query[query.length - 1].equals(e.name)) {
++ans;
}
ans += countRules(e.to, query, pos + (eq ? 1 : 0));
}
return ans;
}
private void solve() {
List<Token> parsed = parse(in.nextLine());
formPairs(parsed);
Node root = makeTree(parsed, 0, parsed.size() - 1);
int m = in.nextInt();
for (int i = 0; i < m; ++i) {
String[] query = in.nextLine().split(" ");
out.println(countRules(root, query, 0));
}
}
@Override
public void run() {
in = new MyScanner();
out = new PrintWriter(System.out);
solve();
in.close();
out.close();
}
public static void main(String[] args) {
new E().run();
}
class Token {
public boolean opening, closing;
public String name;
public Token pair;
public int id;
public Token(boolean opening, boolean closing, String name, int id) {
this.opening = opening;
this.closing = closing;
this.name = name;
this.id = id;
}
}
class Node {
public List<Edge> children;
public Node(List<Edge> children) {
this.children = children;
}
}
class Edge {
public Node to;
public String name;
public Edge(Node to, String name) {
this.to = to;
this.name = name;
}
}
static class MyScanner {
private BufferedReader br;
private StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
return st.nextToken();
}
public String nextLine() {
try {
st = null;
return br.readLine();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public boolean hasNext() {
if (st != null && st.hasMoreTokens()) {
return true;
}
try {
while (br.ready()) {
st = new StringTokenizer(br.readLine());
if (st != null && st.hasMoreTokens()) {
return true;
}
}
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | 30cc9bd793e16ad50d291e8eced5bca8 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class Solver {
static StringTokenizer st;
BufferedReader in;
PrintWriter out;
public static void main(String[] args) throws NumberFormatException, IOException {
Solver solver = new Solver();
solver.open();
solver.solve();
solver.close();
}
public void open() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
public String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
public int nextInt() throws NumberFormatException, IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(nextToken());
}
public static class Tree{
public static Tree parse(String name){
Tree result = new Tree(name);
while (st.hasMoreTokens()){
String nextTag = st.nextToken(">");
if (nextTag.charAt(1)=='/'){
return result;
}else if (nextTag.charAt(nextTag.length()-1)=='/'){
result.child.add(new Tree(nextTag.substring(1, nextTag.length()-1)));
}else{
result.child.add(Tree.parse(nextTag.substring(1)));
}
}
return result;
}
public List<Tree> child;
public String node;
public Tree(String node){
this.node = node;
this.child = new ArrayList<Tree>();
}
public String toString(){
return node+(child.size()>0 ? " -> "+child.toString() : "");
}
public int count(String node){
int result = this.node.equals(node) ? 1 : 0;
for (Tree tree : this.child){
result += tree.count(node);
}
return result;
}
public int check(List<String> rule, int current){
String nextNode = rule.get(current);
if (rule.size()-1==current){
return count(nextNode);
}
if (this.node.equals(nextNode)){
current++;
}
int result = 0;
for (Tree tree : child){
result += tree.check(rule,current);
}
return result;
}
}
public void solve() throws NumberFormatException, IOException {
st = new StringTokenizer(in.readLine());
Tree root = Tree.parse("/");
int n = nextInt();
List<String> rule = new ArrayList<String>(200);
for (int i = 0; i<n;i++){
rule.clear();
st = new StringTokenizer(in.readLine());
while(st.hasMoreTokens()){
rule.add(nextToken());
}
int result = root.check(rule, 0);
out.println(result);
}
}
public void close() {
out.flush();
out.close();
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | ff84a118976c689915b5d4ec1b73b0a6 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
static final int MAXN = 250100;
ArrayList<Integer> g [];
long hashcode [];
long hashes [];
int n, m;
int answer;
StringBuilder sb;
boolean isClosedTag (String tag) {
return tag.charAt(1) == '/';
}
boolean isOpenedClosedTag (String tag) {
return tag.charAt(tag.length() - 2) == '/';
}
long getHashCode (String tag) {
long ret = 0;
for (int i = 0; i < tag.length(); i++) {
if (tag.charAt(i) == '/' || tag.charAt(i) == '<' || tag.charAt(i) == '>') continue;
ret = ret * 31 + tag.charAt(i) - 'a' + 1;
}
return ret;
}
int readTag (String t, int pos, Stack<Integer> stack) {
sb = new StringBuilder();
int lastpos = pos;
for (int i = pos; i < t.length(); i++) {
sb.append(t.charAt(i));
if (t.charAt(i) == '>') {
lastpos = i + 1;
break;
}
}
int index = stack.peek();
String tag = sb.toString();
long hash = getHashCode(tag);
if (isOpenedClosedTag(tag)) {
hashcode[n] = hash;
g[index].add(n);
n++;
} else if (isClosedTag(tag)) {
stack.pop();
} else {
hashcode[n] = hash;
g[index].add(n);
stack.push(n);
n++;
}
return lastpos;
}
void dfs (int v, int index) {
if (hashcode [v] == hashes [index]) {
if (index == m - 1) answer++;
for (int to : g [v]) {
if (index == m - 1) {
dfs (to, index);
} else {
dfs (to, index + 1);
}
}
} else {
for (int to : g [v]) {
dfs (to, index);
}
}
}
public void solve () throws Exception {
g = new ArrayList [MAXN];
for (int i = 0; i < MAXN; i++) {
g [i] = new ArrayList<Integer>();
}
hashcode = new long [MAXN];
String t = in.readLine();
n = 1;
Stack<Integer> stack = new Stack<Integer>();
stack.push(0);
int pos = 0;
while (pos < t.length()) pos = readTag(t, pos, stack);
int q = nextInt();
for (int i = 0; i < q; i++) {
String query = in.readLine();
String tokens [] = query.split(" ");
m = tokens.length;
hashes = new long [m];
for (int j = 0; j < m; j++) {
hashes [j] = getHashCode(tokens[j]);
}
answer = 0;
dfs (0, 0);
out.println(answer);
}
}
final String fname = "";
long stime = 0;
BufferedReader in;
PrintWriter out;
StringTokenizer st;
private String nextToken () throws Exception {
if (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
private int nextInt () throws Exception {
return Integer.parseInt(nextToken());
}
private long nextLong () throws Exception {
return Long.parseLong(nextToken());
}
private double nextDouble () throws Exception {
return Double.parseDouble(nextToken());
}
@Override
public void run() {
try {
in = new BufferedReader (new InputStreamReader(System.in, "ISO-8859-1"));
out = new PrintWriter (new OutputStreamWriter(System.out, "ISO-8859-1"));
solve ();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
out.close();
}
}
public static void main(String[] args) {
new Thread(null, new Solution(), "", 1<<26).start();
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | a826ecd6876ebb8b40807c0fc625d24a | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.*;
import java.util.*;
public class E {
char[] s;
int p;
int[] e;
int res;
int cur = 0;
Map<String, Integer> map = new HashMap<String, Integer>();
StringBuffer sb = new StringBuffer(10);
Tag getTag() {
Tag r = new Tag();
r.type = 1;
++p;
if (s[p] == '/') {
r.type = 2;
++p;
}
sb.setLength(0);
while (s[p] != '>' && s[p] != '/') {
sb.append(s[p++]);
}
if (s[p] == '/') {
r.type = 3;
++p;
}
++p;
String key = sb.toString();
Integer id = map.get(key);
if (id == null) {
id = cur++;
map.put(key, id);
}
r.id = id;
return r;
}
void parse(Tree t) {
Tag tag;
while (p < s.length && (tag = getTag()).type != 2) {
Tree ch = new Tree(tag.id);
t.c.add(ch);
if (tag.type == 1) {
parse(ch);
}
}
}
void walk(Tree t, int i) {
if (t.id == e[i]) {
if (i == e.length - 1) {
++res;
} else {
++i;
}
}
for (Tree ch : t.c) {
walk(ch, i);
}
}
void solve() throws IOException {
in("__std"); out("__std");
s = readLine().toCharArray();
Tree t = new Tree(-1);
parse(t);
int m = readInt();
while (m-- > 0) {
StringTokenizer st = new StringTokenizer(readLine());
e = new int[st.countTokens()];
for (int i = 0; i < e.length; ++i) {
Integer id = map.get(st.nextToken());
if (id == null) {
e = null;
break;
}
e[i] = id;
}
res = 0;
if (e != null) {
walk(t, 0);
}
println(res);
}
exit();
}
class Tag {
int id;
int type;
}
class Tree {
int id;
List<Tree> c = new ArrayList<Tree>();
Tree(int id) {
this.id = id;
}
}
void in(String name) throws IOException {
if (name.equals("__std")) {
in = new BufferedReader(new InputStreamReader(System.in));
} else {
in = new BufferedReader(new FileReader(name));
}
}
void out(String name) throws IOException {
if (name.equals("__std")) {
out = new PrintWriter(System.out);
} else {
out = new PrintWriter(name);
}
}
void exit() {
out.close();
System.exit(0);
}
int readInt() throws IOException {
return Integer.parseInt(readToken());
}
long readLong() throws IOException {
return Long.parseLong(readToken());
}
double readDouble() throws IOException {
return Double.parseDouble(readToken());
}
String readLine() throws IOException {
st = null;
return in.readLine();
}
String readToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
boolean eof() throws IOException {
return !in.ready();
}
void print(String format, Object ... args) {
out.println(new Formatter(Locale.US).format(format, args));
}
void println(String format, Object ... args) {
out.println(new Formatter(Locale.US).format(format, args));
}
void print(Object value) {
out.print(value);
}
void println(Object value) {
out.println(value);
}
void println() {
out.println();
}
StringTokenizer st;
BufferedReader in;
PrintWriter out;
public static void main(String[] args) throws IOException {
new E().solve();
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | bad3a37da3f5e8ace2b7bca42c94b66f | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import javax.tools.ToolProvider;
import java.io.*;
import java.util.*;
/**
* @author Roman Elizarov
*/
public class Krok2012_E {
private static final int MAX_DEPTH = 200000;
public static void main(String[] args) throws IOException {
new Krok2012_E().go();
}
final List<String> tags = new ArrayList<String>();
final Map<String, Integer> tagIndex = new HashMap<String, Integer>();
{
tags.add(null);
}
static class Elem {
int tag;
Elem parent;
Elem[] children = new Elem[4];
int n;
int index;
int prefix;
Elem(int tag) {
this.tag = tag;
}
void add(Elem elem) {
if (n == children.length)
children = Arrays.copyOf(children, n * 2);
children[n++] = elem;
elem.parent = this;
}
}
char[] s;
int pos;
enum Token { OPEN, CLOSE, SELF_CLOSE, END }
Token curToken;
int curTag;
void nextToken() {
if (pos >= s.length) {
curToken = Token.END;
return;
}
curToken = null;
assert s[pos] == '<';
pos++;
if (s[pos] == '/') {
pos++;
curToken = Token.CLOSE;
}
curTag = parseTag();
if (curToken == null && s[pos] == '/') {
pos++;
curToken = Token.SELF_CLOSE;
}
if (curToken == null)
curToken = Token.OPEN;
assert s[pos] == '>';
pos++;
}
StringBuilder sb = new StringBuilder(10);
private int parseTag() {
sb.setLength(0);
while (s[pos] >= 'a' && s[pos] <= 'z')
sb.append(s[pos++]);
String s = sb.toString();
Integer index = tagIndex.get(s);
if (index == null) {
index = tags.size();
tags.add(s);
tagIndex.put(s, index);
}
return index;
}
Elem root = new Elem(0);
Elem[] stack = new Elem[MAX_DEPTH];
int stackSize;
void parseRoot() {
nextToken();
stackSize = 0;
stack[stackSize++] = root;
while (curToken != Token.END) {
Elem top = stack[stackSize - 1];
Elem cur = new Elem(curTag);
Token token = curToken;
nextToken();
switch (token) {
case OPEN:
stack[stackSize++] = cur;
// falls through
case SELF_CLOSE:
top.add(cur);
break;
case CLOSE:
assert top.tag == cur.tag;
stackSize--;
break;
default:
assert false;
}
}
assert stackSize == 1;
}
private void go() throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintStream out = System.out;
s = in.readLine().toCharArray();
parseRoot();
int m = Integer.parseInt(in.readLine().trim());
for (int i = 0; i < m; i++)
out.println(executeQuery(in.readLine().split("\\s+")));
}
int executeQuery(String[] qs) {
int n = qs.length;
int[] qi = new int[n];
for (int j = 0; j < n; j++) {
Integer index = tagIndex.get(qs[j]);
if (index == null)
return 0;
qi[j] = index;
}
stackSize = 0;
stack[stackSize++] = root;
root.index = 0;
root.prefix = 0;
int r = 0;
while (stackSize != 0) {
Elem top = stack[stackSize - 1];
int prefix = top.prefix;
if (top.index >= top.n) {
stackSize--;
} else {
Elem child = top.children[top.index++];
if (child.tag == qi[prefix])
if (prefix == n - 1)
r++;
else
prefix++;
child.index = 0;
child.prefix = prefix;
stack[stackSize++] = child;
}
}
return r;
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | 3516bbf445c1a4d64c78854e22b7e919 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.util.List;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Egor Kulikov (egor@egork.net)
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
}
class TaskE {
int start;
String document;
public void solve(int testNumber, InputReader in, OutputWriter out) {
document = in.readString();
List<Node> roots = new ArrayList<Node>();
while (start != document.length())
roots.add(build());
int queryCount = in.readInt();
for (int i = 0; i < queryCount; i++) {
String[] tags = in.readLine().split(" ");
int result = 0;
for (Node root : roots)
result += root.count(tags, 0);
out.printLine(result);
}
}
private Node build() {
String tag = null;
for (int i = start + 1; ; i++) {
if (document.charAt(i) == '>') {
tag = document.substring(start + 1, i);
start = i + 1;
break;
}
}
if (tag.charAt(tag.length() - 1) == '/')
return new Node(tag.substring(0, tag.length() - 1));
Node result = new Node(tag);
while (document.charAt(start + 1) != '/')
result.addChild(build());
start += tag.length() + 3;
return result;
}
static class Node {
final String tag;
List<Node> children;
Node(String tag) {
this.tag = tag;
}
Node addChild(Node node) {
if (children == null)
children = new ArrayList<Node>();
children.add(node);
return node;
}
public int count(String[] tags, int position) {
int result = 0;
if (tags[position].equals(tag)) {
if (position == tags.length - 1)
result++;
else
position++;
}
if (children != null) {
for (Node node : children)
result += node.count(tags, position);
}
return result;
}
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public static boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private String readLine0() {
StringBuffer buf = new StringBuffer();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public String readLine() {
String s = readLine0();
while (s.trim().length() == 0)
s = readLine0();
return s;
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(outputStream);
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | 54807f21067d03807e089afd94e86e0f | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.*;
import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;
public class Main implements Runnable {
final String filename = "maxtest";
public void writeTest() throws Exception {
for (int i = 0; i < 1000000 / 14; i++) {
out.write("<a><b>");
}
for (int i = 0; i < 1000000 / 14; i++) {
out.write("</b></a>");
}
out.write("\n200\n");
for (int i = 0; i < 200; i++) {
for (int j = 1; j < 200; j++)
out.write("a ");
out.write("a\n");
}
if (true)
return;
}
public void solve() throws Exception {
HashMap<String, Integer> names = new HashMap<String, Integer>();
StringBuilder sb = new StringBuilder();
String bhtml = readword();
int count = 0;
boolean close = false;
ArrayList<Integer> tags = new ArrayList<Integer>();
for (int pos = 0; pos < bhtml.length(); pos++) {
char d = bhtml.charAt(pos);
if (d == '<') {
close = false;
continue;
}
if (d == '>' || d == '/' && sb.length() > 0) {
if (sb.length() > 0) {
String tag = sb.toString();
sb.setLength(0);
int ind = 0;
if (names.containsKey(tag)) {
ind = names.get(tag);
} else {
ind = ++count;
names.put(tag, ind);
}
if (d == '/' | !close) {
tags.add(ind);
}
if (d == '/' | close) {
tags.add(-ind);
}
}
continue;
}
if (d == '/') {
close = true;
continue;
}
sb.append(d);
}
int tests = iread();
int k = 0;
int[] stack = new int[tags.size() + 1];
int cur = 0;
test: for (int ntest = 1; ntest <= tests; ntest++) {
String input = "";
while (input.length() == 0)
input = in.readLine().trim();
String[] tokens = input.split(" +");
int m = tokens.length;
int[] y = new int[m];
for (int i = 0; i < m; i++) {
if (!names.containsKey(tokens[i])) {
out.write("0\n");
continue test;
}
y[i] = names.get(tokens[i]);
}
int ans = 0;
for (Integer x : tags) {
if (x > 0) {
stack[k++] = cur;
if (cur >= m - 1 && y[m - 1] == x)
ans++;
if (cur < m && y[cur] == x)
cur++;
} else {
cur = stack[--k];
}
}
out.write(ans + "\n");
}
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new BufferedWriter(new OutputStreamWriter(System.out));
// in = new BufferedReader(new FileReader(filename + ".in"));
// out = new BufferedWriter(new FileWriter(filename + ".out"));
solve();
out.flush();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
public int iread() throws Exception {
return Integer.parseInt(readword());
}
public double dread() throws Exception {
return Double.parseDouble(readword());
}
public long lread() throws Exception {
return Long.parseLong(readword());
}
BufferedReader in;
BufferedWriter out;
public String readword() throws IOException {
StringBuilder b = new StringBuilder();
int c;
c = in.read();
while (c >= 0 && c <= ' ')
c = in.read();
if (c < 0)
return "";
while (c > ' ') {
b.append((char) c);
c = in.read();
}
return b.toString();
}
public static void main(String[] args) {
try {
Locale.setDefault(Locale.US);
} catch (Exception e) {
}
// new Thread(new Main()).start();
new Thread(null, new Main(), "1", 1 << 25).start();
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | cc98920be300abce5a721482854357c6 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
private StringTokenizer st;
private BufferedReader in;
private PrintWriter out;
static class Tree {
int tag;
Tree[] subtrees;
Tree(int tag) {
this.tag = tag;
}
int query(int[] q, int i) {
int ret = 0;
if (i < q.length && tag == q[i]) {
++i;
}
if (i == q.length) {
if (tag == q[i - 1]) {
ret++;
}
}
for (Tree sub: subtrees) {
ret += sub.query(q, i);
}
return ret;
}
}
int index;
ArrayList<Integer> tags;
HashMap<String, Integer> tagsMap = new HashMap<String, Integer>();
Tree parse() {
int start = tags.get(index++);
Tree tree = new Tree(start);
ArrayList<Tree> sub = new ArrayList<Tree>();
while (tags.get(index) != -start) {
sub.add(parse());
}
index++;
tree.subtrees = (Tree[]) sub.toArray(new Tree[sub.size()]);
return tree;
}
int get(String s) {
if (!tagsMap.containsKey(s)) {
tagsMap.put(s, tagsMap.size() + 1);
}
return tagsMap.get(s);
}
public void solve() throws IOException {
String s = next();
tags = new ArrayList<Integer>();
tags.add(1000000000);
for (int i = 0; i < s.length(); ) {
boolean close = false;
boolean closed = false;
i++;
if (s.charAt(i) == '/') {
close = true;
i++;
}
StringBuilder sb = new StringBuilder();
while (s.charAt(i) != '>') {
if (s.charAt(i) == '/') {
i++;
closed = true;
} else {
sb.append(s.charAt(i++));
}
}
i++;
int tag = get(sb.toString());
if (closed) {
tags.add(tag);
tags.add(-tag);
} else {
tags.add(close ? -tag : tag);
}
}
tags.add(-1000000000);
Tree t = parse();
int qs = nextInt();
loop: for (int it = 0; it < qs; ++it) {
String[] qStr = in.readLine().split(" ");
int[] q = new int[qStr.length];
for (int i = 0; i < q.length; ++i) {
if (!tagsMap.containsKey(qStr[i])) {
out.println(0);
continue loop;
}
q[i] = tagsMap.get(qStr[i]);
}
out.println(t.query(q, 0));
}
}
public void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
eat("");
solve();
out.close();
}
void eat(String s) {
st = new StringTokenizer(s);
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
eat(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static boolean failed = false;
public static void main(String[] args) throws IOException {
Locale.setDefault(Locale.US);
new Solution().run();
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | ad9557aed69ef8a6900c9ee13dd6d8d7 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class E172 {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
Parser parser = new Parser(in.readLine());
List<Token> list = new ArrayList<Token>();
while (true) {
Token s = parser.next();
if (s == null) break;
list.add(s);
}
int[] st = new int[N+1], st1 = new int[MAX+1];
int sp = 0, sp1 = 0;
int n = Integer.valueOf(in.readLine());
L : for (int cs = 0; cs < n; cs++) {
String[] t = in.readLine().split(" ");
int k = t.length;
int[] v = new int[k];
for (int i = 0; i < k; i++) {
if (!map.containsKey(t[i])) {
out.println(0);
continue L;
}
v[i] = map.get(t[i]);
}
int ans = 0, id = 0;
sp = 0;
sp1 = 0;
for (Token tk : list) {
if (tk.type == 1) {
if (tk.hash == v[sp]) {
if (sp == k-1) ans++;
else {
st[sp++] = id;
}
}
st1[sp1++] = id++;
}
else if (tk.type == 2) {
sp1--;
if (sp > 0 && st1[sp1] == st[sp-1]) sp--;
}
else if (tk.type == 3) {
if (tk.hash == v[sp]) {
if (sp == k-1) ans++;
}
}
}
out.println(ans);
}
out.flush();
}
static final int MAX = 1000000, N = 200;
static Map<String, Integer> map = new HashMap<String, Integer>(MAX);
static class Parser {
String s;
int p = 0;
Parser(String s) {
this.s = s;
}
Token next() {
String res = "";
p++;
if (p >= s.length()) return null;
while (s.charAt(p) != '>') {
res += s.charAt(p++);
}
int type = 1;
if (res.charAt(0) == '/') {
type = 2;
res = res.substring(1);
}
else if (res.charAt(res.length()-1) == '/') {
type = 3;
res = res.substring(0, res.length()-1);
}
p++;
return new Token(res, type);
}
}
static class Token {
int hash;
int type;
Token(String str, int type) {
if (!map.containsKey(str)) map.put(str, map.size());
this.hash = map.get(str);
this.type = type;
}
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | b84a83f7af0c5186e9dd36a478dd5766 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
public class E172 {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
Parser parser = new Parser(in.readLine());
List<Token> list = new ArrayList<Token>();
while (true) {
Token s = parser.next();
if (s == null) break;
list.add(s);
}
int[] st = new int[N+1], st1 = new int[MAX+1];
int sp = 0, sp1 = 0;
int n = Integer.valueOf(in.readLine());
for (int cs = 0; cs < n; cs++) {
String[] t = in.readLine().split(" ");
int k = t.length;
String[] v = new String[k];
for (int i = 0; i < k; i++) {
v[i] = t[i].intern();
}
int ans = 0, id = 0;
sp = 0;
sp1 = 0;
for (Token tk : list) {
if (tk.type == 1) {
if (tk.hash == v[sp]) {
if (sp == k-1) ans++;
else {
st[sp++] = id;
}
}
st1[sp1++] = id++;
}
else if (tk.type == 2) {
sp1--;
if (sp > 0 && st1[sp1] == st[sp-1]) sp--;
}
else if (tk.type == 3) {
if (tk.hash == v[sp]) {
if (sp == k-1) ans++;
}
}
}
out.println(ans);
}
out.flush();
}
static final int MAX = 1000000, N = 200;
static class Parser {
String s;
int p = 0;
Parser(String s) {
this.s = s;
}
Token next() {
String res = "";
p++;
if (p >= s.length()) return null;
while (s.charAt(p) != '>') {
res += s.charAt(p++);
}
int type = 1;
if (res.charAt(0) == '/') {
type = 2;
res = res.substring(1);
}
else if (res.charAt(res.length()-1) == '/') {
type = 3;
res = res.substring(0, res.length()-1);
}
p++;
return new Token(res, type);
}
}
static class Token {
String hash;
int type;
Token(String str, int type) {
this.hash = str.intern();
this.type = type;
}
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | 4259e8e06cdda6a7dca33a3b53af07db | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class Codeforces implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
Random rnd;
final long p = 43;
final int maxLevel = 200000;
int[] closePositions;
long[] hashes;
String[] tokens;
ArrayList<Integer> stack = new ArrayList<Integer>();
int[] pointers;
String[][] seqs;
long[][] seqsHashes;
long[] ans;
boolean[][] flags = new boolean[maxLevel][200];
void updateAnswer() {
if(stack.size() == 0) {
return;
}
int last = stack.get(stack.size() - 1);
long lastHash = hashes[last];
for(int i = 0; i < pointers.length; i++) {
if(pointers[i] == seqs[i].length && seqsHashes[i][pointers[i] - 1] == lastHash) {
++ans[i];
}
}
}
void upPointers(int level) {
Arrays.fill(flags[level], false);
int last = stack.get(stack.size() - 1);
long lastHash = hashes[last];
for(int i = 0; i < pointers.length; i++) {
if(pointers[i] < seqs[i].length && seqsHashes[i][pointers[i]] == lastHash) {
flags[level][i] = true;
++pointers[i];
}
}
}
void downPointers(int level) {
for(int i = 0; i < pointers.length; i++) {
if(flags[level][i]) {
--pointers[i];
}
}
}
void rec(int l, int r, boolean flag, int level) {
//out.println(l + " " + r+ " " + flag + " " + stack.size());
if(flag) {
updateAnswer();
}
if(l > r) {
return;
}
while(l <= r) {
int newL = l + 1, newR = closePositions[l] - 1;
stack.add(l);
upPointers(level);
rec(newL, newR, true, level + 1);
downPointers(level);
stack.remove(stack.size() - 1);
l = closePositions[l] + 1;
}
}
void parseTokens(String text) {
ArrayList<String> tokensVector = new ArrayList<String>();
int l = 0;
for(int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if(c == '<') {
l = i;
} else if(c == '>') {
String token = text.substring(l, i + 1);
tokensVector.add(token);
}
}
tokens = new String[tokensVector.size()];
for(int i = 0; i < tokensVector.size(); i++) {
tokens[i] = tokensVector.get(i);
}
}
int getType(String tag) {
if(tag.charAt(1) == '/') {
return 1;
} else if(tag.charAt(tag.length() - 2) == '/') {
return 2;
} else {
return 0;
}
}
long calcHash(String tag) {
long mod = 1, res = 0;
for(int i = 0; i < tag.length(); i++) {
long code = tag.charAt(i) - 32;
res += code * mod;
mod *= p;
}
return res;
}
void parsePositions(String[] tokens) {
stack.clear();
closePositions = new int[tokens.length];
Arrays.fill(closePositions, -1);
for(int i = 0; i < tokens.length; i++) {
String token = tokens[i];
int type = getType(token);
if(type == 0) {
stack.add(i);
} else if(type == 1) {
closePositions[stack.get(stack.size() - 1)] = i;
stack.remove(stack.size() - 1);
} else {
closePositions[i] = i;
}
}
}
void getHashes(String[] tokens) {
hashes = new long[tokens.length];
for(int i = 0; i < tokens.length; i++) {
String token = tokens[i], pureToken = null;
int type = getType(token);
if(type == 0) {
pureToken = token.substring(1, token.length() - 1);
} else if(type == 1) {
pureToken = token.substring(2, token.length() - 1);
} else {
pureToken = token.substring(1, token.length() - 2);
}
hashes[i] = calcHash(pureToken);
}
}
void solve() throws IOException {
String text = nextToken();
parseTokens(text);
parsePositions(tokens);
getHashes(tokens);
int m = nextInt();
seqs = new String[m][];
seqsHashes = new long[m][];
ans = new long[m];
pointers = new int[m];
for(int i = 0; i < m; i++) {
seqs[i] = in.readLine().split(" ");
seqsHashes[i] = new long[seqs[i].length];
for(int j = 0; j < seqs[i].length; j++) {
seqsHashes[i][j] = calcHash(seqs[i][j]);
}
}
rec(0, tokens.length - 1, true, 0);
for(int i = 0; i < m; i++) {
out.println(ans[i]);
}
}
public static void main(String[] args) {
new Thread(null, new Codeforces(), "yarrr", 1 << 26).start();
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
rnd = new Random();
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(42);
}
}
String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | cce676e1acd7c365e601cf91a9c31c70 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.*;
import java.util.*;
public class E {
private static void solve() throws IOException {
String document = br.readLine();
List<Tag> tags = getTags(document);
int queries = Integer.parseInt(br.readLine());
while (queries-- > 0) {
List<String> query = new ArrayList<String>();
StringTokenizer tok = new StringTokenizer(br.readLine());
while (tok.hasMoreTokens()) {
query.add(tok.nextToken());
}
int answer = get(tags, query.toArray(new String[query.size()]));
out.println(answer);
}
}
private static int get(List<Tag> tags, String[] query) {
int curHave = 0;
int answer = 0;
int curDepth = 0;
List<Integer> depthsStack = new ArrayList<Integer>();
for (Tag tag : tags) {
if (tag.name.equals(query[curHave])) {
if (curHave == query.length - 1) {
if (tag.type >= 0) {
++answer;
}
} else {
if (tag.type > 0) {
depthsStack.add(curDepth);
++curHave;
}
}
}
if (tag.type < 0 && !depthsStack.isEmpty()
&& depthsStack.get(depthsStack.size() - 1).intValue() == curDepth - 1) {
depthsStack.remove(depthsStack.size() - 1);
--curHave;
}
if (tag.type > 0) {
++curDepth;
}
if (tag.type < 0) {
--curDepth;
}
}
return answer;
}
static List<Tag> getTags(String document) {
List<Tag> list = new ArrayList<Tag>();
while (!document.isEmpty()) {
if (!document.startsWith("<")) {
throw new AssertionError();
}
int close = document.indexOf('>');
if (close < 0) {
throw new AssertionError();
}
String s = document.substring(1, close);
int type = 1;
if (s.startsWith("/")) {
type = -1;
s = s.substring(1);
} else {
if (s.endsWith("/")) {
type = 0;
s = s.substring(0, s.length() - 1);
}
}
list.add(new Tag(s, type));
document = document.substring(close + 1);
}
return list;
}
static class Tag {
String name;
int type;
private Tag(String name, int type) {
this.name = name;
this.type = type;
}
}
public static void main(String[] args) {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
} catch (Throwable e) {
e.printStackTrace();
System.exit(239);
}
}
static BufferedReader br;
static StringTokenizer st;
static PrintWriter out;
static String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = br.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
static double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
} | Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | 6371b5df3addf2937d60d41760f0d6cd | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static StringTokenizer tok = null;
public static BufferedReader cin;
public static String nextToken() throws Exception {
if (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(cin.readLine());
}
return tok.nextToken();
}
public static int nextInt() throws Exception {
return Integer.parseInt(nextToken());
}
public static double nextDouble() throws Exception {
return Double.parseDouble(nextToken());
}
public static void main(String[] args) throws Exception {
cin = new BufferedReader(new InputStreamReader(System.in));
tok = new StringTokenizer(cin.readLine(), "<>");
ArrayList<Integer> s = new ArrayList<Integer>();
while (tok.hasMoreTokens()) {
String tag = tok.nextToken();
if (tag.endsWith("/")) {
int code = Math.abs(tag.substring(0, tag.length() - 1).hashCode());
s.add(code);
s.add(-code);
} else
if (tag.startsWith("/")) {
int code = Math.abs(tag.substring(1).hashCode());
s.add(-code);
} else {
int code = Math.abs(tag.hashCode());
s.add(code);
}
}
int n = Integer.parseInt(cin.readLine());
for (int i = 0; i < n; i++) {
tok = new StringTokenizer(cin.readLine());
ArrayList<Integer> path = new ArrayList<Integer>();
while (tok.hasMoreTokens()) {
path.add(Math.abs(tok.nextToken().hashCode()));
}
int m = path.size();
int[] min_depth = new int[m];
int depth = 0;
int len = 0;
int ans = 0;
for (int j = 0; j < s.size(); j++) {
int word = s.get(j);
if (word == path.get(len)) {
if (len == m - 1) {
ans++;
} else {
min_depth[len] = depth + 1;
len++;
}
}
if (word > 0) {
depth++;
} else {
if (len > 0 && min_depth[len - 1] >= depth) {
len--;
}
depth--;
}
}
System.out.println(ans);
}
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | ee5c5c3d8a34d1f4f10222370be8374b | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Vector;
public class Solution {
static class Node {
int id, maxSucc, minUnsucc, d;
Node par;
Vector<Node> ch;
public Node(int I, int D) {
id = I;
d = D;
par = null;
ch = new Vector<Solution.Node>();
maxSucc = -1;
minUnsucc = Integer.MAX_VALUE;
}
public boolean isSeq(int p) {
if (maxSucc >= p)
return true;
if (minUnsucc <= p)
return false;
boolean ans = true;
if (id != req[p]) {
if (par == null)
ans = false;
else
ans = par.isSeq(p);
} else {
if (p == 0)
ans = true;
else {
if (par == null)
ans = false;
else
ans = par.isSeq(p - 1);
}
}
if (ans)
maxSucc = Math.max(maxSucc, p);
else
minUnsucc = Math.min(minUnsucc, p);
return ans;
}
}
static HashMap<String, Integer> ids = new HashMap<String, Integer>();
static HashMap<Integer, Vector<Node>> nodes = new HashMap<Integer, Vector<Node>>();
static int[] req = new int[205];
public static void main(String[] args) throws Exception {
new Thread(null, new Runnable() {
@Override
public void run() {
try {
Solution.run();
} catch (Exception e) {
}
}
}, "1", 1 << 25).start();
}
private static void run() throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// BufferedReader in = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(System.out);
long t1 = System.currentTimeMillis();
String[] s = in.readLine().split(">");
Node curr = new Node(-1, 0);
int newID = 0;
for (int i = 0; i < s.length; i++) {
String cont = s[i].substring(1);
if (cont.charAt(0) == '/')
curr = curr.par;
else if (cont.charAt(cont.length() - 1) == '/') {
String name = cont.substring(0, cont.length() - 1);
int id = -1;
if (ids.containsKey(name))
id = ids.get(name);
else {
id = newID++;
ids.put(name, id);
}
Node nd = new Node(id, curr.d + 1);
nd.par = curr;
curr.ch.add(nd);
if (nodes.containsKey(id))
nodes.get(id).add(nd);
else {
Vector<Node> v = new Vector<Node>();
v.add(nd);
nodes.put(id, v);
}
} else {
int id = -1;
if (ids.containsKey(cont))
id = ids.get(cont);
else {
id = newID++;
ids.put(cont, id);
}
Node nd = new Node(id, curr.d + 1);
nd.par = curr;
curr.ch.add(nd);
curr = nd;
if (nodes.containsKey(id))
nodes.get(id).add(nd);
else {
Vector<Node> v = new Vector<Node>();
v.add(nd);
nodes.put(id, v);
}
}
}
int m = Integer.parseInt(in.readLine());
for (int i = 0; i < m; i++) {
for (Integer id : nodes.keySet()) {
Vector<Node> v = nodes.get(id);
for (Node nd : v) {
nd.maxSucc = -1;
nd.minUnsucc = nd.d;
}
}
String[] r = in.readLine().split(" ");
boolean noMatches = false;
for (int j = 0; j < r.length; j++) {
Integer id = ids.get(r[j]);
if (id == null) {
noMatches = true;
break;
} else
req[j] = id;
}
if (noMatches)
out.println(0);
else {
Vector<Node> v = nodes.get(req[r.length - 1]);
int ans = 0;
for (int j = 0; j < v.size(); j++)
if (v.get(j).isSeq(r.length - 1))
ans++;
out.println(ans);
}
}
out.close();
System.err.println(System.currentTimeMillis() - t1);
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | 41a44d50ca67fc0a3f99456d672968f5 | train_002.jsonl | 1333440000 | This problem is about imaginary languages BHTML and BCSS, which slightly resemble HTML and CSS. Read the problem statement carefully as the resemblance is rather slight and the problem uses very simplified analogs.You are given a BHTML document that resembles HTML but is much simpler. It is recorded as a sequence of opening and closing tags. A tag that looks like "<tagname>" is called an opening tag and a tag that looks like "</tagname>" is called a closing tag. Besides, there are self-closing tags that are written as "<tagname/>" and in this problem they are fully equivalent to "<tagname></tagname>". All tagnames in this problem are strings consisting of lowercase Latin letters with length from 1 to 10 characters. Tagnames of different tags may coincide.The document tags form a correct bracket sequence, that is, we can obtain an empty sequence from the given one using the following operations: remove any self-closing tag "<tagname/>", remove a pair of an opening and a closing tag that go consecutively (in this order) and have the same names. In other words, remove substring "<tagname></tagname>". For example, you may be given such document: "<header><p><a/><b></b></p></header><footer></footer>" but you may not be given documents "<a>", "<a></b>", "</a><a>" or "<a><b></a></b>".Obviously, for any opening tag there is the only matching closing one — each such pair is called an element. A self-closing tag also is an element. Let's consider that one element is nested inside another one, if tags of the first element are between tags of the second one. An element is not nested to itself. For instance, in the example above element "b" is nested in "header" and in "p", but it isn't nested in "a" and "footer", also it isn't nested to itself ("b"). Element "header" has three elements nested in it, and "footer" has zero.We need the BCSS rules to apply styles when displaying elements of the BHTML documents. Each rule is recorded as a subsequence of words "x1 x2 ... xn". This rule has effect over all such elements t, which satisfy both conditions from the list: there is a sequence of nested elements with tagnames "x1", "x2", ..., "xn" (that is, the second element is nested in the first one, the third element is nested in the second one and so on), this sequence ends with element t (i.e. tagname of element t equals "xn"). For example, element "b" meets the conditions of the rule "a b" if for element "b" exists element "a" in which it is nested. Element "c" meets the conditions of the rule "a b b c", if three elements exist: "a", "b", "b", and in the chain "a"-"b"-"b"-"c" each following element is nested in the previous one.Given a BHTML document and a set of BCSS rules, write a program that determines the number of elements that meet the conditions of each rule. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
}
class TaskE {
static final int MAX_ELEMENTS = 300000;
public void solve(int testNumber, InputReader in, PrintWriter out) {
int[] stack = new int[MAX_ELEMENTS];
stack[0] = 0;
int sp = 1;
int n = 1;
String[] elements = new String[MAX_ELEMENTS];
elements[0] = "$";
int[] parent = new int[MAX_ELEMENTS];
String line = in.nextLine();
for (int i = 0; i < line.length(); ++i) {
if (line.charAt(i) == '<') {
if (line.charAt(i + 1) == '/') {
if (sp < 1) throw new RuntimeException();
--sp;
} else {
int j = i + 1;
while (line.charAt(j) >= 'a' && line.charAt(j) <= 'z') ++j;
elements[n] = line.substring(i + 1, j);
parent[n] = stack[sp - 1];
if (line.charAt(j) != '/') {
stack[sp++] = n;
}
++n;
}
}
}
if (sp != 1) throw new RuntimeException();
int numQueries = in.nextInt();
int[] answer = new int[MAX_ELEMENTS];
for (int i = 0; i < numQueries; ++i) {
String req = in.nextLine();
String[] parts = req.split(" ", -1);
int size = parts.length;
answer[0] = 0;
int res = 0;
for (int j = 1; j < n; ++j) {
int pans = answer[parent[j]];
if (parts[pans].equals(elements[j])) {
if (pans == size - 1)
++res;
else
++pans;
}
answer[j] = pans;
}
out.println(res);
}
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
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 String nextLine() {
if (tokenizer != null && tokenizer.hasMoreTokens()) {
throw new RuntimeException();
}
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
| Java | ["<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>\n4\na\na b b\na b\nb a", "<b><aa/></b><aa><b/><b/></aa>\n5\naa b\nb\naa\nb aa\na"] | 4 seconds | ["2\n1\n4\n0", "2\n3\n2\n1\n0"] | null | Java 6 | standard input | [
"*special",
"dfs and similar",
"expression parsing"
] | f8ae8984f1f497d9d15887c5a0429062 | The first line of the input contains a BHTML-document. The document has length from 4 to 106 characters. The document has a correct structure, doesn't contain spaces or any other unnecessary characters. Tagnames consist of lowercase Latin letters, their lengths are from 1 to 10 characters. The second line contains an integer m (1 ≤ m ≤ 200) — the number of queries. Then m lines contain the queries, one per line. Each query is a sequence x1, x2, ..., xn, where xi is the i-th element of the query, and n (1 ≤ n ≤ 200) is the number of elements in the query. The elements are separated by single spaces. Each query doesn't begin with and doesn't end with a space. Each query element is a sequence of lowercase Latin letters with length from 1 to 10. | 2,200 | Print m lines, the j-th line should contain the number of elements of the document that correspond to the j-th BCSS-rule. If there are no such elements at all, print on the line 0. | standard output | |
PASSED | bb728a794fd4ae486e6540b3933163e4 | train_002.jsonl | 1584974100 | The King of Berland Polycarp LXXXIV has $$$n$$$ daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are $$$n$$$ other kingdoms as well.So Polycarp LXXXIV has enumerated his daughters from $$$1$$$ to $$$n$$$ and the kingdoms from $$$1$$$ to $$$n$$$. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry.Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another.For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the $$$n$$$-th daughter.For example, let there be $$$4$$$ daughters and kingdoms, the lists daughters have are $$$[2, 3]$$$, $$$[1, 2]$$$, $$$[3, 4]$$$, $$$[3]$$$, respectively. In that case daughter $$$1$$$ marries the prince of kingdom $$$2$$$, daughter $$$2$$$ marries the prince of kingdom $$$1$$$, daughter $$$3$$$ marries the prince of kingdom $$$3$$$, leaving daughter $$$4$$$ nobody to marry to.Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list.Polycarp LXXXIV wants to increase the number of married couples.Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it.If there are multiple ways to add an entry so that the total number of married couples increases then print any of them.For your and our convenience you are asked to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner ab=new Scanner(System.in);
int q=ab.nextInt();
while(q-->0)
{
int x=ab.nextInt();
int min=(int)1e6;int ind=-1;
LinkedHashSet<Integer>set=new LinkedHashSet<>();
LinkedList<Integer>li=new LinkedList<>();
LinkedHashSet<Integer>set2=new LinkedHashSet<>();
for(int y=0;y<x;y++)
{
int z=ab.nextInt();
int arr[]=new int[z];boolean fl=true;;
for(int i=0;i<z;i++)
{
arr[i]=ab.nextInt();
}
Arrays.sort(arr);
for(int a=0;a<z;a++)
{
if(set.contains(arr[a]))continue;
else if(fl&&!(set.contains(arr[a]))){set.add(arr[a]);li.addLast(arr[a]);set2.add(y);break;}
}
if(!(set2.contains(y)))ind=y;
}
if(set.size()==x)System.out.println("OPTIMAL");
else
{
int i=0;
for(int j=1;j<=x;j++){if(!(set.contains(j))){i=j;break;}}
System.out.println("IMPROVE");
System.out.println(ind+1+" "+i);
}
}
}
} | Java | ["5\n4\n2 2 3\n2 1 2\n2 3 4\n1 3\n2\n0\n0\n3\n3 1 2 3\n3 1 2 3\n3 1 2 3\n1\n1 1\n4\n1 1\n1 2\n1 3\n1 4"] | 2 seconds | ["IMPROVE\n4 4\nIMPROVE\n1 1\nOPTIMAL\nOPTIMAL\nOPTIMAL"] | NoteThe first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom.In the second test case any new entry will increase the number of marriages from $$$0$$$ to $$$1$$$.In the third and the fourth test cases there is no way to add an entry.In the fifth test case there is no way to change the marriages by adding any entry. | Java 8 | standard input | [
"greedy",
"graphs",
"brute force"
] | 38911652b3c075354aa8adb2a4c6e362 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of daughters and the number of kingdoms. Each of the next $$$n$$$ lines contains the description of each daughter's list. The first integer $$$k$$$ ($$$0 \le k \le n$$$) is the number of entries in the $$$i$$$-th daughter's list. After that $$$k$$$ distinct integers follow $$$g_i[1], g_i[2], \dots, g_i[k]$$$ ($$$1 \le g_i[j] \le n$$$) — the indices of the kingdoms in the list in the increasing order ($$$g_i[1] < g_i[2] < \dots < g_i[k]$$$). It's guaranteed that the total number of daughters over all test cases does not exceed $$$10^5$$$. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed $$$10^5$$$. | 1,200 | For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers — the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". | standard output | |
PASSED | 116f66e3a7bd47290ec8d6a01f74b3c7 | train_002.jsonl | 1584974100 | The King of Berland Polycarp LXXXIV has $$$n$$$ daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are $$$n$$$ other kingdoms as well.So Polycarp LXXXIV has enumerated his daughters from $$$1$$$ to $$$n$$$ and the kingdoms from $$$1$$$ to $$$n$$$. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry.Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another.For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the $$$n$$$-th daughter.For example, let there be $$$4$$$ daughters and kingdoms, the lists daughters have are $$$[2, 3]$$$, $$$[1, 2]$$$, $$$[3, 4]$$$, $$$[3]$$$, respectively. In that case daughter $$$1$$$ marries the prince of kingdom $$$2$$$, daughter $$$2$$$ marries the prince of kingdom $$$1$$$, daughter $$$3$$$ marries the prince of kingdom $$$3$$$, leaving daughter $$$4$$$ nobody to marry to.Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list.Polycarp LXXXIV wants to increase the number of married couples.Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it.If there are multiple ways to add an entry so that the total number of married couples increases then print any of them.For your and our convenience you are asked to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.PrintWriter;
import java.util.Scanner;
public class PrincessPrinc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// String in = sc.nextLine();
PrintWriter out = new PrintWriter(System.out);
// StringTokenizer st = new StringTokenizer(in);
// int T = Integer.parseInt(st.nextToken());
int T = sc.nextInt();
for (int index = 0; index < T; index++) {
// in = sc.nextLine();
// StringTokenizer ab = new StringTokenizer(in);
// int N = Integer.parseInt(ab.nextToken());
int N = sc.nextInt();
int[] taken = new int[N];
int princess = -1;
for (int count = 0; count < N; count++) {
// in = sc.nextLine();
// StringTokenizer cd = new StringTokenizer(in);
// int k = Integer.parseInt(cd.nextToken());
int k = sc.nextInt();
if (k == 0) {
princess = count + 1;
}
boolean check = false;
for (int i = 0; i < k; i++) {
// int a = Integer.parseInt(cd.nextToken());
int a = sc.nextInt();
a--;
if (taken[a] == 0) {
taken[a] = 1;
check = true;
sc.nextLine();
break;
}
/*
* else if (taken[a] != 0 && i == k - 1) { princess = count + 1; }
*/
}
if (check != true) {
princess = count + 1;
}
// System.out.println(Arrays.toString(taken));
}
if (princess == -1) {
out.println("OPTIMAL");
} else {
int prince = -1;
for (int count = 0; count < taken.length; count++) {
if (taken[count] == 0) {
prince = count + 1;
break;
}
}
out.println("IMPROVE");
out.println(princess + " " + prince);
}
}
out.close();
}
}
| Java | ["5\n4\n2 2 3\n2 1 2\n2 3 4\n1 3\n2\n0\n0\n3\n3 1 2 3\n3 1 2 3\n3 1 2 3\n1\n1 1\n4\n1 1\n1 2\n1 3\n1 4"] | 2 seconds | ["IMPROVE\n4 4\nIMPROVE\n1 1\nOPTIMAL\nOPTIMAL\nOPTIMAL"] | NoteThe first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom.In the second test case any new entry will increase the number of marriages from $$$0$$$ to $$$1$$$.In the third and the fourth test cases there is no way to add an entry.In the fifth test case there is no way to change the marriages by adding any entry. | Java 8 | standard input | [
"greedy",
"graphs",
"brute force"
] | 38911652b3c075354aa8adb2a4c6e362 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of daughters and the number of kingdoms. Each of the next $$$n$$$ lines contains the description of each daughter's list. The first integer $$$k$$$ ($$$0 \le k \le n$$$) is the number of entries in the $$$i$$$-th daughter's list. After that $$$k$$$ distinct integers follow $$$g_i[1], g_i[2], \dots, g_i[k]$$$ ($$$1 \le g_i[j] \le n$$$) — the indices of the kingdoms in the list in the increasing order ($$$g_i[1] < g_i[2] < \dots < g_i[k]$$$). It's guaranteed that the total number of daughters over all test cases does not exceed $$$10^5$$$. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed $$$10^5$$$. | 1,200 | For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers — the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". | standard output | |
PASSED | 2ab2aa5f098e06bc59c49f50eaf7a354 | train_002.jsonl | 1584974100 | The King of Berland Polycarp LXXXIV has $$$n$$$ daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are $$$n$$$ other kingdoms as well.So Polycarp LXXXIV has enumerated his daughters from $$$1$$$ to $$$n$$$ and the kingdoms from $$$1$$$ to $$$n$$$. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry.Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another.For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the $$$n$$$-th daughter.For example, let there be $$$4$$$ daughters and kingdoms, the lists daughters have are $$$[2, 3]$$$, $$$[1, 2]$$$, $$$[3, 4]$$$, $$$[3]$$$, respectively. In that case daughter $$$1$$$ marries the prince of kingdom $$$2$$$, daughter $$$2$$$ marries the prince of kingdom $$$1$$$, daughter $$$3$$$ marries the prince of kingdom $$$3$$$, leaving daughter $$$4$$$ nobody to marry to.Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list.Polycarp LXXXIV wants to increase the number of married couples.Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it.If there are multiple ways to add an entry so that the total number of married couples increases then print any of them.For your and our convenience you are asked to answer $$$t$$$ independent test cases. | 256 megabytes | import java.io.*;
import java.util.*;
public class Q2 {
public static void main(String[] args) {
InputReader in=new InputReader();
PrintWriter out=new PrintWriter(System.out);
int t =in.nextInt();
while(t-->0){
int N =in.nextInt();
long ans =0; int c[]=new int[N+1];
int count=0,index=-1;
for(int i =0;i<N;i++){
int M=in.nextInt(),flag=0;
int arr[]=new int[M];
for(int j=0;j<M;j++)
arr[j]=in.nextInt();
in.shuffle(arr);
Arrays.sort(arr);
for(int j=0;j<M;j++){
int a =arr[j];
if(flag==1)
continue;
if(c[a]==0){
c[a]=1;
flag=1; count++;
}
}
if(flag!=1 && index==-1){
index=i+1;
}
}
if(count==N){
out.println("OPTIMAL");
}else{
for(int k=0;k<N;k++) {
if (c[k + 1] == 0) {
ans = k + 1;
break;
}
}
out.println("IMPROVE");
out.println(index+" "+ans);
}
}
out.close();
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public int[] shuffle(int[] arr) {
Random r = new Random();
for (int i = 1, j; i < arr.length; i++) {
j = r.nextInt(i);
arr[i] = arr[i] ^ arr[j];
arr[j] = arr[i] ^ arr[j];
arr[i] = arr[i] ^ arr[j];
}
return arr;
}
public InputReader() {
reader = new BufferedReader(new InputStreamReader(System.in), 32768);
tokenizer = null;
}
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(System.in), 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 char nextChar() {
return next().charAt(0);
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
| Java | ["5\n4\n2 2 3\n2 1 2\n2 3 4\n1 3\n2\n0\n0\n3\n3 1 2 3\n3 1 2 3\n3 1 2 3\n1\n1 1\n4\n1 1\n1 2\n1 3\n1 4"] | 2 seconds | ["IMPROVE\n4 4\nIMPROVE\n1 1\nOPTIMAL\nOPTIMAL\nOPTIMAL"] | NoteThe first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom.In the second test case any new entry will increase the number of marriages from $$$0$$$ to $$$1$$$.In the third and the fourth test cases there is no way to add an entry.In the fifth test case there is no way to change the marriages by adding any entry. | Java 8 | standard input | [
"greedy",
"graphs",
"brute force"
] | 38911652b3c075354aa8adb2a4c6e362 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of daughters and the number of kingdoms. Each of the next $$$n$$$ lines contains the description of each daughter's list. The first integer $$$k$$$ ($$$0 \le k \le n$$$) is the number of entries in the $$$i$$$-th daughter's list. After that $$$k$$$ distinct integers follow $$$g_i[1], g_i[2], \dots, g_i[k]$$$ ($$$1 \le g_i[j] \le n$$$) — the indices of the kingdoms in the list in the increasing order ($$$g_i[1] < g_i[2] < \dots < g_i[k]$$$). It's guaranteed that the total number of daughters over all test cases does not exceed $$$10^5$$$. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed $$$10^5$$$. | 1,200 | For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers — the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". | standard output | |
PASSED | 478635bfd68553544cc1627da0502e94 | train_002.jsonl | 1584974100 | The King of Berland Polycarp LXXXIV has $$$n$$$ daughters. To establish his power to the neighbouring kingdoms he wants to marry his daughters to the princes of these kingdoms. As a lucky coincidence there are $$$n$$$ other kingdoms as well.So Polycarp LXXXIV has enumerated his daughters from $$$1$$$ to $$$n$$$ and the kingdoms from $$$1$$$ to $$$n$$$. For each daughter he has compiled a list of kingdoms princes of which she wanted to marry.Polycarp LXXXIV is very busy, so he finds a couple for his daughters greedily one after another.For the first daughter he takes the kingdom with the lowest number from her list and marries the daughter to their prince. For the second daughter he takes the kingdom with the lowest number from her list, prince of which hasn't been taken already. If there are no free princes in the list then the daughter marries nobody and Polycarp LXXXIV proceeds to the next daughter. The process ends after the $$$n$$$-th daughter.For example, let there be $$$4$$$ daughters and kingdoms, the lists daughters have are $$$[2, 3]$$$, $$$[1, 2]$$$, $$$[3, 4]$$$, $$$[3]$$$, respectively. In that case daughter $$$1$$$ marries the prince of kingdom $$$2$$$, daughter $$$2$$$ marries the prince of kingdom $$$1$$$, daughter $$$3$$$ marries the prince of kingdom $$$3$$$, leaving daughter $$$4$$$ nobody to marry to.Actually, before starting the marriage process Polycarp LXXXIV has the time to convince one of his daughters that some prince is also worth marrying to. Effectively, that means that he can add exactly one kingdom to exactly one of his daughter's list. Note that this kingdom should not be present in the daughter's list.Polycarp LXXXIV wants to increase the number of married couples.Unfortunately, what he doesn't have the time for is determining what entry to add. If there is no way to increase the total number of married couples then output that the marriages are already optimal. Otherwise, find such an entry that the total number of married couples increases if Polycarp LXXXIV adds it.If there are multiple ways to add an entry so that the total number of married couples increases then print any of them.For your and our convenience you are asked to answer $$$t$$$ independent test cases. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.text.*;
public class Prac{
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
public InputReader(InputStream st) {
this.stream = st;
}
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
public String rs() {
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 String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
public static class Key {
private final int x;
private final int y;
public Key(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Key)) return false;
Key key = (Key) o;
return x == key.x && y == key.y;
}
@Override
public int hashCode() {
int result = x;
result = 31 * result + y;
return result;
}
}
static PrintWriter w = new PrintWriter(System.out);
static long mod=998244353L,mod1=1000000007;
public static void main(String [] args){
InputReader sc=new InputReader(System.in);
int t=sc.ni();
while(t-->0){
int n=sc.ni();
TreeSet<Integer> s=new TreeSet<>();
int k=0;
for(int i=1;i<=n;i++){
s.add(i);
}
int ans[][]=new int[n][2];
int a1=0,a2=0;
boolean f=false;
for(int i=1;i<=n;i++){
int x=sc.ni();
int min=1000000;
for(int j=0;j<x;j++){
int a=sc.ni();
if(s.contains(a)&&a<min){
min=a;
}
}
if(min==1000000&&!f){
f=true;
a1=i;
}
else{
s.remove(min);
}
}
if(f){
w.println("IMPROVE");
w.println(a1+" "+s.first());
}
else w.println("OPTIMAL");
}
w.close();
}
} | Java | ["5\n4\n2 2 3\n2 1 2\n2 3 4\n1 3\n2\n0\n0\n3\n3 1 2 3\n3 1 2 3\n3 1 2 3\n1\n1 1\n4\n1 1\n1 2\n1 3\n1 4"] | 2 seconds | ["IMPROVE\n4 4\nIMPROVE\n1 1\nOPTIMAL\nOPTIMAL\nOPTIMAL"] | NoteThe first test case is depicted in the statement. Adding the fourth kingdom to the list of the fourth daughter makes her marry the prince of the fourth kingdom.In the second test case any new entry will increase the number of marriages from $$$0$$$ to $$$1$$$.In the third and the fourth test cases there is no way to add an entry.In the fifth test case there is no way to change the marriages by adding any entry. | Java 8 | standard input | [
"greedy",
"graphs",
"brute force"
] | 38911652b3c075354aa8adb2a4c6e362 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of daughters and the number of kingdoms. Each of the next $$$n$$$ lines contains the description of each daughter's list. The first integer $$$k$$$ ($$$0 \le k \le n$$$) is the number of entries in the $$$i$$$-th daughter's list. After that $$$k$$$ distinct integers follow $$$g_i[1], g_i[2], \dots, g_i[k]$$$ ($$$1 \le g_i[j] \le n$$$) — the indices of the kingdoms in the list in the increasing order ($$$g_i[1] < g_i[2] < \dots < g_i[k]$$$). It's guaranteed that the total number of daughters over all test cases does not exceed $$$10^5$$$. It's also guaranteed that the total number of kingdoms in lists over all test cases does not exceed $$$10^5$$$. | 1,200 | For each test case print the answer to it. Print "IMPROVE" in the first line if Polycarp LXXXIV can add some kingdom to some of his daughter's list so that the total number of married couples increases. The second line then should contain two integers — the index of the daughter and the index of the kingdom Polycarp LXXXIV should add to that daughter's list. If there are multiple ways to add an entry so that the total number of married couples increases then print any of them. Otherwise the only line should contain one word "OPTIMAL". | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.