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 | 8cc7888aa687bfc330a5fc25bd81867f | train_003.jsonl | 1402241400 | Valera loves his garden, where n fruit trees grow.This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day aiβ+β1 (all fruits that are not collected in these two days, become unfit to eat).Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? | 256 megabytes |
import java.util.Scanner;
public class TestB {
public static void main (String args[]) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int v=sc.nextInt();
int[] derevja = new int[3010];
int sum_fruktov=0;
for (int i=0; i<n; i++){
int k=sc.nextInt();
int p=sc.nextInt();
derevja[k]+=p;
}
int novye =0;
for (int i=1; i<3010; i++){
/*System.out.println("Derevja["+i+"]="+derevja[i]);
System.out.println("Derevja["+i+1+"]="+derevja[i+1]);
System.out.println("Novye="+novye);*/
if (derevja[i]+novye<=v){
sum_fruktov+=derevja[i]+novye;
novye=0;
}
else {
sum_fruktov+=v;
if (novye>=v) {
novye=derevja[i];
}else {
novye=derevja[i]-v+novye;
}
}
}
System.out.println(sum_fruktov);
}
} | Java | ["2 3\n1 5\n2 3", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20"] | 1 second | ["8", "60"] | NoteIn the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. | Java 7 | standard input | [
"implementation",
"greedy"
] | 848ead2b878f9fd8547e1d442e2f85ff | The first line contains two space-separated integers n and v (1ββ€βn,βvββ€β3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1ββ€βai,βbiββ€β3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree. | 1,400 | Print a single integer β the maximum number of fruit that Valera can collect. | standard output | |
PASSED | 15115fbd0e5c27d2bcd95f5b92ec522d | train_003.jsonl | 1402241400 | Valera loves his garden, where n fruit trees grow.This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day aiβ+β1 (all fruits that are not collected in these two days, become unfit to eat).Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? | 256 megabytes | import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main
{
private final int SIZEN = 30001;
public void foo()
{
MyScanner scan = new MyScanner();
int n = scan.nextInt();
int v = scan.nextInt();
int[][] dp = new int[SIZEN + 2][2];
for(int i = 0;i < n;++i)
{
int a = scan.nextInt();
int b = scan.nextInt();
dp[a][0] += b;
}
int sum = 0;
for(int i = 1;i <= SIZEN;++i)
{
if(dp[i][1] >= v)
{
sum += v;
dp[i + 1][1] += dp[i][0];
}
else if(dp[i][0] + dp[i][1] >= v)
{
sum += v;
dp[i + 1][1] += dp[i][0] - (v - dp[i][1]);
}
else
{
sum += dp[i][0] + dp[i][1];
}
}
System.out.println(sum);
}
public static void main(String[] args)
{
new Main().foo();
}
class MyScanner
{
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
BufferedInputStream bis = new BufferedInputStream(System.in);
public int read()
{
if (-1 == numChars)
{
throw new InputMismatchException();
}
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = bis.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if (numChars <= 0)
{
return -1;
}
}
return buf[curChar++];
}
public int nextInt()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if (c < '0' || c > '9')
{
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
{
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public String next()
{
int c = read();
while (isSpaceChar(c))
{
c = read();
}
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
private boolean isSpaceChar(int c)
{
return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
}
}
} | Java | ["2 3\n1 5\n2 3", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20"] | 1 second | ["8", "60"] | NoteIn the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. | Java 7 | standard input | [
"implementation",
"greedy"
] | 848ead2b878f9fd8547e1d442e2f85ff | The first line contains two space-separated integers n and v (1ββ€βn,βvββ€β3000) β the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers ai and bi (1ββ€βai,βbiββ€β3000) β the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree. | 1,400 | Print a single integer β the maximum number of fruit that Valera can collect. | standard output | |
PASSED | fe5b69b811e7f4385d56a004d1bbc082 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.Scanner;
public class B60 {
static int[] dx = {0, 0, 0, 0, 1, -1};
static int[] dy = {1, -1, 0, 0, 0, 0};
static int[] dz = {0, 0, 1, -1, 0, 0};
static boolean[][][] vis;//z x y
static int k;
static int n;
static int m;
static int counter = 0;
public static void dfs(int z, int x, int y) {
vis[z][x][y] = true;
counter++;
for (int t = 0; t < dx.length; t++) {
if (z + dz[t] >= 0 && z + dz[t] < k &&
x + dx[t] >= 0 && x + dx[t] < n &&
y + dy[t] >= 0 && y + dy[t] < m
&& !vis[z + dz[t]][x + dx[t]][y + dy[t]]) {
dfs(z + dz[t], x + dx[t], y + dy[t]);
}
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
k = in.nextInt();
n = in.nextInt();
m = in.nextInt();
vis = new boolean[k][n][m]; //z x y
for (int z = 0; z < k; z++) {
for (int x = 0; x < n; x++) {
String curret = in.next();
for (int y = 0; y < m; y++) {
vis[z][x][y] = curret.charAt(y) == '#';
}
}
}
dfs(0, in.nextInt() - 1, in.nextInt() - 1);
System.out.println(counter);
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | af78484560cb0d5352c08c0acafeb464 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class B_SerialTime {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int k = s.nextInt(), n = s.nextInt(), m = s.nextInt();
boolean b[][][] = new boolean[k][n][m];
for (int t = 0; t < k; ++t) {
for (int i = 0; i < n; ++i) {
char[] cs = s.next().toCharArray();
for (int j = 0; j < m; ++j) {
b[t][i][j] = cs[j] == '.';
}
}
}
int[] dz = { -1, 1, 0, 0, 0, 0 };
int[] dx = { 0, 0, -1, 1, 0, 0 };
int[] dy = { 0, 0, 0, 0, -1, 1 };
Deque<int[]> q = new ArrayDeque<int[]>();
q.add(new int[] { 0, s.nextInt()-1, s.nextInt()-1 });
int c = 0;
while (!q.isEmpty()) {
int[] p = q.poll();
int z = p[0], x = p[1], y = p[2];
if (0<=z&&z<k&&0<=x&&x<n&&0<=y&&y<m&&b[z][x][y]) {
b[z][x][y]=false;
++c;
for(int i = 0; i < 6; ++i){
q.add(new int[]{z+dz[i],x+dx[i],y+dy[i]});
}
}
}
System.out.println(c);
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | d9a341dab2e2c352e0023b7350805688 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class Serial {
static int[] dx = {1, 0, 0, -1, 0, 0};
static int[] dy = {0, -1, 1, 0, 0, 0};
static int[] dz = {0, 0, 0, 0, 1, -1};
static int k, n, m, x, y;
public static void main (String args[]) {
Scanner sc = new Scanner(System.in);
k = sc.nextInt();
n = sc.nextInt();
m = sc.nextInt();
sc.nextLine();
char[][][] dish = new char[k][n][m];
for (int i = 0; i < k; i++) {
sc.nextLine();
for (int j = 0; j < n; j++) {
String line = sc.nextLine();
for (int k = 0; k < m; k++) {
dish[i][j][k] = line.charAt(k);
}
}
}
sc.nextLine();
x = sc.nextInt();
y = sc.nextInt();
System.out.print(fill(dish, x-1, y-1));
}
public static int fill(char[][][] dish, int x, int y) {
Queue<Point3D> q = new LinkedList<>();
int count = 1;
q.add(new Point3D(0, x, y));
dish[0][x][y] = '#';
while(!q.isEmpty()) {
Point3D current = q.remove();
for (int i = 0; i < 6; i++) {
int adjX = current.x + dx[i];
int adjY = current.y + dy[i];
int adjZ = current.z + dz[i];
if (inBounds(adjX, adjY, adjZ) && dish[adjX][adjY][adjZ] == '.') {
q.add(new Point3D(adjX, adjY, adjZ));
count++;
dish[adjX][adjY][adjZ] = '#';
}
}
}
return count;
}
public static boolean inBounds(int x, int y, int z) {
return (x >= 0 && x < k && y >= 0 && y < n && z >= 0 && z < m);
}
}
class Point3D {
int x, y, z;
Point3D(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 0b42e6b3959eb742a8d1ea94ceaab14c | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.Scanner;
public class SerialTime {
public static void main(String args[]) {
// Create a scanner that is to read from System.in
Scanner scan = new Scanner(System.in);
int layers = scan.nextInt();
int rows = scan.nextInt();
int cols = scan.nextInt();
scan.nextLine();
char[][][]plates = new char[layers][rows][cols];
for (int i = 0; i < layers; i++) {
scan.nextLine();
for (int j = 0; j < rows; j++) {
String line = scan.nextLine();
for (int k = 0; k < cols; k++) {
plates[i][j][k] = line.charAt(k);
}
}
}
int[] count = {0};
scan.nextLine();
int start = scan.nextInt();
int end = scan.nextInt();
dfs(plates, 0, start - 1, end -1, count);
System.out.println(count[0]);
}
public static void dfs(char[][][]plates, int plate, int r, int c, int[] count) {
if (isOutOfBounds(plates, plate, r, c) || plates[plate][r][c] != '.') {
return;
} else {
count[0]++;
plates[plate][r][c] = 'V';
int[] dr4 = {0, 1, 0, -1};
int[] dc4 = {1, 0, -1, 0};
dfs(plates, plate + 1, r, c, count); // below
for (int d = 0; d < 4; d++) {
dfs(plates, plate, r + dr4[d], c + dc4[d], count);
}
dfs(plates, plate - 1, r, c, count); // top
}
}
public static boolean isOutOfBounds(char[][][] plates, int plate, int r, int c) {
return (plate < 0 || plate >= plates.length || r < 0 || r >= plates[0].length || c < 0 || c >= plates[0][0].length);
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 65f89b90abc62f5cb7954613a4d91d2e | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class Serial
{
public static void main
(String[] args)
{
Scanner s = new Scanner(System.in);
int k, n, m;
k = s.nextInt();
n = s.nextInt();
m = s.nextInt();
boolean[][][] dish = new boolean[k+2][n+2][m+2];
// h <- [0.. k+2)
// i <- [0.. n+2)
// j <- [0.. m+2)
// clear h=0 and h=k+1
for(int i = 0; i < n+2; i++){
for(int j = 0; j < m+2; j++){
dish[ 0 ][i][j] = true;
dish[k+1][i][j] = true;
}
}
// clear i=0 and i=n+1
for(int h = 1; h < k+1; h++){
for(int j = 0; j < m+2; j++){
dish[h][ 0 ][j] = true;
dish[h][n+1][j] = true;
}
}
// clear j=0 and j=m+1
for(int h = 1; h < k+1; h++){
for(int i = 1; i < n+1; i++){
dish[h][i][ 0 ] = true;
dish[h][i][m+1] = true;
}
}
String line;
for(int h = 1; h < k+1; h++){
for(int i = 1; i < n+1; i++){
line = s.next();
for(int j = 1; j < m+1; j++){
dish[h][i][j] = (line.charAt(j-1) == '#') ? true : false;
}
}
}
int result = 0;
Queue<Coord> q = new LinkedList<Coord>();
q.add(new Coord(1, s.nextInt(), s.nextInt()));
Coord curr;
while(!q.isEmpty()){
curr = q.remove();
if(!dish[curr.h][curr.i][curr.j]){
dish[curr.h][curr.i][curr.j] = true;
result++;
q.add(new Coord(curr.h + 1, curr.i , curr.j ));
q.add(new Coord(curr.h - 1, curr.i , curr.j ));
q.add(new Coord(curr.h , curr.i + 1, curr.j ));
q.add(new Coord(curr.h , curr.i - 1, curr.j ));
q.add(new Coord(curr.h , curr.i , curr.j + 1));
q.add(new Coord(curr.h , curr.i , curr.j - 1));
}
}
System.out.println(result);
}
static class Coord
{
public int h, i, j;
public Coord(
int h,
int i,
int j
)
{
this.h = h;
this.i = i;
this.j = j;
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | df2bfec4ff2843232e9049193a03ecf9 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigDecimal;
public class Task {
public static void main(String[] args) throws Exception {
new Task().solve();
}
double a;
double b;
double c;
double d;
void solve() throws Exception {
Reader in = new Reader("1.in");
PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(System.out) ) );
int k = in.nextInt();
int n = in.nextInt();
int m = in.nextInt();
int[][][] g = new int[n][m][k];
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
String s = in.next();
for (int j2 = 0; j2 < m; j2++) {
if (s.charAt(j2) == '.') {
g[j][j2][i] = 1;
}
}
}
}
int x = in.nextInt()-1;
int y = in.nextInt()-1;
boolean u[][][] = new boolean[n][m][k];
Queue<Pair> q = new LinkedList<>();
q.add(new Pair(x,y,0));
int count = 0;
u[x][y][0] = true;
while (!q.isEmpty()) {
Pair pair = q.poll();
count++;
x = pair.x;
y = pair.y;
int z = pair.z;
//System.out.println(x+" "+y+" "+z);
if (x+1 < n && g[x+1][y][z] == 1 && !u[x+1][y][z]) {
q.add(new Pair(x+1,y,z));
u[x+1][y][z] = true;
}
if (x-1 >= 0 && g[x-1][y][z] == 1 && !u[x-1][y][z]) {
q.add(new Pair(x-1,y,z));
u[x-1][y][z] = true;
}
if (y+1 < m && g[x][y+1][z] == 1 && !u[x][y+1][z]) {
q.add(new Pair(x,y+1,z));
u[x][y+1][z] = true;
}
if (y-1 >= 0 && g[x][y-1][z] == 1 && !u[x][y-1][z]) {
q.add(new Pair(x,y-1,z));
u[x][y-1][z] = true;
}
if (z+1 < k && g[x][y][z+1] == 1 && !u[x][y][z+1]) {
q.add(new Pair(x,y,z+1));
u[x][y][z+1] = true;
}
if (z-1 >= 0 && g[x][y][z-1] == 1 && !u[x][y][z-1]) {
q.add(new Pair(x,y,z-1));
u[x][y][z-1] = true;
}
}
out.print(count);
out.flush();
out.close();
}
class Pair {
int x;
int y;
int z;
Pair(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}
class Reader {
BufferedReader br;
StringTokenizer token = null;
Reader(String file) throws Exception {
br = new BufferedReader( new InputStreamReader(System.in) );
}
String next() throws Exception {
while (token == null || !token.hasMoreElements()) {
token = new StringTokenizer(br.readLine());
}
return token.nextToken();
}
int nextInt() throws Exception {
return Integer.parseInt(next());
}
long nextLong() throws Exception {
return Long.parseLong(next());
}
double nextDouble() throws Exception {
return Double.parseDouble(next());
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 839fb4bfd5536d6873da93b22675fd57 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes |
import java.io.DataInputStream;
import java.io.InputStream;
public class SerialTime {
static int ans = 0;
static boolean b [][][];
static boolean c [][][];
static int p [][] = {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
public static void main(String [] args) throws Exception{
FS in = new FS(System.in);
int z = in.nextInt();
int n = in.nextInt();
int m = in.nextInt();
b = new boolean[z][n][m];
c = new boolean[z][n][m];
for(int k = 0 ; k < z;k++){
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < m ; j++){
b[k][i][j]=(in.nextChar()=='.')?true:false;
}
}
}
int sx = in.nextInt();
int sy = in.nextInt();
DFS(0 , sx -1 , sy -1);
System.out.println(ans);
}
public static void DFS(int k , int i , int j){
ans++;
c[k][i][j]=true;
for(int a = 0 ; a < 6 ; a++){
try{
if(b[k+p[a][0]][p[a][1]+i][j+p[a][2]] && !c[k+p[a][0]][p[a][1]+i][j+p[a][2]]){
DFS(k+p[a][0],i+p[a][1],j+p[a][2]);
}
}
catch (Exception e){}
}
}
}
class FS
{
final private int BUFFER_SIZE = 1 << 17;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public FS(InputStream in)
{
din = new DataInputStream(in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String nextString() throws Exception
{
StringBuffer sb=new StringBuffer("");
byte c = read();
while (c <= ' ') c = read();
do
{
sb.append((char)c);
c=read();
}while(c>' ');
return sb.toString();
}
public char nextChar() throws Exception
{
byte c=read();
while(c<=' ') c= read();
return (char)c;
}
public int nextInt() throws Exception
{
int ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
public long nextLong() throws Exception
{
long ret = 0;
byte c = read();
while (c <= ' ') c = read();
boolean neg = c == '-';
if (neg) c = read();
do
{
ret = ret * 10 + c - '0';
c = read();
} while (c > ' ');
if (neg) return -ret;
return ret;
}
private void fillBuffer() throws Exception
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) buffer[0] = -1;
}
private byte read() throws Exception
{
if (bufferPointer == bytesRead) fillBuffer();
return buffer[bufferPointer++];
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 35ea91aaa3194f8ad9c78b16f1656a10 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.LinkedList;
import java.util.Scanner;
import java.util.Queue;
public class Serial {
public static void main(String[]args) {
Scanner input = new Scanner(System.in);
int z = input.nextInt();
int x = input.nextInt();
int y = input.nextInt();
input.nextLine();
char[][][] g = new char[x][y][z];
boolean[][][] v = new boolean[x][y][z];
for(int i = 0; i < z; i++) {
input.nextLine();
for(int j = 0; j < x; j++) {
String line = input.nextLine();
for(int k = 0; k < y; k++) {
g[j][k][i] = line.charAt(k);
}
}
}
input.nextLine();
int row = input.nextInt() - 1;
int col = input.nextInt() - 1;
Queue<Point> q = new LinkedList<>();
q.add(new Point(row, col, 0));
v[row][col][0] = true;
int[] xNext = {1, 0, -1, 0, 0, 0};
int[] yNext = {0, 1, 0, -1, 0, 0};
int[] zNext = {0, 0, 0, 0, -1, 1};
int count = 1;
while(!q.isEmpty()) {
Point cur = q.poll();
int xc = cur.x;
int yc = cur.y;
int zc = cur.z;
for(int i = 0; i < 6; i++) {
int xn = xNext[i]+xc;
int yn = yNext[i]+yc;
int zn = zNext[i]+zc;
if(xn >= 0 && xn < x && yn >= 0 && yn < y && zn >=0 && zn < z && !v[xn][yn][zn] && g[xn][yn][zn] == '.') {
q.add(new Point(xn,yn,zn));
v[xn][yn][zn] = true;
count++;
}
}
}
System.out.println(count);
}
}
class Point {
int x;
int y;
int z;
public Point(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | bb995192de9aa46ab72e34f231f360ec | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
BufferedReader in;
StringTokenizer str = null;
PrintWriter out;
private String next() throws Exception{
while (str == null || !str.hasMoreElements())
str = new StringTokenizer(in.readLine());
return str.nextToken();
}
private int nextInt() throws Exception{
return Integer.parseInt(next());
}
private long nextLong() throws Exception{
return Long.parseLong(next());
}
private double nextDouble() throws Exception{
return Double.parseDouble(next());
}
int N, M, K;
char [][][]a;
int [][][]d;
final static int oo = Integer.MAX_VALUE/2;
Queue<int[]> q;
int di[] = new int[]{0, 0, -1, 1, 0, 0};
int dj[] = new int[]{-1, 1, 0, 0, 0, 0};
int dk[] = new int[]{0, 0, 0, 0, -1, 1};
public void run() throws Exception{
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
K = nextInt();
N = nextInt();
M = nextInt();
a = new char[K][N][M];
for(int i=0;i<K;i++){
in.readLine();
for(int j=0;j<N;j++){
char []x = next().toCharArray();
for(int t=0;t<M;t++){
a[i][j][t] = x[t];
}
}
}
// for(int i=0;i<K;i++){
// for(int j=0;j<N;j++){
// System.out.println(Arrays.toString(a[i][j]));
// }
// System.out.println();
// }
d = new int[K][N][M];
for(int i=0;i<K;i++){
for(int j=0;j<N;j++){
Arrays.fill(d[i][j], oo);
}
}
in.readLine();
int si = nextInt()-1, sj = nextInt()-1;
q = new LinkedList<int[]>();
q.add(new int[]{0, si, sj});
d[0][si][sj] = 1;
while(q.size() > 0) {
int []c = q.poll();
// System.out.println(Arrays.toString(c));
int ck = c[0], ci = c[1], cj = c[2];
for(int i=0;i<di.length;i++){
int nk = ck + dk[i];
int ni = ci + di[i];
int nj = cj + dj[i];
add(nk, ni, nj, ck, ci, cj);
}
}
int c = 0;
for(int i=0;i<K;i++){
for(int j=0;j<N;j++){
for(int t=0;t<M;t++){
if (d[i][j][t] == oo) continue;
c++;
}
}
}
out.println(c);
out.close();
}
private void add(int nk, int ni, int nj, int k, int i, int j) {
if (nk < 0 || nk >= K) return;
if (ni < 0 || ni >= N) return;
if (nj < 0 || nj >= M) return;
// System.out.println(nk + " " + ni + " " + nj + " " + k + " " + i + " " + j + " " + d[k][i][j]);
if (a[nk][ni][nj] == '#') return;
if (d[nk][ni][nj] > d[k][i][j] + 1) {
d[nk][ni][nj] = d[k][i][j] + 1;
q.add(new int[]{nk, ni, nj});
}
}
public static void main(String[] args) throws Exception{
new Main().run();
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 9415af136755895cf6e935d1ca92d0de | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main {
BufferedReader in;
StringTokenizer str = null;
PrintWriter out;
private String next() throws Exception{
while (str == null || !str.hasMoreElements())
str = new StringTokenizer(in.readLine());
return str.nextToken();
}
private int nextInt() throws Exception{
return Integer.parseInt(next());
}
private long nextLong() throws Exception{
return Long.parseLong(next());
}
private double nextDouble() throws Exception{
return Double.parseDouble(next());
}
int N, M, K;
char [][][]a;
int di[] = new int[]{0, 0, -1, 1, 0, 0};
int dj[] = new int[]{-1, 1, 0, 0, 0, 0};
int dk[] = new int[]{0, 0, 0, 0, -1, 1};
int []p, size;
public void run() throws Exception{
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
K = nextInt();
N = nextInt();
M = nextInt();
a = new char[K][N][M];
for(int i=0;i<K;i++){
in.readLine();
for(int j=0;j<N;j++){
char []x = next().toCharArray();
for(int t=0;t<M;t++){
a[i][j][t] = x[t];
}
}
}
in.readLine();
int si = nextInt()-1, sj = nextInt()-1;
p = new int[N*K*M];
size = new int[N*K*M];
for(int i=0;i<p.length;i++) {
p[i] = i;
size[i] = 1;
}
for(int k=0;k<K;k++){
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
if (a[k][i][j] == '#') continue;
for(int t=0;t<di.length;t++){
int nk = k + dk[t];
int ni = i + di[t];
int nj = j + dj[t];
union(nk, ni, nj, k, i, j);
}
}
}
}
int id = find(si * M + sj);
out.println(size[id]);
out.close();
}
private void union(int nk, int ni, int nj, int k, int i, int j) {
if (nk < 0 || nk >= K) return;
if (ni < 0 || ni >= N) return;
if (nj < 0 || nj >= M) return;
// System.out.println(nk + " " + ni + " " + nj + " " + k + " " + i + " " + j + " " + d[k][i][j]);
if (a[nk][ni][nj] == '#') return;
int id1 = find(nk * N * M + ni * M + nj);
int id2 = find(k * N * M + i * M + j);
if (id1 == id2) return;
p[id2] = id1;
size[id1]+=size[id2];
}
private int find(int x) {
if (p[x] != x) return p[x] = find(p[x]);
return x;
}
public static void main(String[] args) throws Exception{
new Main().run();
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | ab24965074a28d5f19409dc06a363f8f | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;;
public class serial {
public static char[][][] squares;
public static boolean[][][] visited;
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int l = in.nextInt();
int r = in.nextInt();
int c = in.nextInt();
squares = new char[l][r][c];
visited = new boolean[l][r][c];
in.nextLine();
in.nextLine();
for(int i = 0; i < l; i++)
{
for (int j = 0; j< r; j++)
{
squares[i][j] = in.nextLine().toCharArray();
}
in.nextLine();
}
int x = in.nextInt();
int y = in.nextInt();
int minutes = fillWater(0, x - 1, y - 1);
System.out.println(minutes);
}
public static int fillWater(int l, int r, int c)
{
//System.out.println(l + " " + r + " " + c);
if(!valid(l,r,c) || visited[l][r][c]){
//System.out.println("Not Valid");
return 0;
}
visited[l][r][c] = true;
if(squares[l][r][c] == '.'){
return 1 + fillWater(l+1, r, c) + fillWater(l - 1, r, c) + fillWater(l, r + 1, c) + fillWater(l, r - 1, c) + fillWater(l, r, c + 1) + fillWater(l, r, c-1);
}
return 0;
}
public static boolean valid(int l, int r, int c)
{
return (l >= 0 && l < squares.length) && (r >= 0 && r < squares[l].length) && (c >= 0 && c < squares[l][r].length);
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | d4a90b540e709521f3f2fd8d29bd9f40 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.net.*;
import java.io.*;
public class imba2 {
public static void main( String[] args ) throws Exception {
Scanner file = new Scanner(System.in);
int n , m , bb;
bb= file.nextInt(); n = file.nextInt(); m = file.nextInt();
char [][][] d= new char[bb][n][m];
boolean [][][] visited = new boolean[bb][n][m];
file.nextLine();
for(int e=0; e <bb; e++ ) {
file.nextLine();
for(int dd= 0; dd < n ;dd++) {
d[e][dd] = file.nextLine().toCharArray();
}
}
int time = 0;
Queue<int []> p = new LinkedList<int []>();
int [] news = new int[3];
news[0] = 0;
news[1] = file.nextInt()-1;
news[2] = file.nextInt()-1;
p.add(news);
int [] x = new int[]{1,-1,0,0,0,0};
int [] y = new int[]{0,0,-1,1,0,0};
int [] z = new int[]{0,0,0,0,-1,1};
while(!p.isEmpty()) {
int [] k = p.remove();
int a = k[0];
int b = k[1];
int c= k[2];
if(a>=0 && a< bb && b >=0 && b < n && c >=0 && c < m && !visited[a][b][c] && d[a][b][c] =='.') {
time++;
visited[a][b][c] = true;
for(int h=0; h < 6; h++) {
p.add(new int[] {a+x[h], b +y[h], c+z[h]});
}
}
}
System.out.println(time);
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 5f032e2e8b762683d140f2067d88397e | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class WaterFill {
static int n_x;
static int n_y;
static int n_z;
static char a[][][];
static class Point {
public int x;
public int y;
public int z;
Point(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
}
// The six directions water can flow
static int dx[] = { 1, -1, 0, 0, 0, 0 };
static int dy[] = { 0, 0, 1, -1, 0, 0 };
static int dz[] = { 0, 0, 0, 0, 1, -1 };
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
n_x = scan.nextInt();
n_y = scan.nextInt();
n_z = scan.nextInt();
String whitespace = scan.nextLine();
assert whitespace.equals("");
whitespace = scan.nextLine();
assert whitespace.equals("");
a = new char[n_x][n_y][n_z];
for (int x = 0; x < n_x; ++x) {
for (int y = 0; y < n_y; ++y) {
String line = scan.nextLine();
for (int z = 0; z < n_z; ++z) {
a[x][y][z] = line.charAt(z);
}
}
whitespace = scan.nextLine();
assert whitespace.equals("");
}
Queue<Point> bfsq = new LinkedList<Point>();
// start at the tap's point
int tap_y = scan.nextInt() - 1;
int tap_z = scan.nextInt() - 1;
bfsq.add(new Point(0, tap_y, tap_z));
int drips = 0;
while (bfsq.peek() != null) {
Point p = bfsq.peek();
if (a[p.x][p.y][p.z] == '.') {
a[p.x][p.y][p.z] = 'w';
drips++;
for (int dir = 0; dir < 6; ++dir) {
if (validPoint(p.x + dx[dir], p.y + dy[dir], p.z + dz[dir])) {
bfsq.add(new Point(p.x + dx[dir], p.y + dy[dir], p.z + dz[dir]));
//*dbg*/System.out.printf("Point (%d, %d, %d) added to bfsq\n", p.x + dx[dir], p.y + dy[dir], p.z + dz[dir]);
}
}
}
bfsq.remove();
}
System.out.println(drips);
}
public static boolean validPoint(int x, int y, int z) {
return x >= 0 && x < n_x &&
y >= 0 && y < n_y &&
z >= 0 && z < n_z;
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 1a931e9baecbb91fa2136dd786031900 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | /*
* @Author: steve
* @Date: 2015-12-10 21:43:46
* @Last Modified by: steve
* @Last Modified time: 2015-12-10 22:01:39
*/
import java.io.*;
import java.util.*;
public class SerialTime {
public static boolean[][][] matriz, visitados;
public static int cont,k,n,m;
public static void main(String[] args) throws Exception{
BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
String[] cads = entrada.readLine().split(" ");
k = Integer.parseInt(cads[0]);
n=Integer.parseInt(cads[1]);
m=Integer.parseInt(cads[2]);
matriz = new boolean[k][n][m];
visitados= new boolean[k][n][m];
entrada.readLine();
for(int i=0;i<k;i++){
for(int j=0;j<n;j++){
String cad=entrada.readLine();
for(int l=0;l<m;l++)
if(cad.charAt(l)=='#')
matriz[i][j][l]=true;
//System.out.println(i+" "+j+" "+Arrays.toString(matriz[i][j]));
}
entrada.readLine();
}
cads= entrada.readLine().split(" ");
cont=0;
dfs(0,Integer.parseInt(cads[0])-1,Integer.parseInt(cads[1])-1);
System.out.println(cont);
}
public static void dfs(int i, int j, int l){
if(visitados[i][j][l] || matriz[i][j][l])
return;
//System.out.println(i+" "+j+" "+l);
visitados[i][j][l]=true;
cont++;
if(i+1<k) dfs(i+1,j,l);
if(j+1<n) dfs(i,j+1,l);
if(j-1>=0) dfs(i,j-1,l);
if(l-1>=0) dfs(i,j,l-1);
if(l+1<m) dfs(i,j,l+1);
if(i-1>=0) dfs(i-1,j,l);
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 4e69789926ddc6ef14d56a6bc7f2af36 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class R56qBSerialTime {
static char rect[][][];
static boolean vis[][][];
static int k,n,m;
static int dk[],dx[],dy[];
public static void main(String args[] ) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter w = new PrintWriter(System.out);
dk = new int[]{-1,1,0,0,0,0};
dx = new int[]{0,0,-1,1,0,0};
dy = new int[]{0,0,0,0,-1,1};
StringTokenizer st1 = new StringTokenizer(br.readLine());
k = ip(st1.nextToken());
n = ip(st1.nextToken());
m = ip(st1.nextToken());
br.readLine();
rect = new char[k][n][m];
for(int i=0;i<k;i++){
for(int x=0;x<n;x++)
rect[i][x] = br.readLine().toCharArray();
br.readLine();
}
StringTokenizer st2 = new StringTokenizer(br.readLine());
int x = ip(st2.nextToken()) - 1;
int y = ip(st2.nextToken()) - 1;
vis = new boolean[k][n][m];
vis[0][x][y] = true;
dfs(0,x,y);
int ans = 0;
for(boolean der[][] : vis)
for(boolean der2[] : der)
for(boolean der3 : der2)
if(der3) ans++;
w.println(ans);
w.close();
}
public static void dfs(int lev,int x,int y){
for(int i=0;i<6;i++)
if(g(lev+dk[i],x+dx[i],y+dy[i]) && !vis[lev+dk[i]][x+dx[i]][y+dy[i]]){
vis[lev+dk[i]][x+dx[i]][y+dy[i]] = true;
dfs(lev+dk[i],x+dx[i],y+dy[i]);
}
}
public static boolean g(int x,int y,int z){
return (x>=0) && (y>=0) && (z>=0) && (x<k) && (y<n) && (z<m) && rect[x][y][z] == '.';
}
public static int ip(String s){
return Integer.parseInt(s);
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 2125f3e51b36eabfda055ce94bed6de4 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
*
* @author Mbt
*/
public class G {
public static void main(String[] args) throws IOException {
new Solver().solve();
}
}
class Solver{
final int MAXNMK= 11;
char[][][] plate= new char[MAXNMK][MAXNMK][];
boolean[][][] seen= new boolean[MAXNMK][MAXNMK][MAXNMK];
int[][] adj= { {0, -1, 0}, {0, 1, 0}, {0, 0, -1}, {0, 0, 1}, {1, 0, 0}, {-1, 0, 0} };
int n, m, k;
void solve() throws IOException{
BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer= new StringTokenizer(reader.readLine());
k= Integer.valueOf(tokenizer.nextToken());
n= Integer.valueOf(tokenizer.nextToken());
m= Integer.valueOf(tokenizer.nextToken());
reader.readLine();
for (int i=0; i<k; i++){
for (int j=0; j<n; j++){
plate[i][j]= reader.readLine().toCharArray();
}
reader.readLine();
}
tokenizer= new StringTokenizer(reader.readLine());
int x= Integer.valueOf(tokenizer.nextToken());
int y= Integer.valueOf(tokenizer.nextToken());
System.out.println(dfs(0, x-1, y-1));
}
int dfs(int depth, int row, int col){
if (seen[depth][row][col] || plate[depth][row][col]=='#') return 0;
int count=1;
seen[depth][row][col]= true;
for (int i=0; i<adj.length; i++)
for (int j=0; j<adj[i].length; j++){
int newD= depth + adj[i][0];
int newR= row + adj[i][1];
int newC= col + adj[i][2];
if (newD>=0 && newD<k &&
newR>=0 && newR<n &&
newC>=0 && newC<m)
count += dfs(newD, newR, newC);
}
return count;
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 75eeb2f6f9b594897f6f31bf9a2857a1 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution {
static int result = 0;
static int n, m, k;
static int[][][] d;
static boolean[][][] visited;
static int[] hx = {-1, 0, 1, 0, 0, 0};
static int[] hy = {0, 1, 0, -1, 0, 0};
static int[] hl = {0, 0, 0, 0, -1, 1};
static char[][][] a;
static int[] nFree;
static int[] nFilled;
static void print(boolean[][][] a, int level) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(a[level][i][j]);
}
System.out.println();
}
System.out.println();
}
static void dfs (int u, int v, int lev) {
result++;
for (int i = 0; i < 6; i++) {
int newL = hl[i] + lev;
int newX = hx[i] + u;
int newY = hy[i] + v;
if (newX >= 0 && newX < m && newY >= 0 && newY < n && newL >= 0 && newL < k) {
if (!visited[newL][newX][newY] && a[newL][newX][newY] == '.') {
visited[newL][newX][newY] = true;
dfs(newX, newY, newL);
}
}
}
}
public static void main (String args[]) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
k = sc.nextInt(); m = sc.nextInt(); n = sc.nextInt(); sc.nextLine(); sc.nextLine();
nFree = new int[k];
nFilled = new int[k];
a = new char[k][m][n];
for (int j = 0; j < k; j++) {
for (int i = 0; i < m; i++) a[j][i] = sc.nextLine().toCharArray();
sc.nextLine();
}
int xstart = sc.nextInt(); int ystart = sc.nextInt();
xstart--; ystart--;
visited = new boolean[k][m][n];
visited[0][xstart][ystart] = true;
dfs(xstart, ystart, 0);
pw.println(result);
//for (int i = 0; i < k; i++) print(visited, i);
sc.close();
pw.close();
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | aa833a39752931f154e836533469fcba | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class serial {
static int height, numRows, numCols;
static char[][][] sink;
static int[] dh = {1, -1, 0, 0, 0, 0};
static int[] dr = {0, 0, 1, -1, 0, 0};
static int[] dc = {0, 0, 0, 0, -1, 1};
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
height = in.nextInt();
numRows = in.nextInt();
numCols = in.nextInt();
sink = new char[height][numRows][numCols];
in.nextLine();
for(int k = 0; k < height; k++) {
String placeholder = in.nextLine();
for(int j = 0; j < numRows; j++) {
sink[k][j] = in.nextLine().toCharArray();
}
}
int r = in.nextInt() - 1;
int c = in.nextInt() - 1;
System.out.println(solve(0, r, c));
}
public static int solve(int h, int r, int c) {
if(h < 0 || h >= sink.length
|| r < 0 || r >= sink[0].length
|| c < 0 || c >= sink[0][0].length
|| sink[h][r][c] == '#') {
return 0;
}
sink[h][r][c] = '#';
int total = 0;
for(int i = 0; i < dh.length; i++) {
total += solve(h + dh[i], r + dr[i], c + dc[i]);
}
return 1 + total;
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | b006883234d834a2673146c30fa404ca | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.*;
import java.util.*;
public class b56{
static int k,n,m;
public static void main(String[] args) {
MyScanner obj = new MyScanner();
k=obj.nextInt();
n=obj.nextInt();
m=obj.nextInt();
String s;
char ar[][][]=new char[k][n][m];
int dz[]={0,0,0,0,-1,1};
int dx[]={-1,0,1,0,0,0};
int dy[]={0,-1,0,1,0,0};
obj.nextLine();
for(int z=0;z<k;z++)
{
for(int i=0;i<n;i++)
{
s=obj.nextLine();
for(int j=0;j<m;j++)
{
ar[z][i][j]=s.charAt(j);
}
}
obj.nextLine();
}
int x=obj.nextInt()-1;
int y=obj.nextInt()-1;
UF obj1=new UF(n*m*k);
for(int z=0;z<k;z++)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(ar[z][i][j]=='.'){
for(int c=0;c<6;c++)
{
int nk = z + dz[c];
int ni = i + dx[c];
int nj = j + dy[c];
if(ok(ar,nk,ni,nj))
//System.out.println((((z+dz[c])*n*m)+((i+dx[c])*m)+(i+dy[c]))+" "+(z*n*m+i*m+j));
obj1.union((nk * n * m + ni * m + nj),(z * n * m + i * m + j));
}
}
}
}
}
int id=obj1.find(x*m+y);
System.out.println(obj1.sz[id]);
}
public static boolean ok(char ar[][][],int z,int i,int j)
{
if(i>=0&&i<n&&j>=0&&j<m&&z>=0&&z<k&&ar[z][i][j]=='.')
return true;
return false;
}
public static class UF{
public int[] id; // parent link (site indexed)
public int[] sz; // size of component for roots (site indexed)
public int count; // number of components
public UF(int N)
{
count = N;
id = new int[N];
sz = new int[N];
for (int i = 0; i < N; i++){ id[i] = i;sz[i] = 1;}
}
public int count()
{ return count; }
public boolean connected(int p, int q)
{ return find(p) == find(q); }
public int find(int p)
{ // Follow links to find a root.
while (p != id[p]) {id[p]=id[id[p]];p = id[p];}
return p;
}
public void union(int p, int q)
{
int i = find(p);
int j = find(q);
if (i == j) return;
// Make smaller root point to larger one.
if (sz[i] < sz[j]) { id[i] = j; sz[j] += sz[i]; }
else { id[j] = i; sz[i] += sz[j]; }
count--;
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | af457bd66c58e29c3cee60569da42531 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.*;
import java.util.*;
public class bb56{
static int k,n,m;
public static void main(String[] args) {
MyScanner obj = new MyScanner();
k=obj.nextInt();
n=obj.nextInt();
m=obj.nextInt();
int count=0;
String s;
char ar[][][]=new char[k+5][n+5][m+5];
int no[][][]=new int[k+5][n+5][m+5];
int dz[]={0,0,0,0,-1,1};
int dx[]={-1,0,1,0,0,0};
int dy[]={0,-1,0,1,0,0};
obj.nextLine();
for(int z=1;z<=k;z++)
{
for(int i=1;i<=n;i++)
{
s=obj.nextLine();
for(int j=1;j<=m;j++)
{
ar[z][i][j]=s.charAt(j-1);
if(ar[z][i][j]=='.')
no[z][i][j]=++count;
else
no[z][i][j]=-1;
}
}
obj.nextLine();
}
int x=obj.nextInt();
int y=obj.nextInt();
UF obj1=new UF(count);
for(int z=1;z<=k;z++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(ar[z][i][j]=='.'){
for(int c=0;c<6;c++)
{
if(ok(ar,z+dz[c],i+dx[c],j+dy[c]))
obj1.union(no[z+dz[c]][i+dx[c]][j+dy[c]]-1,no[z][i][j]-1);
}
}
}
}
}
int count1=0;
for(int z=1;z<=k;z++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(ar[z][i][j]=='.'){
if(obj1.connected(no[1][x][y]-1,no[z][i][j]-1))
count1+=1;
}
}
}
}
System.out.println(count1);
}
public static boolean ok(char ar[][][],int z,int i,int j)
{
if(i>=1&&i<=n&&j>=1&&j<=m&&z>=1&&z<=k&&ar[z][i][j]=='.')
return true;
return false;
}
public static class UF{
public int[] id; // parent link (site indexed)
public int[] sz; // size of component for roots (site indexed)
public int count; // number of components
public UF(int N)
{
count = N;
id = new int[N];
sz = new int[N];
for (int i = 0; i < N; i++){ id[i] = i;sz[i] = 1;}
}
public int count()
{ return count; }
public boolean connected(int p, int q)
{ return find(p) == find(q); }
public int find(int p)
{ // Follow links to find a root.
while (p != id[p]) {id[p]=id[id[p]];p = id[p];}
return p;
}
public void union(int p, int q)
{
int i = find(p);
int j = find(q);
if (i == j) return;
// Make smaller root point to larger one.
if (sz[i] < sz[j]) { id[i] = j; sz[j] += sz[i]; }
else { id[j] = i; sz[i] += sz[j]; }
count--;
}
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 31f8afb664e50407c4e393a8661f38c1 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
import java.io.*;
public class serialtime{
public static int tantos = 0;
public static boolean maz[][][];
public static boolean vis[][][];
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
String t[] = lector.readLine().split(" ");
int a= Integer.parseInt(t[0]);
int b= Integer.parseInt(t[1]);
int c= Integer.parseInt(t[2]);
maz = new boolean[a][b][c];
vis = new boolean[a][b][c];
for(int n = 0;n<a;n++){
lector.readLine();
for(int m = 0;m<b;m++){
String tt = lector.readLine();
for(int k = 0;k<c;k++)
maz[n][m][k]=(tt.charAt(k)=='.');
}
}
lector.readLine();
t = lector.readLine().split(" ");
int x = Integer.parseInt(t[0])-1;
int y = Integer.parseInt(t[1])-1;
hagale(0,x,y);
System.out.println(tantos);
}
public static void hagale(int x,int y,int z){
//if(!vis[x][y][z]){
vis[x][y][z] = true;
tantos++;
//}
int dix[] = {1,-1,0,0,0,0};
int diy[] ={0,0,1,-1,0,0};
int diz[] = {0,0,0,0,1,-1};
for(int n = 0;n<6;n++)
if(x+dix[n]>-1 && x+dix[n]<maz.length &&
y+diy[n]>-1 && y+diy[n]<maz[0].length &&
z+diz[n]>-1 && z+diz[n]<maz[0][0].length &&
maz[x+dix[n]][y+diy[n]][z+diz[n]] && !vis[x+dix[n]][y+diy[n]][z+diz[n]])
hagale(x+dix[n],y+diy[n],z+diz[n]);
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 70baacee81b442731a5f8e4820325911 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
import java.io.*;
public class SerialTime
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int k = in.nextInt();
int n = in.nextInt();
int m = in.nextInt();
char[][][] plate = new char[k][n][m];
for(int x = 0; x < k; x++)
{
for(int y = 0; y < n; y++)
{
plate[x][y] = in.next().toCharArray();
}
}
int startX = in.nextInt() - 1;
int startY = in.nextInt() - 1;
int volume = 1;
ArrayList<Drop> queue = new ArrayList<Drop>();
queue.add(new Drop(0, startX, startY));
boolean[][][] visited = new boolean[k][n][m];
visited[0][startX][startY] = true;
int[] dl = {1, -1, 0, 0, 0, 0};
int[] dx = {0, 0, 1, 0, -1, 0};
int[] dy = {0, 0, 0, 1, 0, -1};
while(queue.size() > 0)
{
Drop node = queue.remove(0);
for(int i = 0; i < dl.length; i++)
{
if(node.layer + dl[i] >= 0 && node.layer + dl[i] < k && node.x + dx[i] >= 0 && node.x + dx[i] < n &&
node.y + dy[i] >= 0 && node.y + dy[i] < m && plate[node.layer + dl[i]][node.x + dx[i]][node.y + dy[i]] == '.' &&
!visited[node.layer + dl[i]][node.x + dx[i]][node.y + dy[i]])
{
Drop newNode = new Drop(node.layer + dl[i], node.x + dx[i], node.y + dy[i]);
visited[newNode.layer][newNode.x][newNode.y] = true;
volume++;
queue.add(newNode);
}
}
}
System.out.println(volume);
}
}
class Drop
{
int layer;
int x;
int y;
public Drop(int l, int X, int Y)
{
layer = l;
x = X;
y = Y;
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 48a77bf627ff0e3ca23a692d29fb7e67 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.*;
import java.util.*;
public class B60 {
static int a[][][];
static boolean[][][] was;
static int count;
static int k;
static int n;
static int m;
static boolean check(int x, int y, int z) {
return ((x < k) && (x >= 0) && (y < n) && (y >= 0) && (z < m) && (z >= 0));
}
static void dfs(int x, int y, int z) {
was[x][y][z] = true;
count++;
for (int i = -1; i < 2; i++) {
for (int j = -1; j < 2; j++) {
for (int j2 = -1; j2 < 2; j2++) {
if ((check(x + i, y + j, z + j2)) && (Math.abs(i) + Math.abs(j) + Math.abs(j2) == 1)) {
if (!was[x + i][y + j][z + j2] && (a[x + i][y + j][z + j2] == 0)) {
dfs(x + i, y + j, z + j2);
}
}
}
}
}
}
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
k = in.nextInt();
n = in.nextInt();
m = in.nextInt();
a = new int[k][n][m];
was = new boolean[k][n][m];
count = 0;
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
String s = in.next();
for (int j2 = 0; j2 < m; j2++) {
was[i][j][j2] = false;
if (s.charAt(j2) == '.') {
a[i][j][j2] = 0;
} else {
a[i][j][j2] = 1;
}
}
}
}
int start_x = in.nextInt();
int start_y = in.nextInt();
dfs(0, start_x - 1, start_y - 1);
out.print(count);
out.close();
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 132c95d177cc8f670930651f972586a4 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.Scanner;
public class Main {
private static char[][][] plate;
static int l,n,m;
static final int[] DX = {0,0,1,-1,0,0};
static final int[] DY = {0,0,0,0,1,-1};
static final int[] DZ = {1,-1,0,0,0,0};
static int answer = 0;
static boolean legal(int i, int j, int k) {
return i >= 0 && i < l && j >= 0 && j < n && k >= 0 && k < m;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
l = in.nextInt();
n = in.nextInt();
m = in.nextInt();
plate = new char[l][n][];
for (int i = 0; i < l; i++) {
for (int j = 0; j < n; j++) {
plate[i][j] = in.next().toCharArray();
}
}
int x = in.nextInt() - 1;
int y = in.nextInt() - 1;
dfs(0, x, y);
System.out.println(answer);
}
private static void dfs(int i, int j, int k) {
plate[i][j][k] = '#';
answer++;
for (int t = 0; t < 6; t++) {
int ni = i + DX[t];
int nj = j + DY[t];
int nk = k + DZ[t];
if (legal(ni, nj, nk) && plate[ni][nj][nk] == '.') {
dfs(ni, nj, nk);
}
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 26dd94a8272cf8c92292e43e8b07dba0 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | //http://codeforces.com/problemset/problem/60/B
import java.util.*;
import java.io.*;
public class Serial
{
public static void main(String args[])
{
Scanner fin = new Scanner(System.in);
int layers = fin.nextInt();
int rows = fin.nextInt();
int cols = fin.nextInt();
char plates[][][] = new char[layers][rows][cols];
fin.nextLine();
for(int i = 0; i < layers; ++i)
{
fin.nextLine();
for(int j = 0; j < rows; ++j)
{
String line = fin.nextLine();
for(int k = 0; k < cols; ++k)
{
plates[i][j][k] = line.charAt(k);
}
}
}
int startX = fin.nextInt();
int startY = fin.nextInt();
int count[] = {0};
dfs(plates, 0, startX - 1, startY - 1, count);
System.out.println(count[0]);
}
public static void dfs(char plates[][][], int plate, int r, int c, int count[])
{
//System.out.println(plate + " " + r + " " + c + " " + plates.length);
if((plate < 0 || plate >= plates.length) || (r < 0 || r >= plates[0].length) || (c < 0 || c >= plates[0][0].length))
{
return;
}
if(plates[plate][r][c] != '.')
{
return;
}
count[0]++;
plates[plate][r][c] = 'V';
dfs(plates, plate + 1, r, c, count);
dfs(plates, plate, r + 1, c, count);
dfs(plates, plate, r - 1, c, count);
dfs(plates, plate, r, c + 1, count);
dfs(plates, plate, r, c - 1, count);
dfs(plates, plate - 1, r, c, count);
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | c2b9c5ec36442de12351fc3281de8a48 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.StringTokenizer;
public class CodeG
{
static class Scanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String nextLine()
{
try
{
return br.readLine();
}
catch(Exception e)
{
throw(new RuntimeException());
}
}
public String next()
{
while(!st.hasMoreTokens())
{
String l = nextLine();
if(l == null)
return null;
st = new StringTokenizer(l);
}
return st.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
public double nextDouble()
{
return Double.parseDouble(next());
}
public int[] nextIntArray(int n)
{
int[] res = new int[n];
for(int i = 0; i < res.length; i++)
res[i] = nextInt();
return res;
}
public long[] nextLongArray(int n)
{
long[] res = new long[n];
for(int i = 0; i < res.length; i++)
res[i] = nextLong();
return res;
}
public double[] nextDoubleArray(int n)
{
double[] res = new double[n];
for(int i = 0; i < res.length; i++)
res[i] = nextDouble();
return res;
}
public void sortIntArray(int[] array)
{
Integer[] vals = new Integer[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public void sortLongArray(long[] array)
{
Long[] vals = new Long[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public void sortDoubleArray(double[] array)
{
Double[] vals = new Double[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public String[] nextStringArray(int n)
{
String[] vals = new String[n];
for(int i = 0; i < n; i++)
vals[i] = next();
return vals;
}
public Integer nextInteger()
{
String s = next();
if(s == null)
return null;
return Integer.parseInt(s);
}
public int[][] nextIntMatrix(int n, int m)
{
int[][] ans = new int[n][];
for(int i = 0; i < n; i++)
ans[i] = nextIntArray(m);
return ans;
}
public char[][] nextGrid(int r, int c)
{
char[][] grid = new char[r][];
for(int i = 0; i < r; i++)
grid[i] = next().toCharArray();
return grid;
}
public static <T> T fill(T arreglo, int val)
{
if(arreglo instanceof Object[])
{
Object[] a = (Object[]) arreglo;
for(Object x : a)
fill(x, val);
}
else if(arreglo instanceof int[])
Arrays.fill((int[]) arreglo, val);
else if(arreglo instanceof double[])
Arrays.fill((double[]) arreglo, val);
else if(arreglo instanceof long[])
Arrays.fill((long[]) arreglo, val);
return arreglo;
}
<T> T[] nextObjectArray(Class <T> clazz, int size)
{
@SuppressWarnings("unchecked")
T[] result = (T[]) java.lang.reflect.Array.newInstance(clazz, size);
for(int c = 0; c < 3; c++)
{
Constructor <T> constructor;
try
{
if(c == 0)
constructor = clazz.getDeclaredConstructor(Scanner.class, Integer.TYPE);
else if(c == 1)
constructor = clazz.getDeclaredConstructor(Scanner.class);
else
constructor = clazz.getDeclaredConstructor();
}
catch(Exception e)
{
continue;
}
try
{
for(int i = 0; i < result.length; i++)
{
if(c == 0)
result[i] = constructor.newInstance(this, i);
else if(c == 1)
result[i] = constructor.newInstance(this);
else
result[i] = constructor.newInstance();
}
}
catch(Exception e)
{
throw new RuntimeException(e);
}
return result;
}
throw new RuntimeException("Constructor not found");
}
public void printLine(int... vals)
{
if(vals.length == 0)
System.out.println();
else
{
System.out.print(vals[0]);
for(int i = 1; i < vals.length; i++)
System.out.print(" ".concat(String.valueOf(vals[i])));
System.out.println();
}
}
public void printLine(long... vals)
{
if(vals.length == 0)
System.out.println();
else
{
System.out.print(vals[0]);
for(int i = 1; i < vals.length; i++)
System.out.print(" ".concat(String.valueOf(vals[i])));
System.out.println();
}
}
public void printLine(double... vals)
{
if(vals.length == 0)
System.out.println();
else
{
System.out.print(vals[0]);
for(int i = 1; i < vals.length; i++)
System.out.print(" ".concat(String.valueOf(vals[i])));
System.out.println();
}
}
public void printLine(int prec, double... vals)
{
if(vals.length == 0)
System.out.println();
else
{
System.out.printf("%." + prec + "f", vals[0]);
for(int i = 1; i < vals.length; i++)
System.out.printf(" %." + prec + "f", vals[i]);
System.out.println();
}
}
}
static int k, n, m;
static char[][][] tablero;
static int floodFill(int i, int j, int l)
{
if(i < 0 || i >= k || j < 0 || j >= n || l < 0 || l >= m || tablero[i][j][l] == '#')
return 0;
tablero[i][j][l] = '#';
return 1 + floodFill(i + 1, j, l) + floodFill(i - 1, j, l) +
floodFill(i, j + 1, l) + floodFill(i, j - 1, l) +
floodFill(i, j, l + 1) + floodFill(i, j, l - 1);
}
public static void main(String[] args)
{
Scanner sc = new Scanner();
k = sc.nextInt();
n = sc.nextInt();
m = sc.nextInt();
tablero = new char[k][n][];
for(int i = 0; i < k; i++)
for(int j = 0; j < n; j++)
tablero[i][j] = sc.next().toCharArray();
int i = sc.nextInt();
int j = sc.nextInt();
int total = floodFill(0, i - 1, j - 1);
sc.printLine(total);
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | bb9c5468e3991961098f9c5da1dcd3ad | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class SerialTime {
int k;
int n;
int m;
int x;
int y;
int[] dx = {1, 0, -1, 0, 0, 0};
int[] dy = {0, 1, 0, -1, 0, 0};
int[] dz = {0, 0, 0, 0, 1, -1};
char[][][] plate;
Deque<Coord> toVisit;
int visited;
public static void main(String[] args) {
SerialTime main = new SerialTime();
main.run();
}
public void run() {
plate = new char[10][10][10];
Scanner sc = new Scanner(System.in);
k = sc.nextInt();
n = sc.nextInt();
m = sc.nextInt();
sc.nextLine();
sc.nextLine();
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
String line = sc.nextLine();
for (int l = 0; l < m; l++) {
plate[i][j][l] = line.charAt(l);
}
}
sc.nextLine();
}
x = sc.nextInt();
y = sc.nextInt();
x--;
y--;
sc.close();
bfs();
}
public int bfs() {
visited = 0;
toVisit = new ArrayDeque<Coord>(1000);
toVisit.addLast(new Coord(x, y, 0));
while (!toVisit.isEmpty()) {
Coord currentCoord = toVisit.poll();
int currentX = currentCoord.x;
int currentY = currentCoord.y;
int currentZ = currentCoord.z;
if (plate[currentZ][currentX][currentY] != '.') {
continue;
}
plate[currentZ][currentX][currentY] = 'v';
visited++;
for (int i = 0; i < dx.length; i++) {
if ((currentX + dx[i] < n && currentX + dx[i] >= 0) &&
(currentY + dy[i] < m && currentY + dy[i] >= 0) &&
(currentZ + dz[i] < k && currentZ + dz[i] >= 0) &&
(plate[currentZ + dz[i]][currentX + dx[i]][currentY + dy[i]] == '.')) {
Coord coord = new Coord(currentX + dx[i], currentY + dy[i], currentZ + dz[i]);
toVisit.addLast(coord);
}
}
}
System.out.println(visited);
return visited;
}
public void printPlate() {
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
for (int l = 0; l < m; l++) {
System.out.print(plate[i][j][l]);
}
System.out.println();
}
System.out.println();
}
}
public class Coord {
int x;
int y;
int z;
public Coord(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public String toString() {
return "x = " + x + " y = " + y + " z = " + z;
}
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 571f54d375d277880880f17e4da27aec | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class SerialTime {
int k;
int n;
int m;
int x;
int y;
int[] dx = {1, 0, -1, 0, 0, 0};
int[] dy = {0, 1, 0, -1, 0, 0};
int[] dz = {0, 0, 0, 0, 1, -1};
char[][][] plate;
Deque<Coord> toVisit;
int visited;
public static void main(String[] args) {
SerialTime main = new SerialTime();
main.run();
}
public void run() {
plate = new char[10][10][10];
Scanner sc = new Scanner(System.in);
k = sc.nextInt();
n = sc.nextInt();
m = sc.nextInt();
sc.nextLine();
sc.nextLine();
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
String line = sc.nextLine();
for (int l = 0; l < m; l++) {
plate[i][j][l] = line.charAt(l);
}
}
sc.nextLine();
}
x = sc.nextInt();
y = sc.nextInt();
x--;
y--;
sc.close();
// printPlate();
bfs();
}
public int bfs() {
visited = 0;
toVisit = new ArrayDeque<Coord>(1000);
toVisit.addLast(new Coord(x, y, 0));
while (!toVisit.isEmpty()) {
Coord currentCoord = toVisit.poll();
// System.out.println("currentCoord = " + currentCoord);
int currentX = currentCoord.x;
int currentY = currentCoord.y;
int currentZ = currentCoord.z;
if (plate[currentZ][currentX][currentY] != '.') {
continue;
}
plate[currentZ][currentX][currentY] = 'v';
visited++;
// System.out.println();
for (int i = 0; i < dx.length; i++) {
if ((currentX + dx[i] < n && currentX + dx[i] >= 0) &&
(currentY + dy[i] < m && currentY + dy[i] >= 0) &&
(currentZ + dz[i] < k && currentZ + dz[i] >= 0) &&
(plate[currentZ + dz[i]][currentX + dx[i]][currentY + dy[i]] == '.')) {
Coord coord = new Coord(currentX + dx[i], currentY + dy[i], currentZ + dz[i]);
// System.out.println("coord to be added = " + coord);
toVisit.addLast(coord);
}
}
// System.out.println();
}
System.out.println(visited);
// System.out.println();
// printPlate();
return visited;
}
public void printPlate() {
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
for (int l = 0; l < m; l++) {
System.out.print(plate[i][j][l]);
}
System.out.println();
}
System.out.println();
}
}
public class Coord {
int x;
int y;
int z;
public Coord(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public String toString() {
return "x = " + x + " y = " + y + " z = " + z;
}
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 38220f08954e23841974f371fdc1dae9 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.*;
import java.util.*;
public class Pr60B {
public static void main(String[] args) throws IOException {
new Pr60B().run();
}
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());
}
void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out, true);
solve();
out.flush();
}
int[][][] plan;
int n;
int m;
int k;
final int[][] where = { { 0, 0, -1 }, { 0, 0, 1 }, { 0, -1, 0 },
{ 0, 1, 0 }, { -1, 0, 0 }, { 1, 0, 0 } };
void dfs(int i, int j, int c) {
plan[i][j][c] = 1;
for (int t = 0; t < 6; t++) {
if (i + where[t][0] > -1 && i + where[t][0] < k) {
if (j + where[t][1] > -1 && j + where[t][1] < n) {
if (c + where[t][2] > -1 && c + where[t][2] < m) {
if (plan[i + where[t][0]][j + where[t][1]][c
+ where[t][2]] == 0) {
dfs(i + where[t][0], j + where[t][1], c
+ where[t][2]);
}
}
}
}
}
}
void solve() throws IOException {
k = nextInt();
n = nextInt();
m = nextInt();
plan = new int[k][n][m];
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
String s = nextToken();
for (int c = 0; c < m; c++) {
if (s.charAt(c) != '.') {
plan[i][j][c] = -1;
}
}
}
}
int x = nextInt() - 1;
int y = nextInt() - 1;
dfs(0, x, y);
int time = 0;
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
for (int c = 0; c < m; c++) {
if (plan[i][j][c] == 1) {
time++;
}
}
}
}
out.println(time);
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | f472a7938b22b8ff0df68fbdbed2205f | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.Scanner;
public class Serial {
private static int arrx[]= {1,0,0,-1,0,0}, arry[]={0,1,0,0,-1,0}, arrz[]={0,0,1,0,0,-1};
private static int[][][] connect;
private static char[][][] bowl;
// private static int count;
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int layers = in.nextInt();
int length = in.nextInt();
int width = in.nextInt();
// System.out.println(layers + " " + length+ " " + width);
connect = new int[layers][length][width];
bowl = new char[layers][length][width];
in.nextLine();
in.nextLine();
for(int i = 0; i<layers; i++)
{
for(int j = 0; j<length; j++)
{
bowl[i][j]= in.nextLine().toCharArray();
for(int k = 0; k<width;k++)
{
connect[i][j][k] = 0;
}
}
in.nextLine();
}
// string();
int startl = in.nextInt()-1;
int startw = in.nextInt()-1;
//dfs method
System.out.println(count(startl, startw));
// System.out.println();
// string();
}
static int count(int l, int w)
{
int amnt = 0;
amnt = check(0, l, w, 1);
return amnt;
}
static int check(int x, int y, int z, int count)
{
connect[x][y][z] = 1;
boolean check = false;
for(int i =0; i<6; i++)
{
if(x+arrx[i]>=0 && x+arrx[i]<connect.length && y+arry[i]>=0 && y+arry[i]<connect[x].length && z+arrz[i]>=0 && z+arrz[i]<connect[x][y].length && connect[x+arrx[i]][y+arry[i]][z+arrz[i]]!=1 && bowl[x+arrx[i]][y+arry[i]][z+arrz[i]]!= '#' && bowl[x+arrx[i]][y+arry[i]][z+arrz[i]]== '.' )
{
// System.out.println(x + " " + y + " " + z);
check = true;
count += check(x+arrx[i],y+arry[i],z+arrz[i], 1);
}
}
if(check)
return count;
else
return 1;
}
static void string()
{
for(int[][] a: connect)
{
for(int[] b: a)
{
for(int c: b)
{
System.out.print(c + " ");
}
System.out.println();
}
}
for(char[][] a: bowl)
{
for(char[] b: a)
{
for(char c: b)
{
System.out.print(c + " ");
}
System.out.println();
}
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | dfb32cffe2075efe9857dbfa69883b27 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.*;
import java.util.*;
public class DFS_1 {
private static boolean[][][] visited, matrix;
public static void main(String[] args) {
Scanner util = new Scanner(System.in);
int k = util.nextInt();
int n = util.nextInt();
int m = util.nextInt();
util.nextLine();
util.nextLine();
matrix = new boolean[k][n][m];
visited = new boolean[k][n][m];
for(int i = 0; i < k; i++) {
for(int j = 0; j < n; j++) {
String in = util.nextLine();
for(int l = 0; l < m; l++) {
if(in.charAt(l) == '.')
matrix[i][j][l] = true;
else
matrix[i][j][l] = false;
}
}
util.nextLine();
}
int x = util.nextInt() - 1;
int y = util.nextInt() - 1;
util.nextLine();
System.out.println(dfs(x, y, 0));
}
private static int dfs (int x, int y, int z) {
if(x < 0 || y < 0 || z < 0 || matrix.length <= z ||
matrix[0].length <= x || matrix[0][0].length <= y ||
!matrix[z][x][y] || visited[z][x][y])
return 0;
visited[z][x][y] = true;
int sum = 0;
for(int dz = -1; dz <= 1; dz++) {
for(int dx = -1; dx <= 1; dx++) {
for(int dy = -1; dy <= 1; dy++) {
if(Math.abs(dx) + Math.abs(dy) + Math.abs(dz) != 1)
continue;
sum += dfs(x + dx, y + dy, z + dz);
}
}
}
return sum + 1;
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 169402bac3e5cfc1b3198f0ee3019981 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.Scanner;
public class SerialTime {
private static boolean[][][] plate;
public static int check(int x, int y, int z) {
int[] dz = { -1, 1, 0, 0, 0, 0 };
int[] dx = { 0, 0, -1, 1, 0, 0 };
int[] dy = { 0, 0, 0, 0, -1, 1 };
if(x < 0 || x >= plate.length || y < 0 || y >= plate[0].length || z < 0 || z >= plate[0][0].length) {
return 0;
}
if(plate[x][y][z]) {
return 0;
}
plate[x][y][z] = true;
int count = 1;
for(int i = 0; i < 6; ++i){
count+=(check(x+dx[i],y+dy[i],z+dz[i]));
}
return count;
}
public static void main(String[] args) {
// read in values
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int n = sc.nextInt();
int m = sc.nextInt();
// create 3-d layers for plate
plate = new boolean[k][n][m];
for(int i = 0; i < k; i++) {
for(int j = 0; j < n; j++) {
String s = sc.next();
for(int l = 0; l < m; l++) {
char curr = s.charAt(l);
plate[i][j][l] = curr == '#';
}
}
}
int next1 = sc.nextInt()- 1;
int next2 = sc.nextInt() - 1;
int done = check(0,next1, next2);
System.out.println(done);
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 2a9601468350b44940e43c64df26cd60 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class P060B {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int K = in.nextInt();
int N = in.nextInt();
int M = in.nextInt();
boolean[][][] plate = new boolean[K][N][M];
boolean[][][] visit = new boolean[K][N][M];
for (int k = 0; k < K; ++k)
for (int n = 0; n < N; ++n)
{
String line = in.next();
for (int m = 0; m < M; ++m)
plate[k][n][m] = line.charAt(m) == '.';
}
int X = in.nextInt()-1;
int Y = in.nextInt()-1;
if (!plate[0][X][Y])
{
System.out.println(0);
return;
}
int ans = 1;
ArrayDeque<Point> bfs = new ArrayDeque<Point>();
visit[0][X][Y] = true;
bfs.add(new Point(X, Y, 0));
int[] dx = {-1, 1, 0, 0, 0, 0};
int[] dy = {0, 0, -1, 1, 0, 0};
int[] dz = {0, 0, 0, 0, -1, 1};
while (!bfs.isEmpty())
{
Point cur = bfs.remove();
//System.out.println("At " + cur.z + " " + cur.x + " " + cur.y);
for (int i = 0; i < 6; ++i)
{
int newx = cur.x + dx[i];
int newy = cur.y + dy[i];
int newz = cur.z + dz[i];
if (newx < 0 || newx >= N || newy < 0 || newy >= M || newz < 0 || newz >= K) continue;
if (!plate[newz][newx][newy] || visit[newz][newx][newy]) continue;
++ans;
visit[newz][newx][newy] = true;
bfs.add(new Point(newx, newy, newz));
}
}
System.out.println(ans);
}
static class Point {
int x, y, z;
public Point(int x, int y, int z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 3f6ede5771df8d8daff7e4bad6a8b9b1 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.LinkedList;
import java.util.Scanner;
public class B {
static class Triple {
int i, j, k;
public Triple(int kk, int ii, int jj) {
i = ii;
j = jj;
k = kk;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt(), n = sc.nextInt(), m = sc.nextInt();
char[][][] grid = new char[k][n][m];
boolean[][][] vis = new boolean[k][n][m];
for (int _ = 0; _ < k; _++) {
for (int i = 0; i < n; i++) {
String row=sc.next();
for (int j = 0; j < m; j++) {
grid[_][i][j] = row.charAt(j);
}
}
}
int x = sc.nextInt() - 1;
int y = sc.nextInt() - 1;
LinkedList<Triple> queue = new LinkedList<Triple>();
queue.add(new Triple(0, x, y));
int res = 0;
int[] dx = new int[] { -1, 0, 1, 0, 0, 0 };
int[] dy = new int[] { 0, -1, 0, 1, 0, 0 };
int[] dz = new int[] { 0, 0, 0, 0, -1, 1 };
while (!queue.isEmpty()) {
Triple tmp = queue.remove();
if (vis[tmp.k][tmp.i][tmp.j])
continue;
vis[tmp.k][tmp.i][tmp.j] = true;
res++;
for (int i = 0; i < dx.length; i++) {
int newK = tmp.k + dz[i];
int newI = tmp.i + dx[i];
int newJ = tmp.j + dy[i];
if (newK >= 0 && newK < k && newI >= 0 && newI < n && newJ >= 0
&& newJ < m) {
if (grid[newK][newI][newJ] != '#')
queue.add(new Triple(newK, newI, newJ));
}
}
}
System.out.println(res);
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 27942d1c28f5464c122088ea0bdd488c | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.Scanner;
// 60B
public class SerialTime {
static int height;
static int rows;
static int cols;
static int[] dx = new int[] { 1, 0, 0, -1, 0, 0 };
static int[] dy = new int[] { 0, 1, 0, 0, -1, 0 };
static int[] dz = new int[] { 0, 0, 1, 0, 0, -1 };
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
height = in.nextInt();
rows = in.nextInt();
cols = in.nextInt();
char[][][] plate = new char[cols][rows][height];
for (int i = height - 1; i >= 0; i--) {
for (int j = rows - 1; j >= 0; j--) {
String line = in.next();
for (int k = 0; k < cols; k++) {
plate[k][j][i] = line.charAt(k);
}
}
}
int y = rows - in.nextInt();
int x = in.nextInt() - 1;
int z = height - 1;
System.out.println(dfs(plate, x, y, z, new boolean[cols][rows][height]));
}
static int dfs(char[][][] plate, int x, int y, int z, boolean[][][] visited) {
visited[x][y][z] = true;
int reachable = 1;
for (int i = 0; i < dx.length; i++) {
int newX = x + dx[i], newY = y + dy[i], newZ = z + dz[i];
if (newX >= 0 && newX < cols &&
newY >= 0 && newY < rows &&
newZ >= 0 && newZ < height &&
!visited[newX][newY][newZ] && plate[newX][newY][newZ] != '#') {
reachable += dfs(plate, newX, newY, newZ, visited);
}
}
return reachable;
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 4360685c2afafaf8c29416c33f2c9d7e | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static BufferedReader br;
static PrintWriter out;
static StringTokenizer st;
static class Coor{
private int a;
private int b;
private int c;
public Coor(int a, int b, int c){
this.a = a;
this.b = b;
this.c = c;
}
public Coor add(int[] v){
return new Coor(a + v[0],
b + v[1],
c + v[2]);
}
public boolean isCorrect(){
return
(a >= 0 && a < k) &&
(b >= 0 && b < n) &&
(c >= 0 && c < m);
}
}
static int[][] vector = new int[][]{{0, 0, 1}, {0, 0, -1}, {0, 1, 0}, {0, -1, 0}, {1, 0, 0}, {-1, 0, 0}};
static int cnt = 0;
static char[][][] a;
static int k;
static int n;
static int m;
static void dfs(Coor s){
a[s.a][s.b][s.c] = '#';
cnt++;
for(int i = 0; i < vector.length; i++){
Coor c = s.add(vector[i]);
if(c.isCorrect() && a[c.a][c.b][c.c] == '.'){
dfs(c);
}
}
}
static void solve() throws Exception {
k = nextInt();
n = nextInt();
m = nextInt();
a = new char[k][n][m];
for(int i = 0; i < k; i++){
for(int j = 0; j < n; j++){
String line = next();
for(int p = 0; p < m; p++){
a[i][j][p] = line.charAt(p);
}
}
}
int x = nextInt() - 1;
int y = nextInt() - 1;
Coor start = new Coor(0, x, y);
dfs(start);
out.println(cnt);
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}
static long nextLong() throws IOException {
return Long.parseLong(next());
}
static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = br.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
public static void main(String[] args) {
try {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new PrintStream(System.out));
solve();
out.close();
br.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | f0b2e2c70908fd9eb1c9e4491dd911e6 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.System.*;
public class Solution60b {
char[][][] mat;
int lays, rows, cols;
int[] dy = {1, -1, 0, 0, 0, 0};
int[] dr = {0, 0, 1, -1, 0, 0};
int[] dc = {0, 0, 0, 0, 1, -1};
public void run() throws Exception {
Scanner file = new Scanner(System.in);
lays = file.nextInt();
rows = file.nextInt();
cols = file.nextInt();
mat = new char[lays][rows][cols];
for(int lay = 0; lay < lays; lay++) {
for(int r = 0; r < rows; r++) {
mat[lay][r] = file.next().toCharArray();
}
}
int sr = file.nextInt();
int sc = file.nextInt();
int t = 0;
HashSet<int[]> v = new HashSet<int[]>();
LinkedList<int[]> q = new LinkedList<int[]>();
q.add(new int[] {0, sr-1, sc-1});
while(!q.isEmpty()) {
int blarf = q.size();
for(int yo = 0; yo < blarf; yo++) {
int[] p = q.remove();
// out.println("reading " + Arrays.toString(p));
if(in(p) && at(p) == '.') {
t++;
block(p);
for (int i = 0; i < dy.length; i++) {
int[] n = {p[0] + dy[i], p[1] + dr[i], p[2] + dc[i]};
if(in(n) && !v.contains(n) && at(n) == '.'){
v.add(n);
q.add(n);
// out.println(Arrays.toString(n));
}
}
}
}
}
out.println(t);
}
public void block(int[] p) {
mat[p[0]][p[1]][p[2]] = '#';
}
public char at(int[] p){
return mat[p[0]][p[1]][p[2]];
}
public boolean in(int[] p) {
int y = p[0];
int r = p[1];
int c = p[2];
return y>=0&&y<lays&&r>=0&&r<rows&&c>=0&&c<cols;
}
public static void main(String[] args) throws Exception {
new Solution60b().run();
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | fa018959b886f18f1d5ef5bb8cf83102 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class SerialTime {
public static void main(String[] args) throws IOException {
Scanner kb = new Scanner(System.in);
int layers = kb.nextInt();
int rows = kb.nextInt();
int cols = kb.nextInt();
kb.nextLine();
kb.nextLine();
char [][][] map = new char[rows][cols][layers];
createMap(kb, layers, map);
int rowStart = kb.nextInt() - 1;
int colStart = kb.nextInt() - 1;
int output = findOpenSpots(map, rowStart, colStart);
System.out.println(output);
}
public static int findOpenSpots(char [][][] map, int row, int col) {
int output = openSpotsHelper(map, row, col, 0);
return output;
}
public static int openSpotsHelper(char [][][] map, int row, int col, int layer) {
int sum = 0;
// isValid checks to see if the row and col is in range and if
// the current spot is an empty spot
if(isValid(map, row, col, layer)) {
sum++;
// X means visited;
map[row][col][layer] = 'X';
sum += openSpotsHelper(map, row, col, layer - 1);
sum += openSpotsHelper(map, row, col - 1, layer);
sum += openSpotsHelper(map, row - 1, col, layer);
sum += openSpotsHelper(map, row, col + 1, layer);
sum += openSpotsHelper(map, row + 1, col, layer);
sum += openSpotsHelper(map, row, col, layer + 1);
}
return sum;
}
public static boolean isValid(char[][][] map, int row, int col, int layer) {
return row >= 0 && row < map.length && col >= 0 && col < map[0].length &&
layer >= 0 && layer < map[0][0].length && map[row][col][layer] == '.';
}
// growing from top to bottom, 0 layer is the top!
public static void createMap(Scanner kb, int layers, char [][][] map) {
int lays = 0;
while(lays < layers) {
for(int row = 0; row < map.length; row++) {
String line = kb.nextLine();
for(int col = 0; col < map[0].length; col++) {
map[row][col][lays] = line.charAt(col);
}
}
kb.nextLine();
lays++;
}
}
public static void printMap(char[][][] map) {
for(int layer = 0; layer < map[0][0].length; layer++) {
for(int row = 0; row < map.length; row++) {
for(int col = 0; col < map[0].length; col++) {
System.out.print(map[row][col][layer]);
}
System.out.println();
}
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 9cd017ea07f3259f1cc807db2ef8f4b2 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.InputStream;
import java.io.OutputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class Task {
private static final boolean readFromFile = false;
public static void main(String args[]){
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FileOutputStream fileOutputStream;
FileInputStream fileInputStream;
if (readFromFile){
try{
fileInputStream = new FileInputStream(new File("input.txt"));
fileOutputStream = new FileOutputStream(new File("output.txt"));
}catch (FileNotFoundException e){
throw new RuntimeException(e);
}
}
PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
InputReader in = new InputReader((readFromFile)?fileInputStream:inputStream);
Solver s = new Solver(in,out);
s.solve();
out.close();
}
}
class Solver{
InputReader in;
PrintWriter out;
char map[][][];
boolean u[][][];
int ans = 0,m,n,k;
static final int dx[] = {-1,0,0,1,0,0};
static final int dy[] = {0,1,-1,0,0,0};
static final int dz[] = {0,0,0,0,-1,1};
void dfs(int z, int y, int x){
u[z][y][x]=true;
ans++;
for (int i=0;i<6;i++){
int nx = x +dx[i];
int ny = y +dy[i];
int nz = z +dz[i];
if (nx>=0 && nx<m &&
ny>=0 && ny<n &&
nz>=0 && nz<k &&
!u[nz][ny][nx] &&
map[nz][ny][nx]!='#')
dfs(nz, ny, nx);
}
}
public void solve(){
k = in.nextInt();
n = in.nextInt();
m = in.nextInt();
map = new char[k][n][m];
in.nextLine();
for (int i=0;i<k;i++){
for (int j=0;j<n;j++){
String temp = in.nextLine();
map[i][j] = temp.toCharArray();
}
in.nextLine();
}
int y = in.nextInt(),
x = in.nextInt();
u = new boolean[k][n][m];
dfs(0,y-1,x-1);
out.println(ans);
}
Solver(InputReader in, PrintWriter out){
this.in=in;
this.out=out;
}
}
class InputReader{
private BufferedReader buf;
private StringTokenizer tok;
InputReader(InputStream in){
tok = null;
buf = new BufferedReader(new InputStreamReader(in));
}
InputReader(FileInputStream in){
tok = null;
buf = new BufferedReader(new InputStreamReader(in));
}
public String next(){
while (tok==null || !tok.hasMoreTokens()){
try{
tok = new StringTokenizer(buf.readLine());
}catch (IOException e){
throw new RuntimeException(e);
}
}
return tok.nextToken();
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public float nextFloat(){
return Float.parseFloat(next());
}
public String nextLine(){
try{
return buf.readLine();
}catch (IOException e){
return null;
}
}
} | Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 7d445e689b9a8e342621b7c2987f1135 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
public class SerialTime {
static int[] dk = {1, -1, 0, 0, 0, 0};
static int[] dn = {0, 0, 1, -1, 0, 0};
static int[] dm = {0, 0, 0, 0, 1, -1};
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int k = scan.nextInt();
int n = scan.nextInt();
int m = scan.nextInt();
char[][][] plate = new char[k][n][m];
for (int i = 0; i < k; i++) {
for (int j = 0; j < n; j++) {
String s = scan.next();
for (int h = 0; h < m; h++) {
plate[i][j][h] = s.charAt(h);
}
}
}
int x = scan.nextInt();
int y = scan.nextInt();
System.out.println(search(0, x - 1, y - 1, plate, 0));
}
private static int search(int k, int n, int m, char[][][] plate, int count) {
if (k >= 0 && k < plate.length && n >= 0 && n < plate[0].length
&& m >= 0 && m < plate[0][0].length && plate[k][n][m] == '.') {
plate[k][n][m] = '#';
int curr = count;
for (int i = 0; i < 6; i++) {
count += search(k + dk[i], n + dn[i], m + dm[i], plate, curr);
}
return 1 + count;
}
return 0;
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 0f379cd3e6a7d05a60dcb60ed35388a7 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Solution60B {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
int K = in.nextInt(), N = in.nextInt(), M = in.nextInt();
char[][][] mat = new char[K][N][M];
for (int i = 0; i < K; i++) {
for (int j = 0; j < N; j++) {
String next = in.next();
mat[i][j] = next.toCharArray();
}
}
int r = in.nextInt() - 1, c = in.nextInt() - 1;
int val = dfs(mat, 0, r, c);
System.out.println(val);
}
static int[] dh = {0, 0, 0, 0, 1, -1};
static int[] dr = {-1, 0, 1, 0, 0, 0};
static int[] dc = {0, -1, 0, 1, 0, 0};
public static int dfs(char[][][] mat, int h, int r, int c) {
if (!inBounds(mat, h, r, c)) {
// System.out.println("not inbounds");
// System.out.println(h + " " + r + " " + c);
// System.out.println(mat.length + " " + mat[0].length + " " + mat[0][0].length);
return 0;
}
if (mat[h][r][c] == '#') {
// System.out.println("hashtag");
return 0;
}
// System.out.println(h + " " + r + " " + c);
int val = 1;
mat[h][r][c] = '#';
for (int i = 0; i < 6; i++) {
val += dfs(mat, h + dh[i], r + dr[i], c + dc[i]);
}
return val;
}
private static boolean inBounds(char[][][] mat, int h, int r, int c) {
return h >= 0 && h < mat.length && r >= 0 && r < mat[h].length && c >= 0 && c < mat[h][r].length;
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 3dde3b01818916abc5b2ac5fc9524b22 | train_003.jsonl | 1298131200 | The Cereal Guy's friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn't washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped kβΓβnβΓβm, that is, it has k layers (the first layer is the upper one), each of which is a rectangle nβΓβm with empty squares ('.') and obstacles ('#'). The water can only be present in the empty squares. The tap is positioned above the square (x,βy) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1βΓβ1βΓβ1 cubes. | 256 megabytes | import java.util.*;
/**
* Created by kapilkrishnakumar on 9/11/15.
*/
public class CodeSerialTime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int n = sc.nextInt();
int m = sc.nextInt();
char[][][] plate = new char[k][n][m];
// System.out.println("height: "+k + " x: "+n + " y: "+m);
sc.nextLine();
sc.nextLine();
int numEmpty = 0;
for(int z = 0; z < k; z++){
for(int x = 0; x < n; x++){
String line = sc.nextLine();
for(int y = 0; y < m; y++){
// System.out.println("z: "+z + " x: "+x + " y: "+y);
plate[z][x][y] = line.charAt(y);
if(line.charAt(y) == '.') numEmpty++;
}
}
//blank line
sc.nextLine();
}
int tapX = sc.nextInt() - 1;
int tapY = sc.nextInt() - 1;
// printPlate(plate);
// System.out.println("tap: "+tapX+", "+tapY);
System.out.println(bfs(plate, tapX, tapY, numEmpty));
}
public static int bfs(char[][][] plate, int startX, int startY, int numEmpty){
boolean[][][] visited = new boolean[plate.length][plate[0].length][plate[0][0].length];
int[] currentPos = {0, startX, startY};
Queue<int[]> q = new LinkedList<int[]>();
q.add(currentPos);
visited[currentPos[0]][currentPos[1]][currentPos[2]] = true;
int numVisited = 1;
while(!q.isEmpty()){
int[] pos = q.poll();
int z = pos[0];
int x = pos[1];
int y = pos[2];
// System.out.println(Arrays.toString(pos));
// numEmpty--;
// if(numEmpty == 0)
// return timeCounter;
//add next to queue
int[] dz6 = {-1, 0, 1, 0, 0, 0};
int[] dx6 = {0, 1, 0, 0, 0, -1};
int[] dy6 = {0, 0, 0, 1, -1, 0};
for(int d = 0; d < dz6.length; d++){
int xdx = x + dx6[d];
int ydy = y + dy6[d];
int zdz = z + dz6[d];
if(0 <= zdz && zdz < visited.length && 0 <= xdx && xdx < visited[0].length &&
0 <= ydy && ydy < visited[0][0].length){
if(plate[zdz][xdx][ydy] == '.' && !visited[zdz][xdx][ydy]) {
int[] addPos = {zdz, xdx, ydy};
visited[zdz][xdx][ydy] = true;
numVisited++;
// System.out.println(numVisited);
q.add(addPos);
// System.out.println(Arrays.toString(addPos));
// System.out.println(visited[zdz][xdx][ydy]);
}
}
}
}
return numVisited;
}
// public static int[] addNext(int[] current, boolean[][][] visited){
// int[] dz6 = {-1, 0, 1, 0, 0, 0};
// int[] dx6 = {0, 1, 0, 0, 0, -1};
// int[] dy6 = {0, 0, 0, 1, -1, 0};
//
// int z = current[0];
// int x = current[1];
// int y = current[2];
//
// for(int d = 0; d < dz6.length; d++){
// for(int a = 0; a < dx6.length; a++){
// for(int b = 0; b < dy6.length; b++){
// int xdx = x + dx6[a];
// int ydy = y + dy6[b];
// int zdz = z + dz6[d];
// if(0 <= zdz && zdz <= visited.length && 0 <= xdx && xdx <= visited[0].length &&
// 0 <= ydy && ydy <= visited[0][0].length && !visited[zdz][xdx][ydy]){
// return new int[]{zdz, xdx, ydy};
// }
// }
// }
// }
// }
public static void printPlate(char[][][] plate){
for(int z = 0; z < plate.length; z++){
for(int x = 0; x < plate[0].length; x++){
for(int y = 0; y < plate[0][0].length; y++){
System.out.print(plate[z][x][y]+ " ");
}
System.out.println();
}
//blank line
System.out.println();
}
}
}
| Java | ["1 1 1\n\n.\n\n1 1", "2 1 1\n\n.\n\n#\n\n1 1", "2 2 2\n\n.#\n##\n\n..\n..\n\n1 1", "3 2 2\n\n#.\n##\n\n#.\n.#\n\n..\n..\n\n1 2", "3 3 3\n\n.#.\n###\n##.\n\n.##\n###\n##.\n\n...\n...\n...\n\n1 1"] | 2 seconds | ["1", "1", "5", "7", "13"] | null | Java 7 | standard input | [
"dsu",
"dfs and similar"
] | 3f6e5f6d9a35c6c9e71a7eeab4acf199 | The first line contains three numbers k, n, m (1ββ€βk,βn,βmββ€β10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters '.' or '#', which represents the "layers" of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1ββ€βxββ€βn,β1ββ€βyββ€βm) which are the tap's coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m. | 1,400 | The answer should contain a single number, showing in how many minutes the plate will be filled. | standard output | |
PASSED | 2313d66cbe41843fbb209cf5693e611a | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.BigDecimal;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader inp = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
solver.solve(inp, out);
out.close();
}
static class Solver {
class pair implements Comparable<pair>{
int i;
int cnt;
public pair(int i,int cnt)
{
this.i=i;
this.cnt=cnt;
}
public int compareTo(pair p)
{
return Long.compare(this.i,p.i);
}
}
class Node implements Comparable < Node > {
int i;
int cnt;
Node(int i, int cnt) {
this.i = i;
this.cnt = cnt;
}
public int compareTo(Node n) {
if (this.cnt == n.cnt) {
return Integer.compare(this.i, n.i);
}
return Integer.compare(this.cnt, n.cnt);
}
}
public boolean done(int[] sp, int[] par) {
int root;
root = findSet(sp[0], par);
for (int i = 1; i < sp.length; i++) {
if (root != findSet(sp[i], par))
return false;
}
return true;
}
public int findSet(int i, int[] par) {
int x = i;
boolean flag = false;
while (par[i] >= 0) {
flag = true;
i = par[i];
}
if (flag)
par[x] = i;
return i;
}
public void unionSet(int i, int j, int[] par) {
int x = findSet(i, par);
int y = findSet(j, par);
if (x < y) {
par[y] = x;
} else {
par[x] = y;
}
}
public long pow(long a, long b, long MOD) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2, MOD);
if (b % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * a % MOD) % MOD;
}
}
public boolean isPrime(int n)
{
for(int i=2;i<n;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}
public void minPrimeFactor(int n, int[] s) {
boolean prime[] = new boolean[n + 1];
Arrays.fill(prime, true);
s[1] = 1;
s[2] = 2;
for (int i = 4; i <= n; i += 2) {
prime[i] = false;
s[i] = 2;
}
for (int i = 3; i <= n; i += 2) {
if (prime[i]) {
s[i] = i;
for (int j = 2 * i; j <= n; j += i) {
prime[j] = false;
s[j] = i;
}
}
}
}
public void findAllPrime(int n, ArrayList < Node > al, int s[]) {
int curr = s[n];
int cnt = 1;
while (n > 1) {
n /= s[n];
if (curr == s[n]) {
cnt++;
continue;
}
Node n1 = new Node(curr, cnt);
al.add(n1);
curr = s[n];
cnt = 1;
}
}
public int binarySearch(int n, int k) {
int left = 1;
int right = 100000000 + 5;
int ans = 0;
while (left <= right) {
int mid = (left + right) / 2;
if (n / mid >= k) {
left = mid + 1;
ans = mid;
} else {
right = mid - 1;
}
}
return ans;
}
public boolean checkPallindrom(String s) {
char ch[] = s.toCharArray();
for (int i = 0; i < s.length() / 2; i++) {
if (ch[i] != ch[s.length() - 1 - i])
return false;
}
return true;
}
public boolean pallindrom(String s1, String s2)
{
char ch[] = s1.toCharArray();
char ch1[] = s2.toCharArray();
for(int i=0;i<s1.length();i++)
{
if(ch[i]!=ch1[s1.length()-1-i])
{
return false;
}
}
return true;
}
public void remove(ArrayList < Integer > [] al, int x) {
for (int i = 0; i < al.length; i++) {
for (int j = 0; j < al[i].size(); j++) {
if (al[i].get(j) == x)
al[i].remove(j);
}
}
}
public long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public void printDivisors(long n, ArrayList < Long > al) {
// Note that this loop runs till square root
for (long i = 1; i*i <= (n); i++) {
if (n % i == 0) {
// If divisors are equal, print only one
if (n / i == i) {
al.add(i);
} else // Otherwise print both
{
al.add(i);
al.add(n / i);
}
}
}
}
public static long constructSegment(long seg[], long arr[], int low, int high, int pos) {
if (low == high) {
seg[pos] = arr[low];
return seg[pos];
}
int mid = (low + high) / 2;
long t1 = constructSegment(seg, arr, low, mid, (2 * pos) + 1);
long t2 = constructSegment(seg, arr, mid + 1, high, (2 * pos) + 2);
seg[pos] = t1 + t2;
return seg[pos];
}
public static long querySegment(long seg[], int low, int high, int qlow, int qhigh, int pos) {
if (qlow <= low && qhigh >= high) {
return seg[pos];
} else if (qlow > high || qhigh < low) {
return 0;
} else {
long ans = 0;
int mid = (low + high) / 2;
ans += querySegment(seg, low, mid, qlow, qhigh, (2 * pos) + 1);
ans += querySegment(seg, mid + 1, high, qlow, qhigh, (2 * pos) + 2);
return ans;
}
}
public static int lcs(char[] X, char[] Y, int m, int n) {
if (m == 0 || n == 0)
return 0;
if (X[m - 1] == Y[n - 1])
return 1 + lcs(X, Y, m - 1, n - 1);
else
return Integer.max(lcs(X, Y, m, n - 1), lcs(X, Y, m - 1, n));
}
public static long recursion(long start, long end, long cnt[], int a, int b) {
long min = 0;
long count = 0;
int ans1 = -1;
int ans2 = -1;
int l = 0;
int r = cnt.length - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (cnt[mid] >= start) {
ans1 = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
l = 0;
r = cnt.length - 1;
while (l <= r) {
int mid = (l + r) / 2;
if (cnt[mid] <= end) {
ans2 = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
if (ans1 == -1 || ans2 == -1 || ans2 < ans1) {
// System.out.println("min1 "+min);
min = a;
return a;
} else {
min = b * (end - start + 1) * (ans2 - ans1 + 1);
}
if (start == end) {
// System.out.println("min "+min);
return min;
}
long mid = (end + start) / 2;
min = Long.min(min, recursion(start, mid, cnt, a, b) + recursion(mid + 1, end, cnt, a, b));
// System.out.println("min "+min);
return min;
}
public int lowerBound(ArrayList<Long> al,long ele)
{
int l =0;
int r =al.size()-1;
int ans=-1;
while(l<=r)
{
int mid = (l+r)/2;
if(al.get(mid)<=ele)
{
ans=mid;
l=mid+1;
}
else
{
r=mid-1;
}
}
return ans;
}
public int lowerBound(long arr[],long ele)
{
int l =0;
int r =arr.length-1;
int ans=-1;
while(l<=r)
{
int mid = (l+r)/2;
if(arr[mid]<=ele)
{
ans=mid;
l=mid+1;
}
else
{
r=mid-1;
}
}
return ans;
}
public long dfs_util(ArrayList < Integer > [] al, boolean vis[], int x ,long arr[],long val) {
vis[x] = true;
long temp=0;
for (int i = 0; i < al[x].size(); i++) {
if (!vis[al[x].get(i)]) {
temp+=dfs_util(al, vis, al[x].get(i),arr,val+1);
}
}
arr[x]=val-(temp);
return (temp+1);
}
public long[] dfs(ArrayList[] al) {
long arr[] = new long[al.length];
boolean vis[] = new boolean[al.length];
for (int i = 0; i < al.length; i++) {
if (!vis[i]) {
dfs_util(al, vis, i,arr,0);
}
}
return arr;
}
public void permute(String s,int l, int r,ArrayList<String> al)
{
if(l==r)
{
al.add(s);
}
for(int i=l;i<=r;i++)
{
String str=swap(s,l,i);
permute(str, l+1, r, al);
}
}
public String swap(String s, int l, int r)
{
char ch[] = s.toCharArray();
char tem = ch[l];
ch[l]=ch[r];
ch[r]=tem;
return String.valueOf(ch);
}
public int[] computeLps(String s)
{
int ans[] =new int[s.length()];
char ch[] = s.toCharArray();
int n = s.length();
int i=1;
int len=0;
ans[0]=0;
while(i<n)
{
if(ch[i]==ch[len])
{
len++;
ans[i]=len;
i++;
}
else
{
if(len!=0)
{
len=ans[len-1];
}
else
{
ans[i]=len;
i++;
}
}
}
return ans;
}
public int longestPrefixSuffix(String s)
{
int n = s.length();
if(n < 2) {
return 0;
}
int len = 0;
int i = n/2;
while(i < n) {
if(s.charAt(i) == s.charAt(len)) {
++len;
++i;
}
else
{
if(len == 0) {
++i;
}
else
{
--len;
}
}
}
return len;
}
public boolean convertFromBaseToBase(long num, int fromBase, int toBase,HashSet<Integer> hs) {
StringBuilder s=new StringBuilder();
boolean f=true;
int cnt=0;
while(num>0)
{
long tem = num%toBase;
if(tem==1)
{
if(hs.contains(cnt))
{
f=false;
break;
}
else
{
hs.add(cnt);
}
}
else if(tem==0)
{
}
else
{
f=false;
break;
}
num/=toBase;
cnt++;
}
return f;
}
private boolean possible(long arr[],long d,long k)
{
long tem=0;
for(int i=0;i<arr.length-1;i++)
{
tem+=(arr[i+1]-arr[i])/(d);
if((arr[i+1]-arr[i])%d==0)
tem--;
}
if(tem<=k)
{
return true;
}
else
return false;
}
public void bfsUtil(ArrayList<Integer> a[],int out[])
{
boolean vis[] = new boolean[a.length];
for(int i=0;i<a.length;i++)
{
if(!vis[i])
{
bipartie(a, vis,out,i);
}
}
}
public int[] bipartie(ArrayList<Integer> arr[],boolean vis[],int color[],int e)
{
Queue<Integer> q = new LinkedList<>();
color[e]=1;
q.add(e);
while(!q.isEmpty())
{
int x = q.remove();
if(vis[x])
{
continue;
}
vis[x]=true;
for(int i=0;i<arr[x].size();i++)
{
if(!vis[arr[x].get(i)])
{
}
else
{
if(color[arr[x].get(i)]==color[x])
{
color[x]=2;
}
}
}
for(int i=0;i<arr[x].size();i++)
{
if(!vis[arr[x].get(i)])
{
if(color[x]==2)
{
color[arr[x].get(i)]=0;
}
else
{
color[arr[x].get(i)]=1-color[x];
}
q.add(arr[x].get(i));
}
}
}
return color;
}
public int dfs1(ArrayList<Integer> al[],int x,boolean arr[],int val,boolean vis[],long ans[])
{
vis[x]=true;
if(arr[x])
{
ans[0]+=(long)val;
}
for (int i = 0; i < al[x].size(); i++) {
if (!vis[al[x].get(i)]) {
int temp = val;
if(!arr[x])
temp++;
dfs1(al, al[x].get(i),arr,temp,vis,ans);
}
}
return 0;
}
private void solve(InputReader inp, PrintWriter out1) {
int t = inp.nextInt();
for(int k=0;k<t;k++)
{
long a = inp.nextLong();
long b = inp.nextLong();
long q = inp.nextLong();
for(int i=0;i< q;i++)
{
long l = inp.nextLong();
long r = inp.nextLong();
long ans=r-l+1;
long lcm = (a*b)/gcd(a, b);
long cnt1 = (r/lcm);
if(cnt1>0)
{
ans-=((cnt1-1)*Math.max(a,b));
long temp = (r/lcm)*lcm;
ans-=Math.min(Math.max(a,b),r-temp+1);
}
long cnt2 = ((l-1)/lcm);
if(cnt2>0)
{
ans+=((cnt2-1)*Math.max(a,b));
long temp = ((l-1)/lcm)*lcm;
ans+=Math.min(Math.max(a,b),l-temp);
}
long x = Math.max(a, b)-1;
if(l<=x)
{
ans-=Math.min(x-l+1,r-l+1);
}
System.out.print(ans+" ");
}
System.out.println();
}
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
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());
}
}
}
class ele implements Comparable<ele>{
int i;
int dis;
boolean mark;
boolean leaf;
public ele(int i,int dis)
{
this.i=i;
this.dis=dis;
this.mark=false;
this.leaf=false;
}
@Override
public int compareTo(ele e)
{
if(this.dis==e.dis)
{
if(e.leaf==true)
return 1;
else if(this.leaf)
return -1;
else
return 0;
}
return -Integer.compare(this.dis,e.dis);
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 429865cb9b73a3f27b0a8a6ebea1dd9d | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
FastScanner fs = new FastScanner();
java.io.PrintWriter out = new java.io.PrintWriter(System.out);
solve(fs, out);
out.flush();
//if (fs.hasNext()) throw new AssertionError("read input");
}
public void solve(FastScanner fs, java.io.PrintWriter out) {
int t = fs.nextInt();
while(t --> 0) {
int a = fs.nextInt(), b = fs.nextInt(), q = fs.nextInt();
final int[] sum = new int[a * b + 1];
for (int i = 0;i < a * b;++ i) sum[i + 1] = sum[i] + (i % a % b == i % b % a ? 0 : 1);
while (q --> 0) {
long l = fs.nextLong(), r = fs.nextLong() + 1;
LongUnaryOperator func = i -> sum[sum.length - 1] * (i / (a * b)) + sum[(int)(i % (a * b))];
out.print(func.applyAsLong(r) - func.applyAsLong(l));
if (q > 0) out.print(" ");
}
out.println();
}
}
static class FastScanner {
private final java.io.InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) return true;
ptr = 0;
try {
buflen = in.read(buffer);
} catch (java.io.IOException e) {
e.printStackTrace();
}
return buflen > 0;
}
private byte readByte() {
return hasNextByte() ? buffer[ptr++ ] : -1;
}
private static boolean isPrintableChar(byte c) {
return 32 < c || c < 0;
}
private static boolean isNumber(int c) {
return '0' <= c && c <= '9';
}
public boolean hasNext() {
while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++ ;
return hasNextByte();
}
public String next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
StringBuilder sb = new StringBuilder();
byte b;
while (isPrintableChar(b = readByte())) sb.appendCodePoint(b);
return sb.toString();
}
public final long nextLong() {
if (!hasNext()) throw new java.util.NoSuchElementException();
long n = 0;
try {
byte b = readByte();
if (b == '-') {
while(isNumber(b = readByte())) n = n * 10 + '0' - b;
return n;
} else if (!isNumber(b)) throw new NumberFormatException();
do n = n * 10 + b - '0'; while (isNumber(b = readByte()));
} catch (java.util.NoSuchElementException e) {
}
return n;
}
public final int nextInt() {
if (!hasNext()) throw new java.util.NoSuchElementException();
int n = 0;
try {
byte b = readByte();
if (b == '-') {
while(isNumber(b = readByte())) n = n * 10 + '0' - b;
return n;
} else if (!isNumber(b)) throw new NumberFormatException();
do n = n * 10 + b - '0'; while (isNumber(b = readByte()));
} catch (java.util.NoSuchElementException e) {
}
return n;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
public static class Arrays {
public static void sort(final int[] array) {
int l, min = 0xFFFFFFFF, max = 0;
for (l = 0;l < array.length;++ l) {
int i = array[l];
min &= i;
max |= i;
if ((i & 0x80000000) == 0) break;
}
for (int r = l + 1;r < array.length;++ r) {
int i = array[r];
min &= i;
max |= i;
if ((i & 0x80000000) != 0) {
array[r] = array[l];
array[l ++] = i;
}
}
int use = min ^ max, bit = Integer.highestOneBit(use & 0x7FFFFFFF);
if (bit == 0) return;
sort(array, 0, l, use, bit);
sort(array, l, array.length, use, bit);
}
private static void sort(final int[] array, final int left, final int right, final int use, int digit) {
if (right - left <= 96) {
for (int i = left + 1;i < right;++ i) {
int tmp = array[i], tmp2, j;
for (j = i;j > left && (tmp2 = array[j - 1]) > tmp;-- j) array[j] = tmp2;
array[j] = tmp;
}
return;
}
int l = left;
while(l < right && (array[l] & digit) == 0) ++ l;
for (int r = l + 1;r < right;++ r) {
int i = array[r];
if ((i & digit) == 0) {
array[r] = array[l];
array[l ++] = i;
}
}
if ((digit = Integer.highestOneBit(use & digit - 1)) == 0) return;
sort(array, left, l, use, digit);
sort(array, l, right, use, digit);
}
public static void sort(final long[] array) {
int l;
long min = 0xFFFFFFFFFFFFFFFFL, max = 0;
for (l = 0;l < array.length;++ l) {
long i = array[l];
min &= i;
max |= i;
if ((i & 0x8000000000000000L) == 0) break;
}
for (int r = l + 1;r < array.length;++ r) {
long i = array[r];
min &= i;
max |= i;
if ((i & 0x8000000000000000L) != 0) {
array[r] = array[l];
array[l ++] = i;
}
}
long use = min ^ max, bit = Long.highestOneBit(use & 0x7FFFFFFFFFFFFFFFL);
if (bit == 0) return;
sort(array, 0, l, use, bit);
sort(array, l, array.length, use, bit);
}
private static void sort(final long[] array, final int left, final int right, final long use, long digit) {
if (right - left <= 96) {
for (int i = left + 1, j;i < right;++ i) {
long tmp = array[i], tmp2;
for (j = i;j > left && (tmp2 = array[j - 1]) > tmp;-- j) array[j] = tmp2;
array[j] = tmp;
}
return;
}
int l = left;
while(l < right && (array[l] & digit) == 0) ++ l;
for (int r = l + 1;r < right;++ r) {
long i = array[r];
if ((i & digit) == 0) {
array[r] = array[l];
array[l ++] = i;
}
}
if ((digit = Long.highestOneBit(use & digit - 1)) == 0) return;
sort(array, left, l, use, digit);
sort(array, l, right, use, digit);
}
}
public static class IntMath {
public static int gcd(int a, int b) {
while (a != 0) if ((b %= a) != 0) a %= b; else return a;
return b;
}
public static int gcd(int... array) {
int ret = array[0];
for (int i = 1;i < array.length;++ i) ret = gcd(ret, array[i]);
return ret;
}
public static long gcd(long a, long b) {
while (a != 0) if ((b %= a) != 0) a %= b; else return a;
return b;
}
public static long gcd(long... array) {
long ret = array[0];
for (int i = 1;i < array.length;++ i) ret = gcd(ret, array[i]);
return ret;
}
public static long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
public static int pow(int a, int b) {
int ans = 1;
for (int mul = a;b > 0;b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul;
return ans;
}
public static int pow(int a, int b, int mod) {
if (b < 0) b = b % (mod - 1) + mod - 1;
long ans = 1;
for (long mul = a;b > 0;b >>= 1, mul = mul * mul % mod) if ((b & 1) != 0) ans = ans * mul % mod;
return (int)ans;
}
public static int floorsqrt(long n) {
return (int)Math.sqrt(n + 0.1);
}
public static int ceilsqrt(long n) {
return n <= 1 ? (int)n : (int)Math.sqrt(n - 0.1) + 1;
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | d23a5684d7358e44c2a51e9676e28711 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf1342_Div2_C {
public static long findCount(long r, long lcm, long b) {
long div = r / lcm;
long pro = div * lcm;
long tot = r;
if (div != 0) {
tot -= Math.min(b, r - pro + 1);
tot -= b * (div - 1);
}
return tot - Math.min(r, b - 1);
}
public static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
public static void main(String[] args) throws IOException {
FastScanner in = new FastScanner();
int t = in.nextInt();
for ( ; t > 0; --t) {
long a = in.nextLong();
long b = in.nextLong();
long q = in.nextLong();
if (a > b) {
long temp = a;
a = b;
b = temp;
}
long lcm = lcm(a, b);
for ( ; q > 0; q--) {
long l = in.nextLong();
long r = in.nextLong();
if (lcm == b || r < b) { System.out.print(0 + " "); continue;}
long cnt = findCount(r, lcm, b);
if (l > 1) cnt -= findCount(l - 1, lcm, b);
System.out.print(cnt + " ");
}
System.out.println();
}
}
public static void shuffle(int[] arr) {
Random rgen = new Random();
for (int i = 0; i < arr.length; i++) {
int rPos = rgen.nextInt(arr.length);
int temp = arr[i];
arr[i] = arr[rPos];
arr[rPos]=temp;
}
}
public static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
st = null;
try {
return br.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 6972dd4059c95a69ff144cd854105dbb | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class C {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(bf.readLine());
StringTokenizer st;
long a, b, q, li, ri;
for (int i = 0; i < t; i++) {
st = new StringTokenizer(bf.readLine());
a = Long.parseLong(st.nextToken());
b = Long.parseLong(st.nextToken());
if (a > b) {
long tmp = a;
a = b;
b = tmp;
} // a is smaller
q = Long.parseLong(st.nextToken());
long l = lcm(a, b);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < q; j++) {
st = new StringTokenizer(bf.readLine());
li = Long.parseLong(st.nextToken());
ri = Long.parseLong(st.nextToken());
long cutL = (li / l);
long cutR = (ri / l);
long equalTo = (cutR - cutL) * b;
equalTo -= min(li - cutL * l, b);
equalTo += min(ri - cutR * l + 1, b);
sb.append(ri - li + 1 - equalTo);
if (j != q - 1) {
sb.append(' ');
}
}
out.println(sb.toString());
}
out.close();
System.exit(0);
}
public static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
public static long gcd(long a, long b) {
long t;
while (a > 0) {
t = b % a;
b = a;
a = t;
}
return b;
}
public static long min(long a, long b) {
return a < b ? a : b;
}
public static long max(long a, long b) {
return a > b ? a : b;
}
public static long abs(long a) {
return a > 0 ? a : -a;
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | f85d1d178d9a9ed72d1af8f309ea57c9 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
// https://codeforces.com/problemset/problem/1342/C
// creating flag array , 1 where condition satisfies
// length = 40000 bcz 1<=a,b <=200
public static int[] flag = new int[40005];
public static int a;
public static int b;
public static void create_flag(){
flag[0] = 0;
//1->ab-1...ab->2ab-1
//accumulative sum array
for(int i = 1;i<a*b;i++){
if((i%a)%b != (i%b)%a){
flag[i] = flag[i-1]+1;
}
else{
flag[i] = flag[i-1];
}
}
}
public static long countNoOfX(long n){
if(n < a*b){
return flag[(int)n];
}
long count = (n/(a*b))*flag[a*b-1];
count += flag[(int)(n%(a*b))];
return count;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
a = sc.nextInt();
b = sc.nextInt();
int q = sc.nextInt();
// (x % a) % b = ((ab+x) % a) % b => x%a = (ab+x)%a
// (x % b) % a = ((ab+x) % b) % a
// values repeat after ab
// create flag array till ab
create_flag();
while (q-- > 0) {
long l = sc.nextLong();
long r = sc.nextLong();
System.out.print(countNoOfX(r)-countNoOfX(l-1)+" ");
}
System.out.println();
Arrays.fill(flag,0);
}
sc.close();
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 31b645f6e190240a108c98980fc6afb1 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
static PrintWriter out = new PrintWriter(System.out);
static Reader in = new Reader();
public static void main(String[] args) throws IOException {
//Scanner sc = new Scanner();
Main solver = new Main();
solver.solve();
out.flush();
out.close();
}
static int INF = (int)1e9;
static int maxn = 5*(int)1e4+5;
static int mod = 998244353;
static int n,m,q,k,t;
static int[] arr;
void solve() throws IOException{
t = in.nextInt();
arr = new int[maxn];
while (t-->0) {
int a = in.nextInt(), b = in.nextInt(), q = in.nextInt();
int lcm = (a*b)/gcd(a,b);
for (int i = 1; i <= lcm ; i++) {
arr[i] = 0;
if (((i%a)%b) != ((i%b)%a)) arr[i]++;
arr[i] += arr[i-1];
}
long l=0 , r=0;
long res = 0;
for (int i = 0; i < q; i++) {
l = in.nextLong();
r = in.nextLong();
res = find(r, lcm)- find(l-1, lcm);
out.print(res+" ");
}
out.println();
}
}
//<>
static long find(long x, int lcm) {
if (x == 0) return 0;
if (x <= lcm) return arr[(int)x];
else {
long div = x/lcm;
long rest = x%lcm;
return arr[lcm]*div+arr[(int)rest];
}
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
if (b == 0)
return a;
if (a == b)
return a;
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
static class Reader {
private InputStream mIs;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public Reader() {
this(System.in);
}
public Reader(InputStream is) {
mIs = is;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = mIs.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
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 String next() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
double nextDouble()
{
return Double.parseDouble(next());
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | bd0fc4df9ce4da0a16a5cae40387e6c6 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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;
MyScanner in = new MyScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class TaskC {
public void solve(int testNumber, MyScanner in, PrintWriter out) {
int a, b, q;
a = in.nextInt();
b = in.nextInt();
q = in.nextInt();
for (int i = 0; i < q; i++) {
long l, r;
l = in.nextLong();
r = in.nextLong();
long ans = cnt(a, b, r) - cnt(a, b, l - 1);
out.print(ans + " ");
}
out.println();
}
private long cnt(int a, int b, long l) {
long mn = Math.min(a, b);
long mx = Math.max(a, b);
long nok = mn * mx / gcd(a, b);
long ans = ((l + 1) / nok) * mx;
if ((l + 1) % nok != 0) {
ans += Math.min(mx, (l + 1) % nok);
}
return (l + 1) - ans;
}
private long gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
}
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner(InputStream io) {
br = new BufferedReader(new InputStreamReader(io));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 8ccd85759ea3f3f7d0704b7f8029cba9 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.Objects;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
try (FastReader reader = new FastReader(); PrintWriter writer = new PrintWriter(System.out)) {
int tc = reader.nextInt();
while (tc-- > 0) {
int a = reader.nextInt();
int b = reader.nextInt();
int q = reader.nextInt();
solve(reader, writer, a, b, q);
writer.write("\n");
}
}
}
public static void solve(FastReader reader, PrintWriter writer, int a, int b, int q) {
int prod = a * b;
int[] freq = new int[prod];
for (int i = 1; i < prod; i++) {
freq[i] = freq[i - 1];
if (i % a % b != i % b % a) {
freq[i]++;
}
}
while (q-- > 0) {
long l = Long.parseLong(reader.nextToken()) - 1;
long r = Long.parseLong(reader.nextToken());
long toRightCount = r / prod * freq[prod - 1] + freq[Math.toIntExact(r % prod)];
long toLeftCount = l / prod * freq[prod - 1] + freq[Math.toIntExact(l % prod)];
writer.write((toRightCount - toLeftCount) + " ");
}
}
static class FastReader implements AutoCloseable {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public FastReader() {
this(System.in);
}
public FastReader(InputStream inputStream) {
this.reader = new BufferedReader(new InputStreamReader(inputStream));
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
private String nextToken() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
String line = nextLine();
Objects.requireNonNull(line);
tokenizer = new StringTokenizer(line);
}
return tokenizer.nextToken();
}
public long nextLong() {
String next = nextToken();
Objects.requireNonNull(next);
return Long.parseLong(next);
}
public int nextInt() {
String next = nextToken();
Objects.requireNonNull(next);
return Integer.parseInt(next);
}
@Override
public void close() {
try {
reader.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 789ad1ede39827bcaf27fc5e5107089a | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes |
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
/**
* Name: YetAnotherCountingProblem
* URL: https://codeforces.com/contest/1342/problem/C
* rating:
*/
public class YetAnotherCountingProblem {
static PrintWriter pw = new PrintWriter(System.out);
public static void solution() {
FastReader reader = new FastReader(System.in);
long[] cache = new long[40005];
int numTests = reader.nextInt(); // reads integer
for (int i = 0; i < numTests; i++) {
int a = reader.nextInt();
int b = reader.nextInt();
int q = reader.nextInt();
int lcm = lcm(a, b);
for (int lcmi = 0; lcmi < lcm; lcmi++) {
if (lcmi%a%b != lcmi%b%a) {
cache[lcmi] = 1;
} else
cache[lcmi] = 0;
}
for (int lcmi = 1; lcmi < lcm; lcmi++) {
cache[lcmi] += cache[lcmi - 1];
}
for (int s = 0; s < q; s++) {
long l = reader.nextLong();
long r = reader.nextLong();
pw.print((calc(cache, r, lcm) - calc(cache, l - 1, lcm)) + " ");
}
pw.println();
}
pw.close();
}
// amount of integer from 0 -> n
public static long calc(long[] cache, long m, int lcm) {
int mModLCM = (int)(m%lcm);
return m/lcm * cache[lcm - 1] + cache[mModLCM];
}
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
// Function to return LCM of two numbers
public static int lcm(int a, int b) {
return (a*b)/gcd(a, b);
}
public static void main(String[] args) {
//System.out.println(lcm(45, 172));
solution();
}
static class FastReader {
InputStream is;
private byte[] inbuf = new byte[1024];
private int lenbuf = 0, ptrbuf = 0;
public FastReader(InputStream is) {
this.is = is;
}
public int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {
lenbuf = is.read(inbuf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return -1;
}
return inbuf[ptrbuf++];
}
public boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
public int skip() {
int b;
while ((b = readByte()) != -1 && isSpaceChar(b)) ;
return b;
}
public String next() {
int b = skip();
StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public String nextLine() {
int b = readByte();
StringBuilder sb = new StringBuilder();
while (b != '\n' || b != '\r') {
sb.appendCodePoint(b);
}
return sb.toString();
}
public int nextInt() {
int num = 0, b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = (num << 3) + (num << 1) + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public long nextLong() {
long num = 0;
int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
if (b == '-') {
minus = true;
b = readByte();
}
while (true) {
if (b >= '0' && b <= '9') {
num = (num << 3) + (num << 1) + (b - '0');
} else {
return minus ? -num : num;
}
b = readByte();
}
}
public double nextDouble() {
return Double.parseDouble(next());
}
public char[] next(int n) {
char[] buf = new char[n];
int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) {
buf[p++] = (char) b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
public char nextChar() {
return (char) skip();
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 5dc0acd9e2fd6673275b05fc70fd9acb | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Objects;
import java.util.Random;
import java.util.StringTokenizer;
public class Solution{
public static void main(String[] args) throws Exception{
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int tt = fs.nextInt();
while(tt-->0) {
int a = fs.nextInt(), b = fs.nextInt(), q = fs.nextInt();
if(b<a) {
int temp = a;
a = b;
b = temp;
}
int lcm = a*b/gcd(a,b);
while(q-->0) {
long l = fs.nextLong(), r = fs.nextLong();
if(a==b) {
out.println(0);
continue;
}
out.print((r-l+1)-(fun(r,lcm,b)-fun(l-1,lcm,b)));
out.print(" ");
}
out.println("");
}
out.close();
}
static long fun(long n, int lcm , int b) {
long count = (n/lcm)*b + b;
long num = (n/lcm)*lcm;
count += Math.min(0, (n-num+1)-b);
return count;
}
static int gcd(int a, int b) {
return (a==0)?b:gcd(b%a,a);
}
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class FastScanner{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next(){
while(!st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
} catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt(){
return Integer.parseInt(next());
}
public int[] readArray(int n){
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = nextInt();
return a;
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 07675e9a002b0424d5e1c7fbc69ba61d | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class YetAnotherCountingProblem {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(br.readLine());
while (--t >= 0) {
String[] line = br.readLine().split(" ");
int a = Integer.parseInt(line[0]), b = Integer.parseInt(line[1]), q = Integer.parseInt(line[2]);
int lcm = a * b / gcd(a, b);
int max = Math.max(a, b);
while (--q >= 0) {
line = br.readLine().split(" ");
long l = Long.parseLong(line[0]), r = Long.parseLong(line[1]);
if (a % b != 0 && b % a != 0) {
long equalL = ((l - 1) / lcm + 1) * max;
long aboveL = l - (l - 1) / lcm * lcm;
if (aboveL < max) {
equalL -= max - aboveL;
}
long equalR = (r / lcm + 1) * max;
long aboveR = 1 + r - r / lcm * lcm;
if (aboveR < max) {
equalR -= max - aboveR;
}
long equal = equalR - equalL;
bw.write(Long.toString(1 + r - l - equal));
} else {
bw.write('0');
}
// long res = 0;
// for (long x = l; x <= r; ++x) {
// if (x % a % b != x % b % a) {
// ++res;
// } else {
// System.out.println(x);
// }
// }
// bw.write(Long.toString(res));
bw.write(' ');
}
bw.newLine();
}
br.close();
bw.close();
}
private static int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 3891c30e6b57482ec578e3ebc8ee72b9 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class c {
public static void main(String[] args) throws IOException {
FastScanner stdin = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = stdin.nextInt();
for (int z = 0; z < t; z ++)
{
long a = stdin.nextInt();
long b = stdin.nextInt();
int q = stdin.nextInt();
long[] before = new long[(int)(a*b)];
for (int i = 1; i < a*b; i ++)
{
before[i] = before[i-1];
if ((i%a)%b==(i%b)%a) before[i] ++;
}
long[] cyc = new long[(int)(a*b)];
cyc[0] = 1;
for (long i = a*b+1; i < 2*a*b; i ++)
{
if (i%a%b==i%b%a) cyc[(int)(i-a*b)] = cyc[(int)(i-a*b)-1] +1;
else cyc[(int)(i-a*b)] = cyc[(int)(i-a*b)-1];
}
for (int i = 0; i < q; i ++)
{
long l = stdin.nextLong();
long r = stdin.nextLong();
long ogl = l;
if (a==b)
{
System.out.print(0 + " ");
continue;
}
if (r < a*b)
{
System.out.print((r-l+1-before[(int)r]+before[(int)l-1]) + " ");
continue;
}
long add = 0;
if (l < a*b)
{
add = before[(int)(a*b-1)] - before[(int)l-1];
l = a*b;
}
long ans = 0;
long hi = r/(a*b) * cyc[(int)(a*b-1)];
hi += cyc[(int)(r%(a*b))];
long lo = (l-1)/(a*b) * cyc[(int)(a*b-1)];
lo += cyc[(int)((l-1)%(a*b))];
ans = hi-lo+add;
System.out.print((r-ogl+1-ans) + " ");
}
System.out.println();
}
out.flush();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream i) {
br = new BufferedReader(new InputStreamReader(i));
st = new StringTokenizer("");
}
public String next() throws IOException {
if(st.hasMoreTokens())
return st.nextToken();
else
st = new StringTokenizer(br.readLine());
return next();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | fd30a77878d3978d76c8b590a2583eff | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Solve8 {
public static void main(String[] args) throws IOException {
PrintWriter pw = new PrintWriter(System.out);
new Solve8().solve(pw);
pw.flush();
pw.close();
}
public void solve(PrintWriter pw) throws IOException {
FastReader sc = new FastReader();
int t = sc.nextInt();
while (t-- > 0) {
int a = sc.nextInt(), b = sc.nextInt(), q = sc.nextInt();
long lcm = lcm(a, b), max = Math.max(a, b);
for (int i = 0; i < q; i++) {
long l = sc.nextLong(), r = sc.nextLong();
long s = max * (r / lcm - (l - 1) / lcm);
long x = (l - 1) / lcm * lcm;
s += Math.max(0, Math.min(r + 1, x + max) - l);
x = r / lcm * lcm;
s -= x >= l ? Math.max(0, (x + max - r - 1)) : 0;
s = (r - l + 1) - s;
pw.print(s + (i + 1 == q ? "\n" : " "));
}
}
}
public long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
public long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
}
}
public String next() {
if (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception 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());
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
}
return null;
}
public boolean hasNext() throws IOException {
if (st != null && st.hasMoreTokens()) {
return true;
}
String s = br.readLine();
if (s == null || s.isEmpty()) {
return false;
}
st = new StringTokenizer(s);
return true;
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 3ca92c71d98e168dff335d281bebd80e | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class C_YetAnotherCountingProblem {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int __ = 0; __ < T; __++) {
final int a = sc.nextInt();
final int b = sc.nextInt();
final int q = sc.nextInt();
final int period = a * b;
final int[] ab = new int[period];
int sum = 0;
for (int i = 0; i < period; i++)
{
if ((i % a) % b != (i % b) % a)
{
sum++;
}
ab[i] = sum;
}
// now sum is the total number during one period.
for (int i = 0; i < q; i++) {
long l = sc.nextLong();
long r = sc.nextLong();
System.out.println(r / period * sum + ab[(int) ((r % period))]
- (l - 1) / period * sum - ab[(int) (((l - 1) % period))]
);
}
}
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | d9ed8d95539c8e0588f4b0e11415cec6 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes |
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
static long f(long r,long lcm,long lt){
long n=r/lcm;
long cnt=lt*n,st=lcm*n;
for(int i=1;i<lt;i++){
if(st+i*1l>r)
break;
cnt++;
}
return cnt;
}
public static void process()throws IOException
{
int a=ni(),b=ni(),q=ni();
long lcm=(a*b)/gcd(a,b),lt=Math.max(a, b);
while(q-- >0){
long l=nl(),r=nl(),cnt1=0,cnt2=0,tot=r-l+1;
cnt1=f(l-1,lcm,lt);
cnt2=f(r,lcm,lt);
cnt2-=cnt1;
p(tot-cnt2);p(" ");
}
pn("");
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
out = new PrintWriter(System.out);
sc=new AnotherReader();
boolean oj = true;
oj = System.getProperty("ONLINE_JUDGE") != null;
if(!oj) sc=new AnotherReader(100);
long s = System.currentTimeMillis();
int t=1;
t=ni();
while(t-->0)
process();
out.flush();
if(!oj)
System.out.println(System.currentTimeMillis()-s+"ms");
System.out.close();
}
static void pn(Object o){out.println(o);}
static void p(Object o){out.print(o);}
static void pni(Object o){out.println(o);System.out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
static boolean multipleTC=false;
static long mod=(long)1e9+7l;
static void r_sort(int arr[],int n){
Random r = new Random();
for (int i = n-1; i > 0; i--){
int j = r.nextInt(i+1);
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
Arrays.sort(arr);
}
static long mpow(long x, long n) {
if(n == 0)
return 1;
if(n % 2 == 0) {
long root = mpow(x, n / 2);
return root * root % mod;
}else {
return x * mpow(x, n - 1) % mod;
}
}
static long mcomb(long a, long b) {
if(b > a - b)
return mcomb(a, a - b);
long m = 1;
long d = 1;
long i;
for(i = 0; i < b; i++) {
m *= (a - i);
m %= mod;
d *= (i + 1);
d %= mod;
}
long ans = m * mpow(d, mod - 2) % mod;
return ans;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 21649d3285b75896ee72454594e2ff34 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Cf131 implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
public int nextInt()
{
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
int res = 0;
do
{
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.')
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception
{
new Thread(null, new Cf131(),"Main",1<<27).start();
}
static class Pair{
int nod;
int ucn;
int siz;
Pair(int nod,int ucn,int siz){
this.nod=nod;
this.ucn=ucn;
this.siz = siz;
}
public static Comparator<Pair> wc = new Comparator<Pair>(){
public int compare(Pair e1,Pair e2){
int c1 = e1.ucn - e1.siz;
int c2 = e2.ucn - e2.siz;
//reverse order
if (c1 < c2)
return 1; // 1 for swaping.
else if (c1 > c2)
return -1;
else{
if(e1.siz>e2.siz)
return 1;
else
return -1;
}
}
};
}
public static long gcd(long a,long b){
if(b==0)return a;
else return gcd(b,a%b);
}
//// iterative BFS
public static void bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){
b[s]=true;
Queue<Integer> q = new LinkedList<>();
q.add(s);
while(q.size()!=0){
int i=q.poll();
// w.println(" #"+i+"# ");
Iterator<Integer> it =a[i].listIterator();
int z=0;
while(it.hasNext()){
z=it.next();
if(!b[z]){
// w.println("* "+z+" *");
b[z]=true;
dist[z] = dist[i]+1;
// x.add(z);
// w.println("@ "+x.get(x.size()-1)+" @");
q.add(z);
}
}
}
}
////recursive BFS
public static int bfsr(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,int[] pre){
b[s]=true;
int p = 0;
int t = a[s].size();
for(int i=0;i<t;i++){
int x = a[s].get(i);
if(!b[x]){
dist[x] = dist[s] + 1;
p+= (bfsr(x,a,dist,b,pre)+1);
}
}
pre[s] = p;
return p;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int t= sc.nextInt();
while(t-->0){
long aa = sc.nextLong();
long bb = sc.nextLong();
long q = sc.nextLong();
long a = Math.min(aa,bb);
long b = Math.max(aa,bb);
long x = ((a*b)/gcd(a,b));
for(int i=0;i<q;i++){
long l = sc.nextLong();
long r = sc.nextLong();
// long minus = Math.min( (l - (((l/x)*x)+b)), 0);
// long plus = Math.min( (r - (((r/x)*x)+b-1)), 0);
// long ans = ((r/x)-(l/x))*b;
// // w.println("* = "+minus+" "+plus+" "+ans);
// ans = Math.max(((r-l+1) - ans + plus + minus), 0) ;
long left = l>=(((l/x)*x)+b)?0:( (((l/x)*x)+b)-l );
long right = r>=(((r/x)*x)+b-1)?0:( (((r/x)*x)+b-1)-r );
long ans = (r-l+1) - ((r/x - l/x)*b) - left + right;
w.print(ans+" ");
}
w.println();
}
// w.println("no. LHS RHS");
// for(int i=1;i<200;i++)
// //if(((i%7)%15)==((i%15)%7))
// w.println(i+" = "+((i%7)%15)+" "+((i%15)%7));
w.flush();
w.close();
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 8750b63e3d5b73c2d904009eba11dd15 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class CF1342C extends PrintWriter {
CF1342C() { super(System.out); }
Scanner sc = new Scanner(System.in);
public static void main(String[] $) {
CF1342C o = new CF1342C(); o.main(); o.flush();
}
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
void main() {
int t = sc.nextInt();
while (t-- > 0) {
int a = sc.nextInt();
int b = sc.nextInt();
int q = sc.nextInt();
int m = a / gcd(a, b) * b;
int[] kk = new int[m + 1];
for (int r = 0; r < m; r++)
if (r % a % b != r % b % a)
kk[r + 1]++;
for (int cnt = 1; cnt <= m; cnt++)
kk[cnt] += kk[cnt - 1];
while (q-- > 0) {
long l = sc.nextLong();
long r = sc.nextLong() + 1;
int l_ = (int) (l % m);
int r_ = (int) (r % m);
long kl = l / m * kk[m] + kk[l_];
long kr = r / m * kk[m] + kk[r_];
print(kr - kl + " ");
}
println();
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | dbd6b6ce2935aaf8c757d1bcaa2678d9 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
static long [][] memo;
static long [] pow = new long[33];
static ArrayList <Integer> [] graph;
static Integer [] d;
static int [] dist;
static boolean[][] visited;
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
// Start writing your solution here. -------------------------------------
long MOD = 1000000007;
int mod = 2019;
int t = sc.nextInt();
//int t = 1;
while(t -- > 0)
{
int a = sc.nextInt(), b = sc.nextInt();
int q = sc.nextInt();
int GCD = gcd(a, b), LCP = a * b / GCD;
long res[] = new long[LCP];
for(int i = 1; i < LCP; i++)
{
res[i] = res[i - 1];
int r1 = (i % a) % b, r2 = (i % b) % a;
if(r1 != r2) res[i]++;
}
//System.out.println(Arrays.toString(res));
for(int i = 0; i < q; i++)
{
long l = sc.nextLong(), r = sc.nextLong();
long ans = solve(r, res) - solve(l - 1, res);
out.print(ans + " ");
}
out.println("");
}
out.close();
}
public static int gcd(int a, int b)
{
if(a % b == 0) return b;
return gcd(b, a % b);
}
public static long solve(long x, long[] res){
int n = res.length;
long a = x / n;
int b = (int)(x % n);
return res[n - 1] * a + res[b];
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------MyScanner class for faster input----------
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 067902edbe72a7cc2dc2b4b098af228a | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
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);
Unstoppable solver = new Unstoppable();
int t=in.nextInt();
while(t-->0)
solver.solve(in, out);
out.close();
}
static class Unstoppable {
static int gcd(int a,int b){
if(b==0) return a;
else return gcd(b,a%b);
}
public void solve(InputReader sc, PrintWriter out) {
int a = sc.nextInt();
int b = sc.nextInt();
int q = sc.nextInt();
int m = a / gcd(a, b) * b;
int[] kk = new int[m + 1];
for (int r = 0; r < m; r++)
if (r % a % b != r % b % a)
kk[r + 1]++;
for (int cnt = 1; cnt <= m; cnt++)
kk[cnt] += kk[cnt - 1];
while (q-- > 0) {
long l = sc.nextLong();
long r = sc.nextLong() + 1;
int l_ = (int) (l % m);
int r_ = (int) (r % m);
long kl = l / m * kk[m] + kk[l_];
long kr = r / m * kk[m] + kk[r_];
out.print(kr - kl + " ");
}
out.println("");
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public long nextLong(){
return Long.parseLong(next());
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 778cca9e784017a25188a67041049a47 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main{
static long lcm(long a,long b) {
return (a/gcd(a,b))*b;
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main(String[] args) throws Exception{
PrintWriter pw=new PrintWriter(System.out);
MScanner sc = new MScanner(System.in);
int tc=sc.nextInt();
while(tc-->0) {
int a=sc.nextInt(),b=sc.nextInt(),q=sc.nextInt();
int lcm=(int)lcm(a, b);
boolean[]yes=new boolean[lcm];
long cnt=0;
long[]prefCnt=new long[lcm];
for(int i=0;i<lcm;i++) {
if((i%a)%b!=(i%b)%a) {
yes[i]=true;
cnt++;
}
prefCnt[i]=cnt;
}
// System.out.println(arrToString(prefCnt));
while(q-->0) {
long l=sc.nextLong()-1,r=sc.nextLong();
long ans=(r/lcm)*cnt+prefCnt[(int)(r%lcm)];
ans-=((l/lcm)*cnt+prefCnt[(int)(l%lcm)]);
pw.print(ans+" ");
}
pw.println();
}
pw.flush();
}
static class MScanner {
StringTokenizer st;
BufferedReader br;
public MScanner(InputStream system) {
br = new BufferedReader(new InputStreamReader(system));
}
public MScanner(String file) throws Exception {
br = new BufferedReader(new FileReader(file));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int[] intArr(int n) throws IOException {
int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
return in;
}
public long[] longArr(int n) throws IOException {
long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
return in;
}
public int[] intSortedArr(int n) throws IOException {
int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
shuffle(in);
Arrays.sort(in);
return in;
}
public long[] longSortedArr(int n) throws IOException {
long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
shuffle(in);
Arrays.sort(in);
return in;
}
public Integer[] IntegerArr(int n) throws IOException {
Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
return in;
}
public Long[] LongArr(int n) throws IOException {
Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
return in;
}
public String nextLine() throws IOException {
return br.readLine();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public char nextChar() throws IOException {
return next().charAt(0);
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public boolean ready() throws IOException {
return br.ready();
}
public void waitForInput() throws InterruptedException {
Thread.sleep(3000);
}
}
static void shuffle(int[]in) {
for(int i=0;i<in.length;i++) {
int idx=(int)(Math.random()*in.length);
int tmp=in[i];
in[i]=in[idx];
in[idx]=tmp;
}
}
static void shuffle(long[]in) {
for(int i=0;i<in.length;i++) {
int idx=(int)(Math.random()*in.length);
long tmp=in[i];
in[i]=in[idx];
in[idx]=tmp;
}
}
static String arrToString(int[]x) {
return Arrays.toString(x);
}
static String arrToString(long[]x) {
return Arrays.toString(x);
}
static String arrToString(Integer[]x) {
return Arrays.toString(x);
}
static String arrToString(Long[]x) {
return Arrays.toString(x);
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 90efd4ae18e77b73812249e7d71b2f7b | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
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;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
CYetAnotherCountingProblem solver = new CYetAnotherCountingProblem();
solver.solve(1, in, out);
out.close();
}
static class CYetAnotherCountingProblem {
long gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
long lcm(int a, int b) {
return 1l * (a * b) / gcd(a, b);
}
long solve2(long x, long lcm, int a) {
long res = (x / lcm) * (lcm - a);
x %= lcm;
if (x >= a) res += (x - a + 1);
return res;
}
public void solve(int testNumber, Scanner sc, PrintWriter pw) {
int q = sc.nextInt();
while (q-- > 0) {
int a = sc.nextInt(), b = sc.nextInt();
if (b > a) {
int temp = a;
a = b;
b = temp;
}
int queries = sc.nextInt();
long LCM = lcm(a, b);
while (queries-- > 0) {
long l = sc.nextLong(), r = sc.nextLong();
pw.print(solve2(r, LCM, a) - solve2(l - 1, LCM, a) + " ");
}
pw.println();
}
}
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
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());
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | fce16211162b104ba156b45210915439 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | /**
* @author egaeus
* @mail sebegaeusprogram@gmail.com
* @veredict Accepted
* @url <https://codeforces.com/problemset/problem/1342/C>
* @category math
* @date 27/04/2012
**/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import static java.lang.Integer.parseInt;
public class CF1342C {
public static void main(String args[]) throws Throwable {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int T = parseInt(in.readLine());
StringBuilder sb = new StringBuilder();
for (int t = 0; t++ < T;) {
StringTokenizer st = new StringTokenizer(in.readLine());
long A = parseInt(st.nextToken()), B = parseInt(st.nextToken()), Q = parseInt(st.nextToken()), MOD = A*B;
long s = 0;
long[] values = new long[(int)MOD];
for(long i = 0; i < MOD; i++) {
if ((i % A) % B != (i % B) % A) {
s++;
}
values[(int)i]=s;
}
for(int q = 0; q < Q; q++) {
st = new StringTokenizer(in.readLine());
long L = Long.parseLong(st.nextToken()), R = Long.parseLong(st.nextToken());
if(q>0)sb.append(" ");
sb.append(f(s, MOD, R, A, B, values)-f(s, MOD, L-1, A, B, values));
}
sb.append("\n");
}
System.out.print(new String(sb));
}
static long f(long s, long MOD, long I, long A, long B, long[] values) {
long result = (I / MOD) * s;
return result + values[(int)(I%MOD)];
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | c220dbb823bb4c457b06248216eb243c | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes |
import java.io.*;
import java.util.StringTokenizer;
// given a, b and q queries
// each queries consist of 2 integer Li, Ri;
// find the number of integer between Li, Ri such that ((x % a) % b) != ((x % b ) % a);
/**
@author Tran Anh Tai
Ideas: if (a == b): return 0 directly;
else WLOG, a > b -> let x = by + d with d is the remainder when x is divided by b;
hence, the condition is equivalent to (by) not divided by a;
hence, y is divided by (b / gcd(a, b));
x = lcm(a, b) * t + d; with d < b;
//what to do now is calculating the number of x such that by is divided by a; (1)
Then the answer is the complement of (1) = (total number of number in range [Li, Ri] - (1));
*/
public class AnotherCountingProb {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Task solver = new Task();
solver.solve(in, out);
out.close();
}
static class Task{
public void solve(InputReader in, PrintWriter out) {
int test = in.nextInt();
int a,b,q;
long r, l;
for (int i = 0; i < test; i++) {
a = in.nextInt();
b = in.nextInt();
q = in.nextInt();
int lcm = (a * b) / gcd(a, b);
if (b < a){
b = a;
}
for (int j = 0; j < q; j++){
l = in.nextLong();
r = in.nextLong();
long au = 0;
for (int re = 0; re < b; re++){
au += (cnt(r, re, lcm) - cnt(l - 1, re, lcm));
}
// the result is the total number - (the number of number in range[l, r] that satisfied the reverse condition);
long result = (r - l + 1) - au;
out.print(result + " ");
}
out.println();
}
}
// count the total number of integer x < l such that (x % a == d);
public static long cnt(long l, int d, int a){
if (l < d){
return 0;
}
int start = 0;
long end = (l - d) / a;
return (end - start + 1);
}
// gcd function
public static int gcd(int a, int b){
if (a == 0){
return b;
}
else{
return gcd(b % a, a);
}
}
}
static class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong(){
return Long.parseLong(nextToken());
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 44c973c4719aff98f9657b5c93f7cdb7 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
static boolean[] vis; //line 74 and 91 hasElement ans pth_fnd
static int MOD=1000000007;
//
static int[] ans;
static int cnt;
static long set1=0,set2=0;
//
public static void main(String[] args) throws IOException{
// long sttm=System.currentTimeMillis();
FastReader sc=new FastReader();
OutputStream out=new BufferedOutputStream(System.out);
int tt=sc.nextInt();
aa: while(tt-->0){
int a=sc.nextInt(),b=sc.nextInt(),q=sc.nextInt();
long lcm=lcmOfTwo(a, b);
int num=Math.max(a,b);
bb: while(q-->0){
long l=sc.nextLong()-1,r=sc.nextLong();
long a1=(r/lcm)*(lcm-num);
if(r%lcm>=num){
a1+=((r%lcm)-num)+1;
}
long a2=(l/lcm)*(lcm-num);
if(l%lcm>=num){
a2+=(l%lcm)-num+1;
}
long ans=a1-a2;
out.write((ans+" ").getBytes());
// System.out.print(ans+" ");
}
out.write(("\n").getBytes());
// System.out.println();
}
out.flush();
}
public static long pow(long n,long k){ //n-pow(k)
if(k==1){
return n%MOD;
}
if(k==0){
return 1;
}
long val=pow(n,k/2)%MOD;
if(k%2==0)return ((val%MOD)*(val%MOD))%MOD;
else return (((val*val)%MOD)*n)%MOD;
}
public static HashMap<Integer,Integer> lcm(int num){
ArrayList<Integer> arrl=new ArrayList<Integer>();
HashMap<Integer,Integer> map=new HashMap<Integer,Integer>();
while(num%2==0){
if(!map.containsKey(2)){
arrl.add(2);
map.put(2, 1);
}
else{
map.put(2,map.get(2)+1);
}
num/=2;
}
for(int i=3;i*i<=num;i+=2){
while(num%i==0){
if(!map.containsKey(i)){
arrl.add(i);
map.put(i, 1);
}
else{
map.put(i,map.get(i)+1);
}
num/=i;
}
}
if(num>2){
if(!map.containsKey(num)){
arrl.add(num);
map.put(num, 1);
}
else{
map.put(num,map.get(num)+1);
}
}
return map;
}
static long m=998244353l;
static long modInverse(long a,long m)
{
long m0 = m;
long y = 0l, x = 1l;
if (m == 1)
return 0l;
while (a > 1)
{
long q = a / m;
long t = m;
m = a % m;
a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
public static int num_fact(int num){
ArrayList<Integer> arr=new ArrayList<Integer>();
int cnt=0;
for(int i=1;i*i<=num;i++){
if(num%i==0){
if(i*i==num){
cnt+=1;
}
else{
cnt+=2;
}
}
}
return cnt;
}
public static void sort_inc(int[][] arr,int col){ //change dimention if req
Arrays.sort(arr, new Comparator<int[]>() {
public int compare(final int[] entry1,final int[] entry2) {
if (entry1[col] > entry2[col]) //this is for inc
return 1;
else if(entry1[col]==entry2[col])
return 0;
else
return -1;
}
});
}
public static boolean prime(int n){
for(int i=2;i*i<=n;i++){
if(n%i==0){
return false;
}
}
return true;
}
static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static long lcmOfTwo(int a,int b){
return a*b/gcd(a,b);
}
}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try{
str = br.readLine();
}
catch (IOException e){
e.printStackTrace();
}
return str;
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 196f40b28fb9b9a599d0f5ab1ed23874 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | /* package codechef; // don't place package name! */
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
FastReader sc = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int test = sc.nextInt();
while(test-->0)
{
int a = sc.nextInt();
int b = sc.nextInt();
int lcm = (a*b)/gcd(a,b);
int max=Math.max(a,b);
int q = sc.nextInt();
while(q-->0)
{
long l = sc.nextLong();
long r = sc.nextLong();
long total=r-l+1;
long multiples=(r/lcm)-((l-1)/lcm);
long ans = total-multiples*max;
long lastMultiple=(r/lcm)*lcm;
long firstMultiple=((l-1)/lcm)*lcm;
if(l>=lcm && l<=firstMultiple+max-1) ans=ans-(firstMultiple+max-l);
if(r>=lcm && lastMultiple+max-1>r) ans=ans+lastMultiple+max-1-r;
if(l<max) ans=ans-(max-l);
if(r<max) ans=ans+max-r-1;
out.print(ans +" ");
}
out.println();
}
out.close();
}
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
}
class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | f69486b2f6f0b394f57562b9c94ef16a | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
static int lcm(int a, int b) {
return a * b / gcd(a, b);
}
static long solve(long r, int a, int b, long lcm, int[][] first, ArrayList<int[]> loop) {
long ans = 0;
for (int[] x : loop) {
int i = x[0], j = x[1];
if (first[i][j] <= r && first[i][j] != 0)
ans += (r - first[i][j]) / lcm + 1;
}
return ans;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner();
PrintWriter out = new PrintWriter(System.out);
int tc = sc.nextInt();
while (tc-- > 0) {
int a = sc.nextInt(), b = sc.nextInt(), q = sc.nextInt();
int[][] first = new int[a][b];
boolean[][] cnt = new boolean[a][b];
int test = 0;
for (int i = a * b; i > 0; i--) {
first[i % a][i % b] = i;
}
ArrayList<int[]> loop = new ArrayList();
for (int i = 0; i < a; i++)
for (int j = 0; j < b; j++) {
if (i % b != j % a) {
cnt[i][j] = true;
} else
loop.add(new int[] { i, j });
}
// System.err.println(a*b-test);
int lcm = lcm(a, b);
while (q-- > 0) {
long l = sc.nextLong(), r = sc.nextLong();
long ans = r - l + 1 - (solve(r, a, b, lcm, first, loop) - solve(l - 1, a, b, lcm, first, loop));
out.print(ans + " ");
}
out.println();
}
out.close();
}
static class Scanner {
BufferedReader br;
StringTokenizer st;
Scanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
Scanner(String fileName) throws FileNotFoundException {
br = new BufferedReader(new FileReader(fileName));
}
String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws NumberFormatException, IOException {
return Long.parseLong(next());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.parseDouble(next());
}
boolean ready() throws IOException {
return br.ready();
}
int[] nxtArr(int n) throws IOException {
int[] ans = new int[n];
for (int i = 0; i < n; i++)
ans[i] = nextInt();
return ans;
}
}
static void sort(int[] a) {
shuffle(a);
Arrays.sort(a);
}
static void shuffle(int[] a) {
int n = a.length;
Random rand = new Random();
for (int i = 0; i < n; i++) {
int tmpIdx = rand.nextInt(n);
int tmp = a[i];
a[i] = a[tmpIdx];
a[tmpIdx] = tmp;
}
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 844ce25573f677112aaa9c27ec411ba0 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.util.*;
import java.io.*;
public class I {
public I(FastScanner in, PrintWriter out, int test) {
int a = in.nextInt();
int b = in.nextInt();
if (a > b) {
int tmp = a;
a = b;
b = tmp;
}
int lcm = a * b / gcd(a, b);
// ((k * lcm + x) % a) % b = (x % a) % b
// ((k * lcm + x) % b) % a = (x % b) % a
// for we find how many valid numbers in range [0, lcm - 1].
int[] A = new int[lcm + 1];
for (int i = 0; i < lcm; i++) {
A[i + 1] = A[i];
if (i % a % b != i % b % a)
A[i + 1]++;
}
int q = in.nextInt();
List<String> res = new ArrayList<>(q);
for (int i = 0; i < q; i++) {
long l = in.nextLong();
long r = in.nextLong() + 1;
long x = l / lcm * A[lcm] + A[(int)(l % lcm)];
long y = r / lcm * A[lcm] + A[(int)(r % lcm)];
res.add(String.valueOf(y - x));
}
out.println(String.join(" ", res));
}
private int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
public static void main(String[] args) {
PrintWriter out = new PrintWriter(System.out);
// Scanner in = new Scanner(
// new BufferedReader(new InputStreamReader(System.in)));
FastScanner in = new FastScanner(System.in);
int T = in.nextInt();
for (int t = 1; t <= T; t++) {
I sol = new I(in, out, t);
}
out.close();
}
}
class FastScanner{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public FastScanner(InputStream stream)
{
this.stream = stream;
}
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++];
}
boolean isSpaceChar(int c)
{
return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
}
boolean isEndline(int c)
{
return c=='\n'||c=='\r'||c==-1;
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String next(){
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do{
res.appendCodePoint(c);
c = read();
}while(!isSpaceChar(c));
return res.toString();
}
String nextLine(){
int c = read();
while (isEndline(c))
c = read();
StringBuilder res = new StringBuilder();
do{
res.appendCodePoint(c);
c = read();
}while(!isEndline(c));
return res.toString();
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 084a4a47ac5bcb3d8abbeb0f5fa52fa1 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.*;
public class C {
static Scanner sc;
// Driver method
public static void main(String args[]) throws FileNotFoundException
{
sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
//File f= new File("stringobits.txt");
//Scanner sc = new Scanner(f);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int a = sc.nextInt();
int b = sc.nextInt();
int q = sc.nextInt();
int[] rem = new int[a*b];
for (int j = 0; j < a; j++) {
for (int k = 0; k < b; k++) {
if (j*b + k != 0) rem[j*b+ k] = rem[j*b + k - 1];
int x = j*b +k;
if ((x%a)%b != ((x%b)%a)) {
rem[x]++;
}
}
}
for (int j = 0; j < q; j++) {
long l = sc.nextLong();
long r = sc.nextLong();
int mod = a*b;
long low = l - (l % mod);
long high = r - (r % mod);
long toret = 0;
toret = toret + (high-low)/mod*rem[a*b-1];
if (l % mod == 0) {}
else toret = toret - rem[(int)(l - low - 1)];
toret = toret + rem[(int)(r - high)];
if (j == q -1) System.out.println(toret);
else System.out.print(toret + " ");
}
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 1ac2a899d133e3eba955d5e47198beca | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class C_YetAnotherCountingProblem {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int __ = 0; __ < T; __++) {
final int a = sc.nextInt();
final int b = sc.nextInt();
final int q = sc.nextInt();
final int period = a * b;
final int[] ab = new int[period];
int sum = 0;
for (int i = 0; i < period; i++) {
if ((i % a) % b != (i % b) % a) {
sum++;
}
ab[i] = sum;
}
// now sum is the total number during one period.
for (int i = 0; i < q; i++) {
long l = sc.nextLong();
long r = sc.nextLong();
System.out.println(r / period * sum + ab[(int) ((r % period))]
- (l - 1) / period * sum - ab[(int) (((l - 1) % period))]
);
}
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | eef1ac442eccdb11aeefd3929f30d2a5 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class C_YetAnotherCountingProblem {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int __ = 0; __ < T; __++) {
final int a = sc.nextInt();
final int b = sc.nextInt();
final int q = sc.nextInt();
final int period = a * b;
final int[] ab = new int[period];
int sum = 0;
for (int i = 0; i < period; i++) {
if ((i % a) % b != (i % b) % a) {
sum++;
}
ab[i] = sum;
}
// now sum is the total number during one period.
for (int i = 0; i < q; i++) {
long l = sc.nextLong();
long r = sc.nextLong();
System.out.println(r / period * sum + ab[(int) ((r % period))]
- (l - 1) / period * sum - ab[(int) (((l - 1) % period))]
);
}
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 1431f5c87d15f5e2c2c39f6edd15a2b4 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Main().new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Main solver = new Main();
solver.solve(1, in, out);
out.close();
}
// prefix sum
public void solve(int testNumber, Scanner in, PrintWriter out) {
int t = in.ni();
for(int ia = 0; ia < t; ia++) {
int a = in.ni();
int b = in.ni();
int sum = a + b;
a = (a < b) ? a : b;
b = sum - a;
int lcm = lcm(a, b);
int q = in.ni();
for(int i = 0; i < q; i++) {
long l = in.nl();
long r = in.nl();
long res = 0;
// cases:
// 1. both are in the same group --> find counts, subtract
// 2. in groups next to each other --> find number of 0's in between
// 3. multiple groups in between --> find number of groups in between, add front end
if(l / lcm == r / lcm) {
long countLeft = Math.max(0, l % lcm - b + 1);
long countRight = Math.max(0, r % lcm - b + 1);
if(countLeft == 0) res = countRight - countLeft;
else res = countRight - countLeft + 1;
} else {
long countLeft = Math.min(lcm - b, lcm - l % lcm);
long countRight = Math.max(0, r % lcm - b + 1);
long countBet = (r / lcm - l / lcm - 1) * (lcm - b);
res = countBet + countLeft + countRight;
}
// long divBoth = r / (a * b) - l / (a * b);
// 01230123||0123 012301230123 01||25
// 01230101||2301 012301012301 01||
// 11111100||0000 111111000000 11||
// 010101 010101
// 010010 010010
// 111000 111000
// 01234560123456012345601234560123456012345601234560123456012345601234560
// 01234560120123456012012345601201234560120123456012012345601201234560120
// 11111111110000000000000000000000000000000000000000000000000000000000000
/*long count = 0;
for(long j = l; j <= r; j++) {
long m1 = (j % a) % b;
long m2 = (j % b) % a;
if(m1 != m2) count++;
}
if(count != res) {
System.err.println("woifjwojfeewof");
}*/
System.out.print(res + " ");// + count + " ");
}
System.out.println();
}
}
static int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
// method to return LCM of two numbers
static int lcm(int a, int b)
{
return (a*b)/gcd(a, b);
}
class Scanner {
BufferedReader br;
StringTokenizer in;
public Scanner(InputStream inputStream) {
br = new BufferedReader(new InputStreamReader(inputStream));
}
public String next() {
return hasMoreTokens() ? in.nextToken() : null;
}
public String readLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
boolean hasMoreTokens() {
while (in == null || !in.hasMoreTokens()) {
String s = readLine();
if (s == null)
return false;
in = new StringTokenizer(s);
}
return true;
}
public String ns() {
return next();
}
public int ni() {
return Integer.parseInt(ns());
}
public long nl() {
return Long.parseLong(ns());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nl();
}
return a;
}
}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 1ef3eefdd42f280f019fa121ad0521ca | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes |
import java.util.Scanner;
public class Codeforces {
static Scanner sc = new Scanner(System.in);
static Long gcd(Long a, Long b) {
if(b == 0) return a;
return gcd(b,a%b);
}
static Long getCount(Long lim, Long period, Long range) {
long ans = 0L;
long blocks = lim/period;
ans += blocks*range;
long last = blocks*period;
ans += Math.min(last+range-1,lim)-last+1;
return ans;
}
public static void main(String[] args) {
int t = sc.nextInt();
for(int i=0;i<t;i++) {
long a,b;
int q;
a = sc.nextLong();
b = sc.nextLong();
q = sc.nextInt();
var lcm = (a*b)/gcd(a,b);
var max = Math.max(a,b);
for(int j=0;j<q;j++) {
long l,r;
l = sc.nextLong();
r = sc.nextLong();
var R = getCount(r,lcm,max);
var L = getCount(l-1,lcm,max);
var ans = r-l+1-(R-L);
System.out.print(ans);
if(j<q-1) System.out.print(" ");
else System.out.println();
}
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | a76adbe9cd0d7b09ce93e1dd3e2ddaab | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | /**
* @author vivek
* programming is thinking, not typing
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class C {
private static void solveTC(int __) {
/* For Google */
// ans.append("Case #").append(__).append(": ");
//code start
int a = scn.nextInt(), b = scn.nextInt(), q = scn.nextInt();
int[] arr = new int[a * b + 1];
for (int i = 1; i < arr.length; i++) {
if ((i % a) % b != (i % b) % a) {
arr[i] = 1;
}
arr[i] += arr[i - 1];
}
while (q-- > 0) {
long l = scn.nextLong();
long r = scn.nextLong();
print(getCount(r, arr) - getCount(l - 1, arr) + " ");
}
//code end
print("\n");
}
private static long getCount(long n, int[] arr) {
long ans = (n / (arr.length - 1)) * arr[arr.length - 1];
ans += arr[(int) (n % (arr.length - 1))];
return ans;
}
/**
* Don't copy other's templates, make your own <br>
* It would be much more beneficial
*/
public static void main(String[] args) {
scn = new Scanner();
ans = new StringBuilder();
int t = scn.nextInt();
// int t = 1;
// int limit= ;
// sieve(limit);
/*
try {
System.setOut(new PrintStream(new File("file_i_o\\output.txt")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
*/
for (int i = 1; i <= t; i++) {
solveTC(i);
}
System.out.print(ans);
}
//Stuff for prime start
/**
* List containing prime numbers <br>
* <b>i<sup>th</sup></b> position contains <b>i<sup>th</sup></b> prime number <br>
* 0th index is <b>null</b>
*/
private static ArrayList<Integer> listOfPrimes;
/**
* query <b>i<sup>th</sup></b> element to get if its prime of not
*/
private static boolean[] isPrime;
/**
* Performs Sieve of Erathosnesis and initialise isPrime array and listOfPrimes list
*
* @param limit the number till which sieve is to be performed
*/
private static void sieve(int limit) {
listOfPrimes = new ArrayList<>();
listOfPrimes.add(null);
boolean[] array = new boolean[limit + 1];
Arrays.fill(array, true);
array[0] = false;
array[1] = false;
for (int i = 2; i <= limit; i++) {
if (array[i]) {
for (int j = i * i; j <= limit; j += i) {
array[j] = false;
}
}
}
isPrime = array;
for (int i = 0; i <= limit; i++) {
if (array[i]) {
listOfPrimes.add(i);
}
}
}
//stuff for prime end
/**
* Calculates the Least Common Multiple of two numbers
*
* @param a First number
* @param b Second Number
* @return Least Common Multiple of <b>a</b> and <b>b</b>
*/
private static long lcm(long a, long b) {
return a * b / gcd(a, b);
}
/**
* Calculates the Greatest Common Divisor of two numbers
*
* @param a First number
* @param b Second Number
* @return Greatest Common Divisor of <b>a</b> and <b>b</b>
*/
private static long gcd(long a, long b) {
return (b == 0) ? a : gcd(b, a % b);
}
static void print(Object obj) {
ans.append(obj.toString());
}
static Scanner scn;
static StringBuilder ans;
//Fast Scanner
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() {
br = new BufferedReader(new
InputStreamReader(System.in));
/*
try {
br = new BufferedReader(new
InputStreamReader(new FileInputStream(new File("file_i_o\\input.txt"))));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
*/
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = nextInt();
}
return array;
}
Integer[] nextIntegerArray(int n) {
Integer[] array = new Integer[n];
for (int i = 0; i < n; i++) {
array[i] = nextInt();
}
return array;
}
long[] nextLongArray(int n) {
long[] array = new long[n];
for (int i = 0; i < n; i++) {
array[i] = nextLong();
}
return array;
}
String[] nextStringArray() {
return nextLine().split(" ");
}
String[] nextStringArray(int n) {
String[] array = new String[n];
for (int i = 0; i < n; i++) {
array[i] = next();
}
return array;
}
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 23e5589df7529a5b4001669f62c5c1f1 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class C {
static final boolean RUN_TIMING = false;
static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1024);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public void go() throws IOException {
// in = new PushbackReader(new BufferedReader(new FileReader(new File("test.txt"))), 1024);
// out = new PrintWriter(new FileWriter(new File("output.txt")));
int zzz = ipar();
for (int zz = 0; zz < zzz; zz++) {
int a = ipar();
int b = ipar();
int q = ipar();
int ab = a*b;
int[] prefix = new int[ab+1];
for (int i = 1; i <= ab; i++) {
prefix[i] = prefix[i-1];
if ((i-1) % a % b != (i-1) % b % a) {
prefix[i]++;
}
}
// out.println(Arrays.toString(prefix));
for (int i = 0; i < q; i++) {
long l = lpar();
long r = lpar();
long lWhole = l / ab;
int lRem = (int)(l % ab);
long rWhole = r / ab;
int rRem = (int)(r % ab);
if (lWhole == rWhole) {
out.print(prefix[rRem+1] - prefix[lRem]);
out.print(" ");
continue;
}
long between = rWhole - lWhole - 1;
out.print(prefix[ab] - prefix[lRem] + prefix[rRem+1] + between * prefix[ab]);
out.print(" ");
}
out.println();
}
}
public int ipar() throws IOException {
return Integer.parseInt(spar());
}
public int[] iapar(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = ipar();
}
return arr;
}
public long lpar() throws IOException {
return Long.parseLong(spar());
}
public long[] lapar(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = lpar();
}
return arr;
}
public double dpar() throws IOException {
return Double.parseDouble(spar());
}
public String spar() throws IOException {
StringBuilder sb = new StringBuilder(1024);
int c;
do {
c = in.read();
} while (Character.isWhitespace(c) && c != -1);
if (c == -1) {
throw new NoSuchElementException("Reached EOF");
}
do {
sb.append((char)c);
c = in.read();
} while (!Character.isWhitespace(c) && c != -1);
while (c != '\n' && Character.isWhitespace(c) && c != -1) {
c = in.read();
}
if (c != -1 && c != '\n') {
in.unread(c);
}
return sb.toString();
}
public String linepar() throws IOException {
StringBuilder sb = new StringBuilder(1024);
int c;
while ((c = in.read()) != '\n' && c != -1) {
if (c == '\r') {
continue;
}
sb.append((char)c);
}
return sb.toString();
}
public boolean haspar() throws IOException {
String line = linepar();
if (line.isEmpty()) {
return false;
}
in.unread('\n');
in.unread(line.toCharArray());
return true;
}
public static void main(String[] args) throws IOException {
long time = 0;
time -= System.nanoTime();
new C().go();
time += System.nanoTime();
if (RUN_TIMING) {
System.out.printf("%.3f ms%n", time/1000000.0);
}
out.flush();
in.close();
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | f16aa4f613869ebb1c5d9d0f87eb9895 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class C {
static final boolean RUN_TIMING = false;
static PushbackReader in = new PushbackReader(new BufferedReader(new InputStreamReader(System.in)), 1024);
static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
public void go() throws IOException {
// in = new PushbackReader(new BufferedReader(new FileReader(new File("test.txt"))), 1024);
// out = new PrintWriter(new FileWriter(new File("output.txt")));
int zzz = ipar();
for (int zz = 0; zz < zzz; zz++) {
int a = ipar();
int b = ipar();
int q = ipar();
int ab = a*b;
int[] prefix = new int[ab+1];
for (int i = 1; i <= ab; i++) {
prefix[i] = prefix[i-1];
if ((i-1) % a % b != (i-1) % b % a) {
prefix[i]++;
}
}
// out.println(Arrays.toString(prefix));
for (int i = 0; i < q; i++) {
long l = lpar()-1;
long r = lpar();
long lWhole = l / ab;
int lRem = (int)(l % ab);
long rWhole = r / ab;
int rRem = (int)(r % ab);
out.print(rWhole * prefix[ab] + prefix[rRem+1] - (lWhole * prefix[ab] + prefix[lRem+1]));
out.print(" ");
}
out.println();
}
}
public int ipar() throws IOException {
return Integer.parseInt(spar());
}
public int[] iapar(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = ipar();
}
return arr;
}
public long lpar() throws IOException {
return Long.parseLong(spar());
}
public long[] lapar(int n) throws IOException {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = lpar();
}
return arr;
}
public double dpar() throws IOException {
return Double.parseDouble(spar());
}
public String spar() throws IOException {
StringBuilder sb = new StringBuilder(1024);
int c;
do {
c = in.read();
} while (Character.isWhitespace(c) && c != -1);
if (c == -1) {
throw new NoSuchElementException("Reached EOF");
}
do {
sb.append((char)c);
c = in.read();
} while (!Character.isWhitespace(c) && c != -1);
while (c != '\n' && Character.isWhitespace(c) && c != -1) {
c = in.read();
}
if (c != -1 && c != '\n') {
in.unread(c);
}
return sb.toString();
}
public String linepar() throws IOException {
StringBuilder sb = new StringBuilder(1024);
int c;
while ((c = in.read()) != '\n' && c != -1) {
if (c == '\r') {
continue;
}
sb.append((char)c);
}
return sb.toString();
}
public boolean haspar() throws IOException {
String line = linepar();
if (line.isEmpty()) {
return false;
}
in.unread('\n');
in.unread(line.toCharArray());
return true;
}
public static void main(String[] args) throws IOException {
long time = 0;
time -= System.nanoTime();
new C().go();
time += System.nanoTime();
if (RUN_TIMING) {
System.out.printf("%.3f ms%n", time/1000000.0);
}
out.flush();
in.close();
}
}
| Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | f531aee22e89f2fe0a5fed6c5d628481 | train_003.jsonl | 1587911700 | You are given two integers $$$a$$$ and $$$b$$$, and $$$q$$$ queries. The $$$i$$$-th query consists of two numbers $$$l_i$$$ and $$$r_i$$$, and the answer to it is the number of integers $$$x$$$ such that $$$l_i \le x \le r_i$$$, and $$$((x \bmod a) \bmod b) \ne ((x \bmod b) \bmod a)$$$. Calculate the answer for each query.Recall that $$$y \bmod z$$$ is the remainder of the division of $$$y$$$ by $$$z$$$. For example, $$$5 \bmod 3 = 2$$$, $$$7 \bmod 8 = 7$$$, $$$9 \bmod 4 = 1$$$, $$$9 \bmod 9 = 0$$$. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class cf1342c {
static BufferedReader __in;
static PrintWriter __out;
static StringTokenizer input;
public static void main(String[] args) throws IOException {
__in = new BufferedReader(new InputStreamReader(System.in));
__out = new PrintWriter(new OutputStreamWriter(System.out));
int t = readInt();
while(t --> 0) {
read();
int a = nextInt(), b = nextInt(), q = nextInt();
/* if(a > b) {
int swap = a;
a = b;
b = swap;
}*/
long[] cyc = new long[a * b + 1];
for(int k = 1; k <= a * b; ++k) {
cyc[k] = cyc[k - 1];
if(((k - 1) % a) % b != ((k - 1) % b) % a) {
++cyc[k];
}
}
for(int i = 0; i < q; ++i) {
read();
long l = nextLong(), r = nextLong() + 1, lastM = r / (a * b) * (a * b), prevM = l / (a * b) * (a * b);
// if(lastM <= r && lastM > l) {
println(cyc[(int)(r - lastM)] + (lastM - prevM) / (a * b) * cyc[a * b] - cyc[(int)(l - prevM)]);
// } else {
// assert lastM == prevM;
// println(cyc[(int)(r - prevM)] - cyc[(int)(l - prevM)]);
// }
}
}
close();
}
static final int IBIG = 1000000007;
static final int IMAX = 2147483647;
static final long LMAX = 9223372036854775807L;
static void read() throws IOException {input = new StringTokenizer(__in.readLine());}
static String readLine() throws IOException {return __in.readLine();}
static int nextInt() {return Integer.parseInt(input.nextToken());}
static int readInt() throws IOException {return Integer.parseInt(__in.readLine());}
static long nextLong() {return Long.parseLong(input.nextToken());}
static void print(String s) {__out.print(s);}
static void println(String s) {__out.println(s);}
static void print(Object o) {__out.print(o);}
static void println(Object o) {__out.println(o);}
static void printy() {__out.println("Yes");}
static void printY() {__out.println("YES");}
static void printn() {__out.println("No");}
static void printN() {__out.println("NO");}
static void printyn(boolean b) {__out.println(b ? "Yes" : "No");}
static void printYN(boolean b) {__out.println(b ? "YES" : "NO");}
static void println(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), i++); __out.println(a[a.length - 1]);}
static void println(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), i++); __out.println(a[a.length - 1]);}
static void println() {__out.println();}
static void close() {__out.close();}
} | Java | ["2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200"] | 3.5 seconds | ["0 0 0 2 4 \n0 91"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a1effd6a0f6392f46f6aa487158fef7d | The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$)Β β the number of test cases. Then the test cases follow. The first line of each test case contains three integers $$$a$$$, $$$b$$$ and $$$q$$$ ($$$1 \le a, b \le 200$$$; $$$1 \le q \le 500$$$). Then $$$q$$$ lines follow, each containing two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le 10^{18}$$$) for the corresponding query. | 1,600 | For each test case, print $$$q$$$ integersΒ β the answers to the queries of this test case in the order they appear. | standard output | |
PASSED | 3d3ef886278653ded1070ac7b938c2bd | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.*;
public class Trying
{
public static void main (String[] args)
{
Scanner enter = new Scanner(System.in);
int n = enter.nextInt(), scores [] = new int [n], pos = 0, max = Integer.MIN_VALUE;
String handles[] = new String [n];
for(int i = 0 ; i < n ; i++)
{
handles[i] = enter.next();
scores[i] += (enter.nextInt()*100) - (enter.nextInt()*50)
+ enter.nextInt() + enter.nextInt() + enter.nextInt() + enter.nextInt() + enter.nextInt() ;
if(scores[i] > max){max = scores[i]; pos = i;}
}
System.out.println(handles[pos]);
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 3ef0fb5bbcbbada91b7dec5d136f0dac | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.*;
public class RoomLeader {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int max = Integer.MIN_VALUE;
String winner = "";
for (int i = 0; i < n; i++) {
String handle = in.next();
int plus = in.nextInt();
int minus = in.nextInt();
int A = in.nextInt();
int B = in.nextInt();
int C = in.nextInt();
int D = in.nextInt();
int E = in.nextInt();
int points = 100 * plus - 50 * minus + A + B + C + D + E;
if (points > max) {
max = points;
winner = handle;
}
}
System.out.println(winner);
in.close();
System.exit(0);
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | eb261fdfe6f26c5f75eca4b449f057f0 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Leader
{
public static void main(String[] args) throws java.lang.Exception {
Scanner f = new Scanner(System.in);
int n=f.nextInt();
String[] matrix = new String[n];
int max=-2147483648;
int index=0;
for(int i=0; i<n; i++){
String handle = f.next();
int score =(100*f.nextInt() -50*f.nextInt() + f.nextInt()+f.nextInt()+f.nextInt()+f.nextInt()+f.nextInt());
matrix[i]= handle+" "+ score;
if(score>max){
max=score;
index=i;
}
}
System.out.println(matrix[index].substring(0,matrix[index].indexOf(' ')));
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | eb2375acd9d0064ce47a0450bc0b934a | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author AlexFetisov
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
String[] names = new String[n];
final int[] scores = new int[n];
Integer[] id = new Integer[n];
for (int i = 0; i < n; ++i) {
names[i] = in.nextString();
scores[i] = in.nextInt() * 100 - in.nextInt() * 50 + in.nextInt() + in.nextInt() + in.nextInt() + in.nextInt() + in.nextInt();
id[i] = i;
}
Arrays.sort(id, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return scores[o2] - scores[o1];
}
});
out.println(names[id[0]]);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer stt;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
}
public String nextLine() {
try {
return reader.readLine().trim();
} catch (IOException e) {
return null;
}
}
public String nextString() {
while (stt == null || !stt.hasMoreTokens()) {
stt = new StringTokenizer(nextLine());
}
return stt.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextString());
}
}
| Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 95edb28ac83446afad730cb1d75e8153 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.Scanner;
public class Ishu
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n,i,j,max,index=0;
int[][] a=new int[50][8];
String[] handle=new String[50];
n=scan.nextInt();
for(i=0;i<n;++i)
{
handle[i]=scan.next();
for(j=0;j<7;++j)
{
a[i][j]=scan.nextInt();
if(j>1)
a[i][7]+=a[i][j];
}
a[i][7]+=a[i][0]*100-a[i][1]*50;
}
max=a[0][7];
for(i=0;i<n;++i)
if(a[i][7]>max)
{
index=i;
max=a[i][7];
}
System.out.println(handle[index]);
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | a639d9474f86ecb6ab68ec945518f247 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Test {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
A[] as = new A[n];
for(int i=0;i<n;i++){
String name = in.next();
int x = in.nextInt()*100;
int y = in.nextInt()*50;
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int d = in.nextInt();
int e = in.nextInt();
as[i] = new A(name,x-y+a+b+c+d+e);
}
Arrays.sort(as);
System.out.println(as[0].name);
}
static class A implements Comparable<A>{
int points;
String name;
A(String name,int points){
this.points = points;
this.name = name;
}
@Override
public int compareTo(A a) {
return a.points-this.points;
}
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 2f36f5931fabca84f8495ad966dc06c1 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class R68A {
static int k;
public static void main (String[] args) throws java.lang.Exception {
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = in.nextInt();
String winner = "";
int mp = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
String ip = in.next();
int pt = (in.nextInt() * 100) - (in.nextInt() * 50) + in.nextInt() + in.nextInt() + in.nextInt() + in.nextInt() + in.nextInt() ;
//System.out.println(ip + " " + pt);
if (pt > mp) {
mp = pt;
winner = ip;
}
}
w.println(winner);
w.close();
}
static 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 UnknownError();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new UnknownError();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public 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];
}
public void skip(int x) {
while (x-- > 0)
read();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public String nextString() {
return next();
}
public String next() {
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 String nextLine() {
StringBuffer buf = new StringBuffer();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public boolean hasNext() {
int value;
while (isSpaceChar(value = peek()) && value != -1)
read();
return value != -1;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | ac89119dfe8d7047e43f419ccd13ebd2 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes |
import static java.lang.System.in;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt(), max = Integer.MIN_VALUE;
String leader = null;
while(n-->0)
{
String name = sc.next();
int score = sc.nextInt() * 100 - sc.nextInt() * 50;
for(int i = 0; i < 5; ++i)
score += sc.nextInt();
if(score > max)
{
max = score;
leader = name;
}
}
out.println(leader);
out.flush();
out.close();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
}
}
| Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 36e137adcaab796fa395d3a38f620bcd | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.*;
import java.io.*;
//1000
public class RoomLeader {
static int N;
static HashMap<String, Integer> points;
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
points = new HashMap<>();
for (int i = 0; i < N; i++)
{
st = new StringTokenizer(br.readLine());
String name = st.nextToken();
int numSuccess = Integer.parseInt(st.nextToken());
int numFail = Integer.parseInt(st.nextToken());
int sum = 0;
for (int j = 0; j < 5; j++)
sum += Integer.parseInt(st.nextToken());
sum += numSuccess*100 + numFail*(-50);
points.put(name, sum);
}
int max = Integer.MIN_VALUE;
String maxName = "";
for (Map.Entry<String, Integer> e : points.entrySet())
{
if (e.getValue() > max)
{
max = e.getValue();
maxName = e.getKey();
}
}
System.out.println(maxName);
}
}
| Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 66efd6c98ded39ad7dd3c2c0aa8609cd | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes |
import java.util.Scanner;
public class ARoomLeader {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String bh="";
int opScore=-400000;
if(n==1)
System.out.println(sc.next());
else
{
for (int i = 0; i < n; i++) {
String handle=sc.next();
int score=sc.nextInt()*100-sc.nextInt()*50;
for (int j = 0; j < 5; j++) {
score+=sc.nextInt();
}
if(score>opScore)
{
opScore=score;
bh=handle;
}
}
System.out.println(bh);
}
}
}
| Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | ece50cfafdd4e207524b5369f8026381 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class SolutionA{
public static void main(String[] args){
new SolutionA().run();
}
int n;
String nick[];
int a[];
void solve(){
n = in.nextInt();
nick = new String[n];
a = new int[n];
for(int i = 0; i < n; i++){
nick[i] = in.next();
int x = in.nextInt();
int y = in.nextInt();
for(int j = 0; j < 5; j++){
a[i] += in.nextInt();
}
a[i] += 100 * x;
a[i] -= 50 * y;
}
int maxi = 0;
for(int i = 1; i<n; i++)
if(a[maxi] < a[i]) maxi = i;
out.println(nick[maxi]);
}
class Pair implements Comparable<Pair>{
int x, y;
Pair(int x, int y){
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
if(o.x == x) return ((Integer) y).compareTo(o.y);
return ((Integer) x).compareTo(o.x);
}
}
FastScanner in;
PrintWriter out;
void run(){
in = new FastScanner(System.in);
out = new PrintWriter(new OutputStreamWriter(System.out));
solve();
out.close();
}
void runIO(){
try{
in = new FastScanner(new File("expr.in"));
out = new PrintWriter(new FileWriter(new File("expr.out")));
solve();
out.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
class FastScanner{
BufferedReader bf;
StringTokenizer st;
public FastScanner(File f){
try{
bf = new BufferedReader(new FileReader(f));
}
catch(IOException ex){
ex.printStackTrace();
}
}
public FastScanner(InputStream is){
bf = new BufferedReader(new InputStreamReader(is));
}
String next(){
while(st == null || !st.hasMoreTokens()){
try{
st = new StringTokenizer(bf.readLine());
}
catch(IOException ex){
ex.printStackTrace();
}
}
return st.nextToken();
}
char nextChar(){
return next().charAt(0);
}
int nextInt(){
return Integer.parseInt(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
float nextFloat(){
return Float.parseFloat(next());
}
String nextLine(){
try{
return bf.readLine();
}
catch(Exception ex){
ex.printStackTrace();
}
return "";
}
long nextLong(){
return Long.parseLong(next());
}
BigInteger nextBigInteger(){
return new BigInteger(next());
}
BigDecimal nextBigDecimal(){
return new BigDecimal(next());
}
int[] nextIntArray(int n){
int a[] = new int[n];
for(int i = 0; i < n; i++)
a[i] = Integer.parseInt(next());
return a;
}
long[] nextLongArray(int n){
long a[] = new long[n];
for(int i = 0; i < n; i++)
a[i] = Long.parseLong(next());
return a;
}
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 92c0a9c31848ce805a35882cc8224b67 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.io.*;
import java.util.*;
public class A1008 {
public static void main(String [] args) /*throws Exception*/ {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(inputReader);//new InputReader(new FileInputStream(new File("input.txt")));new InputReader(inputReader);
PrintWriter out = new PrintWriter(outputReader);//new PrintWriter(new FileOutputStream(new File("output.txt")));
Algorithm solver = new Algorithm();
solver.solve(in, out);
out.close();
}
}
class Algorithm {
void solve(InputReader ir, PrintWriter pw) {
int n = ir.nextInt(), max = 0;
String [] nicknames = new String[n];
int [] total = new int[n];
for (int i = 0, plus, minus, a, b, c, d, e; i < n; i++) {
nicknames[i] = ir.next();
plus = ir.nextInt();
minus = ir.nextInt();
a = ir.nextInt();
b = ir.nextInt();
c = ir.nextInt();
d = ir.nextInt();
e = ir.nextInt();
total[i] = plus * 100 - minus * 50 + a + b + c + d + e;
}
for (int i = 0; i < n; i++) if (total[i] > total[max]) max = i;
pw.print(nicknames[max]);
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
String nextLine(){
String fullLine = null;
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
fullLine = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return fullLine;
}
return fullLine;
}
String [] toArray() {
return nextLine().split(" ");
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 2b8d1df77839f10a99dac3c8be1ed2ab | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.Scanner;
public class CF74A {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
String names[] = new String[n];
int max = Integer.MIN_VALUE;
int contestant = 0;
for (int i = 0; i < n; i++) {
names[i] = in.next();
int score = in.nextInt() * 100;
score -= in.nextInt() * 50;
for (int j = 0; j <= 4; j++) {
score += in.nextInt();
}
if (score > max) {
contestant = i;
max = score;
}
}
System.out.println(names[contestant]);
}
}
| Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 2a28bd56047d280d712dd09ac3ecafb7 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author An Almost Retired Guy
*/
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
TreeMap<Integer, String> map = new TreeMap<>();
for (int i = 0; i < n; i++) {
String name = in.nextString();
int plus = in.nextInt(), minus = in.nextInt(), a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt(), e = in.nextInt();
int score = plus * 100 - minus * 50 + a + b + c + d + e;
map.put(score, name);
}
out.println(map.lastEntry().getValue());
}
}
static class OutputWriter extends PrintWriter {
public OutputWriter(OutputStream outputStream) {
super(new BufferedOutputStream(outputStream));
}
public OutputWriter(Writer writer) {
super(writer);
}
public void close() {
super.close();
}
}
static class InputReader {
BufferedReader br;
StringTokenizer st;
public InputReader(InputStream inputStream) {
br = new BufferedReader(new InputStreamReader(inputStream));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public String nextString() {
return next();
}
public String nextLine() {
try {
return br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
| Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | e57c78a1d2faab590b05f1287cc62fb2 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | //package CF;
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 A {
public static int score(String [][] info, int ind){
int res = Integer.parseInt(info[ind][1])*100 -
Integer.parseInt(info[ind][2])*50
+ Integer.parseInt(info[ind][3])
+ Integer.parseInt(info[ind][4])
+ Integer.parseInt(info[ind][5])
+ Integer.parseInt(info[ind][6])
+ Integer.parseInt(info[ind][7]);
return res;
}
public static void main(String[] args) throws Exception
{
Scanner bf = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = bf.nextInt();
String [][] info = new String[n][8];
for (int i = 0; i < info.length; i++)
{
info[i] = bf.nextLine().split(" ");
}
int max = 0, score = score(info,0);
for (int i = 1; i < info.length; i++)
{
int tmp = score(info,i);
if(tmp > score){
score = tmp;
max = i;
}
}
out.println(info[max][0]);
out.flush();
out.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s)
{
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader fileReader)
{
br = new BufferedReader(fileReader);
}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException
{
return Integer.parseInt(next());
}
public long nextLong() throws IOException
{
return Long.parseLong(next());
}
public String nextLine() throws IOException
{
return br.readLine();
}
public boolean ready() throws IOException
{
return br.ready();
}
}
}
| Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | baca8c4882b5105642a9edd73bdcf3da | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
String win=new String();
int res=Integer.MIN_VALUE;
for(int i=0;i<n;i++){
String t=sc.next();
int temp=sc.nextInt()*100-sc.nextInt()*50+sc.nextInt()+sc.nextInt()
+sc.nextInt()+sc.nextInt()+sc.nextInt();
if(temp>res){
res=temp;
win=t;
}
}
System.out.println(win);
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | f2fa406c8b37abd2ef191de95e4ca213 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
/**
*
* @author User
*/
public class Codeforces {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Scanner in = new Scanner(System.in);
PrintWriter writer = new PrintWriter(System.out);
int n =in.nextInt();
Map<String , Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
String h = in.next();
int p = in.nextInt();
int m = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
int d = in.nextInt();
int e = in.nextInt();
map.put(h,p*100-m*50+a+b+c+d+e);
}
Integer max = Collections.max(map.values());
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Entry x = (Entry)it.next();
Object key = x.getKey();
Object value = x.getValue();
if(max.equals(value)){
writer.println(key);
}
}
writer.close();
}
}
| Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | cbf023f748f160d748b534ac4dde2917 | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main extends PrintWriter {
BufferedReader in;
StringTokenizer stok;
final Random rand = new Random(31);
final int inf = (int) 1e9;
final long linf = (long) 1e18;
final static String IO = "_std";
void solve() throws IOException {
int n = nextInt();
int max = -inf;
String ans = null;
for (int i = 0; i < n; i++) {
String name = next();
int res = nextInt() * 100 - nextInt() * 50 + nextInt() + nextInt() + nextInt() + nextInt() + nextInt();
if (res > max) {
max = res;
ans = name;
}
}
println(ans);
}
Main() {
super(System.out);
in = new BufferedReader(new InputStreamReader(System.in));
}
Main(String fileIn, String fileOut) throws IOException {
super(fileOut);
in = new BufferedReader(new FileReader(fileIn));
}
public static void main(String[] args) throws IOException {
Main main;
if ("_std".equals(IO)) {
main = new Main();
} else if ("_iodef".equals(IO)) {
main = new Main("input.txt", "output.txt");
} else {
main = new Main(IO + ".in", IO + ".out");
}
main.solve();
main.close();
}
String next() throws IOException {
while (stok == null || !stok.hasMoreTokens()) {
String s = in.readLine();
if (s == null) {
return null;
}
stok = new StringTokenizer(s);
}
return stok.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());
}
int[] nextIntArray(int len) throws IOException {
int[] a = new int[len];
for (int i = 0; i < len; i++) {
a[i] = nextInt();
}
return a;
}
int[] nextIntArraySorted(int len) throws IOException {
int[] a = nextIntArray(len);
shuffle(a);
Arrays.sort(a);
return a;
}
void shuffle(int[] a) {
for (int i = 1; i < a.length; i++) {
int x = rand.nextInt(i + 1);
int _ = a[i];
a[i] = a[x];
a[x] = _;
}
}
void shuffleAndSort(int[] a) {
shuffle(a);
Arrays.sort(a);
}
boolean nextPermutation(int[] p) {
for (int a = p.length - 2; a >= 0; --a) {
if (p[a] < p[a + 1])
for (int b = p.length - 1; ; --b)
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
}
return false;
}
<T> List<T>[] createAdjacencyList(int n) {
List<T>[] res = new List[n];
for (int i = 0; i < n; i++) {
res[i] = new ArrayList<>();
}
return res;
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 8221c2610a5312fa72c1214394bd256b | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.util.*;
public class Main
{
static String []first,last;
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int n = s.nextInt();
Winner cs[] = new Winner[n];
for (int i=0;i < n;i++)
{
cs[i] = new Winner(
s.next(),
s.nextInt() * 100 + s.nextInt() * -50
+ s.nextInt() + s.nextInt() + s.nextInt()
+ s.nextInt() + s.nextInt()
);
}
Arrays.sort(cs);
System.out.println(cs[0].name);
}
}
class Winner implements Comparable<Winner>
{
int score;
String name;
public Winner(String n, int s)
{
score = s;
name = n;
}
@Override
public int compareTo(Winner p1)
{
// TODO: Implement this method
return p1.score - score;
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output | |
PASSED | 31c9b93f565336f5ad1e939e6bce48ab | train_003.jsonl | 1302879600 | Let us remind you part of the rules of Codeforces. The given rules slightly simplified, use the problem statement as a formal document.In the beginning of the round the contestants are divided into rooms. Each room contains exactly n participants. During the contest the participants are suggested to solve five problems, A, B, C, D and E. For each of these problem, depending on when the given problem was solved and whether it was solved at all, the participants receive some points. Besides, a contestant can perform hacks on other contestants. For each successful hack a contestant earns 100 points, for each unsuccessful hack a contestant loses 50 points. The number of points for every contestant is represented by the sum of points he has received from all his problems, including hacks.You are suggested to determine the leader for some room; the leader is a participant who has maximum points. | 256 megabytes | import java.io.BufferedReader;
//import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
//import java.io.FileReader;
//import java.io.FileWriter;
//import java.lang.StringBuilder;
import java.util.StringTokenizer;
//import java.lang.Comparable;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.ArrayList;
public class RoomLeader {
//static BufferedReader in = new BufferedReader(new FileReader("input.txt"));
//static PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int n = Integer.parseInt(in.readLine());
String leader = "";
int max_point = -100000;
for(int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(in.readLine());
String name = st.nextToken();
int p = 100 * Integer.parseInt(st.nextToken());
int m = -50 * Integer.parseInt(st.nextToken());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int c = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int e = Integer.parseInt(st.nextToken());
int point = p + m + a + b + c + d + e;
if(point > max_point) {
leader = name;
max_point = point;
}
}
out.print(leader);
out.close();
}
} | Java | ["5\nPetr 3 1 490 920 1000 1200 0\ntourist 2 0 490 950 1100 1400 0\nEgor 7 0 480 900 950 0 1000\nc00lH4x0R 0 10 150 0 0 0 0\nsome_participant 2 1 450 720 900 0 0"] | 2 seconds | ["tourist"] | NoteThe number of points that each participant from the example earns, are as follows: Petr β 3860 tourist β 4140 Egor β 4030 c00lH4x0R β β-β350 some_participant β 2220 Thus, the leader of the room is tourist. | Java 8 | standard input | [
"implementation"
] | b9dacff0cab78595296d697d22dce5d9 | The first line contains an integer n, which is the number of contestants in the room (1ββ€βnββ€β50). The next n lines contain the participants of a given room. The i-th line has the format of "handlei plusi minusi ai bi ci di ei" β it is the handle of a contestant, the number of successful hacks, the number of unsuccessful hacks and the number of points he has received from problems A, B, C, D, E correspondingly. The handle of each participant consists of Latin letters, digits and underscores and has the length from 1 to 20 characters. There are the following limitations imposed upon the numbers: 0ββ€βplusi,βminusiββ€β50; 150ββ€βaiββ€β500 or aiβ=β0, if problem A is not solved; 300ββ€βbiββ€β1000 or biβ=β0, if problem B is not solved; 450ββ€βciββ€β1500 or ciβ=β0, if problem C is not solved; 600ββ€βdiββ€β2000 or diβ=β0, if problem D is not solved; 750ββ€βeiββ€β2500 or eiβ=β0, if problem E is not solved. All the numbers are integer. All the participants have different handles. It is guaranteed that there is exactly one leader in the room (i.e. there are no two participants with the maximal number of points). | 1,000 | Print on the single line the handle of the room leader. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.