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
0eb893b4c0e5c94cec444490b8fbee6b
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import javafx.util.Pair; import java.util.*; import java.io.*; public class marlin{ public static void main(String[] args) throws Exception{ Parser ps = new Parser(System.in); int n = ps.nextInt(); int k = ps.nextInt(); System.out.println("YES"); for(int i = 0; i < 4; i++){ if(i == 0 || i == 3){ for(int j = 0; j < n; j++){ System.out.print("."); } } else{ Set<Integer> colPts = createSymmetry(k, n); k -= colPts.size(); for(int j = 0; j < n; j++){ if(colPts.contains(j)){ System.out.print("#"); } else{ System.out.print("."); } } } System.out.println(); } } //return a set with column coordinates where hotels should be placed in order to create a symmetry //this shall exclude column 0 and last column (n-1) public static Set<Integer> createSymmetry(int hotels, int n){ Set<Integer> colPts = new HashSet<>(); if(hotels % 2 != 0){ colPts.add(n/2); //n is an integer, so decimal part will be truncated off, which will result in middle column --hotels; } //guaranteed that hotels is even at this point int leftSide = 1; int rightSide = (n-(leftSide+1)); while(hotels > 0){ colPts.add(leftSide); colPts.add(rightSide); leftSide++; rightSide = (n-(leftSide+1)); hotels -= 2; } return colPts; } } class Parser { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Parser(InputStream in) { din = new DataInputStream(in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } 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; } //reads in the next string public String next() throws Exception { StringBuilder ret = new StringBuilder(); byte c = read(); while (c <= ' ') c = read(); do { ret = ret.append((char)c); c = read(); } while (c > ' '); return ret.toString(); } 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; } 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
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
a5b03afa24c5a88665e96badc44f4980
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import javafx.util.Pair; import java.util.*; import java.io.*; public class marlin{ public static void main(String[] args) throws Exception{ Parser ps = new Parser(System.in); int n = ps.nextInt(); int k = ps.nextInt(); System.out.println("YES"); for(int i = 0; i < 4; i++){ if(i == 0 || i == 3){ for(int j = 0; j < n; j++){ System.out.print("."); } } else{ Set<Integer> colPts = createSymmetry(k, n); k -= colPts.size(); for(int j = 0; j < n; j++){ if(colPts.contains(j)){ System.out.print("#"); } else{ System.out.print("."); } } } System.out.println(); } } //return a set with column coordinates where hotels should be placed in order to create a symmetry //this shall exclude column 0 and last column (n-1) public static Set<Integer> createSymmetry(int hotels, int n){ Set<Integer> colPts = new HashSet<>(); if(hotels % 2 != 0){ colPts.add(n/2); //n is an integer, so decimal part will be truncated off, which will result in middle column --hotels; } //guaranteed that hotels is even at this point int leftSide = 1; int rightSide = (n-(leftSide+1)); while(hotels > 0){ colPts.add(leftSide); colPts.add(rightSide); rightSide = (n-(++leftSide+1)); hotels -= 2; } return colPts; } } class Parser { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Parser(InputStream in) { din = new DataInputStream(in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } 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; } //reads in the next string public String next() throws Exception { StringBuilder ret = new StringBuilder(); byte c = read(); while (c <= ' ') c = read(); do { ret = ret.append((char)c); c = read(); } while (c > ' '); return ret.toString(); } 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; } 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
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
87cc94992412481dac257a2eb117d704
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.*; import java.io.*; public class grid_new{ public static void main(String[] args)throws IOException { Scanner in=new Scanner(System.in); //int t=in.nextInt(); //while(t-->0) //{ int n=in.nextInt(); int k=in.nextInt(); int i,j; int l=k/2,m=(n-2)-k,s=k,a=(k-(n-2))/2; System.out.println("YES"); for(i=0;i<4;i++) { for(j=0;j<n;j++) { if(i==0 || i==3) System.out.print("."); else if(j==0 || j==(n-1)) System.out.print("."); else { if(k%2==0) { if(j<=l) System.out.print("#"); else System.out.print("."); } else { if(k>=(n-2) && i==1) { System.out.print("#"); } else if(k<(n-2) && i==1) { if(j>=(n-k)/2 && s>0) { System.out.print("#"); s--; } else System.out.print("."); } else if(k>(n-2) && i==2) { if((n-1-j)<=a || j<=a) System.out.print("#"); else System.out.print("."); } else System.out.print("."); } } } System.out.println(); } //} } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
58c29192f3cabf37422de12bdfe57936
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); char[][] arr=new char[4][n]; for(int i=0;i<4;i++) Arrays.fill(arr[i],'.'); System.out.println("YES"); int i=n/2-1; if(k%2==1) { arr[1][n/2]='#'; k--; } else if(k>0&&k%2==0) { arr[1][n/2]=arr[2][n/2]='#'; k-=2; } int l=1; while(k>0) { if(i==0) {l=2;i=(n/2)-1;} arr[l][i]=arr[l][i+2*(n/2-i)]='#'; i--; k-=2; } for(i=0;i<4;i++) { for(int j=0;j<n;j++) System.out.print(arr[i][j]); System.out.println(""); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
3640e88a5e89f1f40168e8bcc7f105b2
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
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 * * @author The Viet Nguyen */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { static int n = 4; static int m; static boolean[][] g = new boolean[n][]; static PrintWriter out; public void solve(int testNumber, InputReader in, PrintWriter out) { TaskB.out = out; m = in.nextInt(); int k = in.nextInt(); for (int i = 0; i < n; ++i) g[i] = new boolean[m]; for (int i = 1; i < n - 1 && k > 1; ++i) for (int j = 1; j <= m / 2 && k > 1; ++j, k -= 2) { g[i][j] = g[i][m - 1 - j] = true; if (j == m - 1 - j) ++k; } if (k % 2 != 0) { for (int i = 1; i < n; ++i) if (!g[i][m / 2]) { g[i][m / 2] = true; break; } } out.println("YES"); print(out); } private void print(PrintWriter out) { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) if (g[i][j]) out.print('#'); else out.print('.'); out.println(); } } } static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
b17f3905c9e6e31be7ecef8905c8ce61
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
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 * * @author The Viet Nguyen */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = 4, m = in.nextInt(), k = in.nextInt(); boolean[][] g = new boolean[n][m]; for (int i = 1; i < n - 1 && k > 1; ++i) for (int j = 1; j <= m / 2 && k > 1; ++j, k -= 2) { g[i][j] = g[i][m - 1 - j] = true; if (j == m - 1 - j) ++k; } if (k % 2 != 0) { for (int i = 1; i < n; ++i) if (!g[i][m / 2]) { g[i][m / 2] = true; break; } } out.println("YES"); print(g, out); } private void print(boolean[][] g, PrintWriter out) { for (boolean[] row : g) { for (boolean ij : row) if (ij) out.print('#'); else out.print('.'); out.println(); } } } static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
1df4c1229999908ad90f0940bfda458d
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; 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; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); char[][] grid = new char[4][n]; for (int i = 0; i < 4; i++) { Arrays.fill(grid[i], '.'); } if (k % 2 == 0) { for (int j = 1; j <= 2; j++) { for (int a = 1; a <= (k / 2); a++) { grid[j][a] = '#'; } } } else if (k <= (n - 2)) { for (int j = 1; j <= k; j++) { grid[1][(n - k - 2) / 2 + j] = '#'; } } else { k--; grid[2][n - 2] = '#'; for (int j = 1; j <= 2; j++) { for (int a = 1; a <= n - 2; a++) { if (k == 0) break; grid[j][a] = '#'; k--; } } } out.println("YES"); for (int i = 0; i < 4; i++) { out.println(new String(grid[i])); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
c2ac4f87af391d41a68cd72e71d45571
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.Scanner; public class A11 { public static void main (String[] args) { //code Scanner sc = new Scanner(System.in); int n=sc.nextInt(); int k =sc.nextInt(); char[][] ar = new char[4][n]; for(int i=0;i<4;i++) for(int j=0;j<n;j++) ar[i][j]='.'; if(k%2==0) { for(int i=1;i<n-1;i++) for(int j=1;j<3;j++) if(k>0) {ar[j][i]='#';k--;} } else if(k<=n-2) { for(int i=n/2-k/2;i<=n/2+k/2;i++) { ar[1][i]='#'; } } else { for(int i = 1;i < n-1;i++){ ar[1][i] = '#'; ar[2][i] = '#'; } k = 2*(n-2)-k; for(int i = n/2-k/2;i <= n/2+k/2;i++){ ar[2][i] = '.'; } } System.out.println("YES"); for(int i=0;i<4;i++) { for(int j=0;j<n;j++) System.out.print(ar[i][j]); System.out.println(); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
adb479b1f6c299064b3d353c59ca7f83
train_004.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class b{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int k = scan.nextInt(); char[][] mat = new char[4][n]; if(k%2==0){ for(int i=0;i<n;++i)mat[0][i]=mat[3][i]='.'; mat[1][0]=mat[2][0]='.'; for(int i=0;i<(k/2);++i)mat[1][i+1]=mat[2][i+1]='#'; for(int i=1+k/2;i<n;++i)mat[1][i]=mat[2][i]='.'; System.out.println("YES"); for(int i=0;i<4;++i){ for(int j=0;j<n;++j)System.out.print(mat[i][j]); System.out.println(); } }else{ if(k<n-2){ for(char[] c : mat)Arrays.fill(c, '.'); for(int i=n/2-k/2;i<=n/2+k/2;++i)mat[1][i]='#'; }else{ for(int i=0;i<n;++i)mat[0][i]=mat[3][i]=mat[2][i]='.'; mat[1][0]=mat[2][0]=mat[1][n-1]=mat[2][n-1]='.'; for(int i=0;i<n-2;++i)mat[1][i+1]='#'; if(k>n-2){ mat[2][1]=mat[2][n-2]='#'; for(int i=0;i<k-n;++i)mat[2][2+i]='#'; } } System.out.println("YES"); for(int i=0;i<4;++i){ for(int j=0;j<n;++j)System.out.print(mat[i][j]); System.out.println(); } } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
1a7e262efd0f6de62bca400a3d2ae755
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
//package geometry; import java.io.*; import java.util.*; import java.util.Map.Entry; import java.text.*; import java.math.*; import java.util.regex.*; import java.awt.Point; /** * * @author prabhat // use stringbuilder,TreeSet, priorityQueue */ public class point4{ public static long[] BIT; public static long[] tree; public static long[] sum; public static int mod=1000000007; public static int[][] dp; public static boolean[][] isPalin; public static int max1=1000010; public static int[][] g; public static LinkedList<Pair> l[]; public static int n,m,q,k,t,a[],b[],arr[],cnt[],chosen[],pos[],val[],blocksize,count; public static long V[],low,high,min=Long.MAX_VALUE,cap[],has[],ans,max,pre[]; public static ArrayList<Integer> adj[],al; public static TreeSet<Integer> ts; public static char s[]; public static int depth,mini,maxi; public static boolean visit[][],isPrime[],used[]; public static int[][] dist; public static ArrayList<Integer>prime; public static int[] x={0,1}; public static int[] y={-1,0}; public static ArrayList<Integer> divisor[]=new ArrayList[1500005]; public static int[][] subtree,parent,mat; public static TreeMap<Integer,Integer> tm; public static LongPoint[] p; public static int[][] grid,memo; public static ArrayList<Pair> list; public static TrieNode root; public static LinkedHashMap<String,Integer> map; public static ArrayList<String> al1; public static int upper=(int)(1e7); public static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception { InputReader in = new InputReader(System.in); PrintWriter pw=new PrintWriter(System.out); n=in.ii(); k=in.ii()+in.ii(); a=in.iia(n); b=in.iia(n); PriorityQueue<Integer> pq=new PriorityQueue<>((i1,i2)->i2-i1); for(int i=0;i<n;i++)pq.add(Math.abs(a[i]-b[i])); long sum=0; for(int i=0;i<k;i++) { int y=pq.poll(); if(y==0)pq.add(1); else pq.add(y-1); } for(int i:pq) { sum+=1L*i*i; } pw.println(sum); /* n=in.ii(); long ans=0; Point[] p=new Point[n]; for(int i=0;i<n;i++) { p[i]=new Point(in.ii(),in.ii()); } for(int i=0;i<n;i++) { if(orient(p[i],p[(i+1)%n],p[(i+2)%n])<0)ans++; } pw.println(ans);*/ pw.close(); } static void Seive() { isPrime=new boolean[upper+1]; Arrays.fill(isPrime,false); for(int i=2;i<=(upper);i++) { if(!isPrime[i]) { for(int j=1;j*i<=upper;j++) { isPrime[j*i]=true; pre[i]+=cnt[j*i]; } } } } static int orient(Point a,Point b,Point c) { //return (int)(c.x-a.x)*(int)(b.y-a.y)-(int)(c.y-a.y)*(int)(b.x-a.x); Point p1=c.minus(a); Point p2=b.minus(a); return (int)(p1.cross(p2)); } public static class Polygon { static final double EPS = 1e-15; public int n; public Point p[]; Polygon(int n, Point x[]) { this.n = n; p = Arrays.copyOf(x, n); } long area(){ //returns 2 * area long ans = 0; for(int i = 1; i + 1 < n; i++) ans += p[i].minus(p[0]).cross(p[i + 1].minus(p[0])); return ans; } boolean PointInPolygon(Point q) { boolean c = false; for (int i = 0; i < n; i++){ int j = (i+1)%n; if ((p[i].y <= q.y && q.y < p[j].y || p[j].y <= q.y && q.y < p[i].y) && q.x < p[i].x + (p[j].x - p[i].x) * (q.y - p[i].y) / (p[j].y - p[i].y)) c = !c; } return c; } // determine if point is on the boundary of a polygon boolean PointOnPolygon(Point q) { for (int i = 0; i < n; i++) if (ProjectPointSegment(p[i], p[(i+1)%n], q).dist(q) < EPS) return true; return false; } // project point c onto line segment through a and b Point ProjectPointSegment(Point a, Point b, Point c) { double r = b.minus(a).dot(b.minus(a)); if (Math.abs(r) < EPS) return a; r = c.minus(a).dot(b.minus(a))/r; if (r < 0) return a; if (r > 1) return b; return a.plus(b.minus(a).mul(r)); } } public static class Point { public double x, y; public Point(double x, double y) { this.x = x; this.y = y; } public Point minus(Point b) { return new Point(x - b.x, y - b.y); } public Point plus(Point a){ return new Point(x + a.x, y + a.y); } public double cross(Point b) { return (double)x * b.y - (double)y * b.x; } public double dot(Point b) { return (double)x * b.x + (double)y * b.y; } public Point mul(double r){ return new Point(x * r, y * r); } public double dist(Point p){ return Math.sqrt(fastHypt( x - p.x , y - p.y)); } public double fastHypt(double x, double y){ return x * x + y * y; } } static class Query implements Comparable<Query>{ int index,k; int L; int R; public Query(){} public Query(int a,int b,int index) { this.L=a; this.R=b; this.index=index; } public int compareTo(Query o) { if(L/blocksize!=o.L/blocksize)return L/blocksize-o.L/blocksize; else return R-o.R; } } static double dist(Point p1,Point p2) { return Math.sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } static class coder { int indx; String name; coder(int indx,String name) { this.indx=indx; this.name=name; } } static class TrieNode { int value; // Only used in leaf nodes int freq; TrieNode[] arr = new TrieNode[2]; public TrieNode() { value = 0; freq=0; arr[0] = null; arr[1] = null; } } static void insert(int pre_xor,int add) { TrieNode temp = root; // Start from the msb, insert all bits of // pre_xor into Trie for (int i=31; i>=0; i--) { // Find current bit in given prefix int val = (pre_xor & (1<<i)) >=1 ? 1 : 0; // Create a new node if needed if (temp.arr[val] == null) temp.arr[val] = new TrieNode(); temp = temp.arr[val]; temp.freq+=add; } // Store value at leaf node //temp.value = pre_xor; } static long query(int pre_xor) { TrieNode temp = root; long ans=0; for (int i=31; i>=0; i--) { // Find current bit in given prefix int val = (pre_xor & (1<<i)) >= 1 ? 1 : 0; if(temp.arr[1-val]!=null&&temp.arr[1-val].freq>0) { ans|=1l<<i; temp=temp.arr[1-val]; } else if(temp.arr[val]!=null&&temp.arr[val].freq>0) temp=temp.arr[val]; else break; } return ans; } static void update(int indx,long val) { while(indx<max1) { BIT[indx]+=val; indx+=(indx&(-indx)); } } static long query1(int indx) { long sum=0; while(indx>0) { sum+=BIT[indx]; indx-=(indx&(-indx)); } return sum; } static int gcd(int a, int b) { int res=0; while(a!=0) { res=a; a=b%a; b=res; } return b; } static slope getSlope(Point p, Point q) { int dx = (int)(q.x - p.x), dy = (int)(q.y - p.y); int g = gcd(dx, dy); return new slope(dy / g, dx / g); } static class slope implements Comparable<slope> { int x,y; public slope(int y,int x) { this.x=x; this.y=y; } public int compareTo(slope s) { if(s.y!=y)return y-s.y; return x-s.x; } } static class Ball implements Comparable { int r; int occ; public Ball(int r,int occ) { this.r = r; this.occ = occ; } @Override public int compareTo(Object o) { Ball b = (Ball) o; return b.occ-this.occ; } } static class E implements Comparable<E>{ int x,y; char c; E(int x,int y,char c) { this.x=x; this.y=y; this.c=c; } public int compareTo(E o) { if(x!=o.x)return o.x-x; else return y-o.y; } } static ArrayList<String> dfs(String s,String[] sarr,HashMap<String, ArrayList<String>> map) { if(map.containsKey(s))return map.get(s); ArrayList<String> res=new ArrayList<>(); if(s.length()==0) { res.add(""); return res; } for(String word:sarr) { if(s.startsWith(word)) { ArrayList<String > sub=dfs(s.substring(word.length()),sarr,map); for(String s2:sub) { res.add(word+ (s2.isEmpty() ? "" : " ")+s2); } } } map.put(s,res); return res; } static class SegmentTree{ int n; int max_bound; public SegmentTree(int n) { this.n=n; tree=new long[4*n+1]; build(1,0,n-1); } void build(int c,int s,int e) { if(s==e) { tree[c]=arr[s]; return ; } int mid=(s+e)>>1; build(2*c,s,mid); build(2*c+1,mid+1,e); tree[c]=(tree[2*c]&tree[2*c+1]); } void put(int c,int s, int e,int l,int r,int v) { if(l>e||r<s||s>e)return ; if (s == e) { tree[c] = arr[s]^v; return; } int mid = (s + e) >> 1; if (l>mid) put(2*c+1,m+1, e , l,r, v); else if(r<=mid)put(2*c,s,m,l,r , v); else{ } } long query(int c,int s,int e,int l,int r) { if(e<l||s>r)return 0L; if(s>=l&&e<=r) { return tree[c]; } int mid=(s+e)>>1; long ans=(1l<<30)-1; if(l>mid)return query(2*c+1,mid+1,e,l,r); else if(r<=mid)return query(2*c,s,mid,l,r); else{ return query(2*c,s,mid,l,r)&query(2*c+1,mid+1,e,l,r); } } } public static ListNode removeNthFromEnd(ListNode a, int b) { int cnt=0; ListNode ra1=a; ListNode ra2=a; while(ra1!=null){ra1=ra1.next; cnt++;} if(b>cnt)return a.next; else if(b==1&&cnt==1)return null; else{ int y=cnt-b+1; int u=0; ListNode prev=null; while(a!=null) { u++; if(u==y) { if(a.next==null)prev.next=null; else { if(prev==null)return ra2.next; prev.next=a.next; a.next=null; } break; } prev=a; a=a.next; } } return ra2; } static ListNode rev(ListNode a) { ListNode prev=null; ListNode cur=a; ListNode next=null; while(cur!=null) { next=cur.next; cur.next=prev; prev=cur; cur=next; } return prev; } static class ListNode { public int val; public ListNode next; ListNode(int x) { val = x; next = null; } } public static String add(String s1,String s2) { int n=s1.length()-1; int m=s2.length()-1; int rem=0; int carry=0; int i=n; int j=m; String ans=""; while(i>=0&&j>=0) { int c1=(int)(s1.charAt(i)-'0'); int c2=(int)(s2.charAt(j)-'0'); int sum=c1+c2; sum+=carry; rem=sum%10; carry=sum/10; ans=rem+ans; i--; j--; } while(i>=0) { int c1=(int)(s1.charAt(i)-'0'); int sum=c1; sum+=carry; rem=sum%10; carry=sum/10; ans=rem+ans; i--; } while(j>=0) { int c2=(int)(s2.charAt(j)-'0'); int sum=c2; sum+=carry; rem=sum%10; carry=sum/10; ans=rem+ans; j--; } if(carry>0)ans=carry+ans; return ans; } public static String[] multiply(String A, String B) { int lb=B.length(); char[] a=A.toCharArray(); char[] b=B.toCharArray(); String[] s=new String[lb]; int cnt=0; int y=0; String s1=""; q=0; for(int i=b.length-1;i>=0;i--) { int rem=0; int carry=0; for(int j=a.length-1;j>=0;j--) { int mul=(int)(b[i]-'0')*(int)(a[j]-'0'); mul+=carry; rem=mul%10; carry=mul/10; s1=rem+s1; } s1=carry+s1; s[y++]=s1; q=Math.max(q,s1.length()); s1=""; for(int i1=0;i1<y;i1++)s1+='0'; } return s; } public static long nCr(long total, long choose) { if(total < choose) return 0; if(choose == 0 || choose == total) return 1; return nCr(total-1,choose-1)+nCr(total-1,choose); } static int get(long s) { int ans=0; for(int i=0;i<n;i++) { if(p[i].x<=s&&s<=p[i].y)ans++; } return ans; } static class LongPoint { public long x; public long y; public LongPoint(long x, long y) { this.x = x; this.y = y; } public LongPoint subtract(LongPoint o) { return new LongPoint(x - o.x, y - o.y); } public long cross(LongPoint o) { return x * o.y - y * o.x; } } static int CountPs(String s,int n) { boolean b=false; char[] S=s.toCharArray(); int[][] dp=new int[n][n]; boolean[][] p=new boolean[n][n]; for(int i=0;i<n;i++)p[i][i]=true; for(int i=0;i<n-1;i++) { if(S[i]==S[i+1]) { p[i][i+1]=true; dp[i][i+1]=0; b=true; } } for(int gap=2;gap<n;gap++) { for(int i=0;i<n-gap;i++) { int j=gap+i; if(S[i]==S[j]&&p[i+1][j-1]){p[i][j]=true;} if(p[i][j]) dp[i][j]=dp[i][j-1]+dp[i+1][j]+1-dp[i+1][j-1]; else if(!p[i][j]) dp[i][j]=dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]; //if(dp[i][j]>=1) // return true; } } // return b; return dp[0][n-1]; } static long divCeil(long a,long b) { return (a+b-1)/b; } static long root(int pow, long x) { long candidate = (long)Math.exp(Math.log(x)/pow); candidate = Math.max(1, candidate); while (pow(candidate, pow) <= x) { candidate++; } return candidate-1; } static long pow(long x, int pow) { long result = 1; long p = x; while (pow > 0) { if ((pow&1) == 1) { if (result > Long.MAX_VALUE/p) return Long.MAX_VALUE; result *= p; } pow >>>= 1; if (pow > 0 && p >= 4294967296L) return Long.MAX_VALUE; p *= p; } return result; } static boolean valid(int i,int j) { if(i>=0&&i<n&&j>=0&&j<m)return true; return false; } private static class DSU{ int[] parent; int[] rank; int cnt; public DSU(int n){ parent=new int[n]; rank=new int[n]; for(int i=0;i<n;i++){ parent[i]=i; rank[i]=1; } cnt=n; } int find(int i){ while(parent[i] !=i){ parent[i]=parent[parent[i]]; i=parent[i]; } return i; } int Union(int x, int y){ int xset = find(x); int yset = find(y); if(xset!=yset) cnt--; if(rank[xset]<rank[yset]){ parent[xset] = yset; rank[yset]+=rank[xset]; rank[xset]=0; return yset; }else{ parent[yset]=xset; rank[xset]+=rank[yset]; rank[yset]=0; return xset; } } } public static int[][] packU(int n, int[] from, int[] to, int max) { int[][] g = new int[n][]; int[] p = new int[n]; for (int i = 0; i < max; i++) p[from[i]]++; for (int i = 0; i < max; i++) p[to[i]]++; for (int i = 0; i < n; i++) g[i] = new int[p[i]]; for (int i = 0; i < max; i++) { g[from[i]][--p[from[i]]] = to[i]; g[to[i]][--p[to[i]]] = from[i]; } return g; } public static int[][] parents3(int[][] g, int root) { int n = g.length; int[] par = new int[n]; Arrays.fill(par, -1); int[] depth = new int[n]; depth[0] = 0; int[] q = new int[n]; q[0] = root; for (int p = 0, r = 1; p < r; p++) { int cur = q[p]; for (int nex : g[cur]) { if (par[cur] != nex) { q[r++] = nex; par[nex] = cur; depth[nex] = depth[cur] + 1; } } } return new int[][]{par, q, depth}; } public static int lower_bound(int[] nums, int target) { int low = 0, high = nums.length - 1; while (low < high) { int mid = low + (high - low) / 2; if (nums[mid] < target) low = mid + 1; else high = mid; } return nums[low] == target ? low : -1; } public static int upper_bound(int[] nums, int target) { int low = 0, high = nums.length - 1; while (low < high) { int mid = low + (high + 1 - low) / 2; if (nums[mid] > target) high = mid - 1; else low = mid; } return nums[low] == target ? low : -1; } public static boolean palin(String s) { int i=0; int j=s.length()-1; while(i<j) { if(s.charAt(i)==s.charAt(j)) { i++; j--; } else return false; } return true; } static int lcm(int a,int b) { return (a*b)/(gcd(a,b)); } public static long pow(long n,long p,long m) { long result = 1; if(p==0) return 1; while(p!=0) { if(p%2==1) result *= n; if(result>=m) result%=m; p >>=1; n*=n; if(n>=m) n%=m; } return result; } /** * * @param n * @param p * @return */ public static long pow(long n,long p) { long result = 1; if(p==0) return 1; if (p==1) return n; while(p!=0) { if(p%2==1) result *= n; p >>=1; n*=n; } return result; } static class Edge implements Comparator<Edge> { private int u; private int v; private long w; public Edge() { } public Edge(int u, int v, long w) { this.u=u; this.v=v; this.w=w; } public int getU() { return u; } public void setU(int u) { this.u = u; } public int getV() { return v; } public void setV(int v) { this.v = v; } public long getW() { return w; } public void setW(int w) { this.w = w; } public long compareTo(Edge e) { return (this.getW() - e.getW()); } @Override public int compare(Edge o1, Edge o2) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } } static class Pair implements Comparable<Pair> { int x,y; Pair (int a,int b) { this.x=a; this.y=b; } public int compareTo(Pair o) { // TODO Auto-generated method stub if(this.x!=o.x) return -Integer.compare(this.x,o.x); else return -Integer.compare(this.y, o.y); //return 0; } public boolean equals(Object o) { if (o instanceof Pair) { Pair p = (Pair)o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private SpaceCharFilter filter; byte inbuffer[] = new byte[1024]; int lenbuffer = 0, ptrbuffer = 0; final int M = (int) 1e9 + 7; int md=(int)(1e7+1); int[] SMP=new int[md]; final double eps = 1e-6; final double pi = Math.PI; PrintWriter out; String check = ""; InputStream obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes()); public InputReader(InputStream stream) { this.stream = stream; } int readByte() { if (lenbuffer == -1) throw new InputMismatchException(); if (ptrbuffer >= lenbuffer) { ptrbuffer = 0; try { lenbuffer = obj.read(inbuffer); } catch (IOException e) { throw new InputMismatchException(); } } if (lenbuffer <= 0) return -1; return inbuffer[ptrbuffer++]; } public int read() { 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; } String is() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ') { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int ii() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long il() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } boolean isSpaceChar(int c) { return (!(c >= 33 && c <= 126)); } int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } float nf() { return Float.parseFloat(is()); } double id() { return Double.parseDouble(is()); } char ic() { return (char) skip(); } int[] iia(int n) { int a[] = new int[n]; for (int i = 0; i<n; i++) a[i] = ii(); return a; } long[] ila(int n) { long a[] = new long[n]; for (int i = 0; i <n; i++) a[i] = il(); return a; } String[] isa(int n) { String a[] = new String[n]; for (int i = 0; i < n; i++) a[i] = is(); return a; } long mul(long a, long b) { return a * b % M; } long div(long a, long b) { return mul(a, pow(b, M - 2)); } double[][] idm(int n, int m) { double a[][] = new double[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id(); return a; } int[][] iim(int n, int m) { int a[][] = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii(); return a; } public String readLine() { 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 interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
7e13d59717a3eb40be306b911b19ea2d
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.IOException; import java.util.PriorityQueue; public class Main{ public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); String nk[] = br.readLine().split(" "); PriorityQueue<Long> pq = new PriorityQueue<Long>(); int n = Integer.parseInt(nk[0]); int k1 = Integer.parseInt(nk[1]); int k2 = Integer.parseInt(nk[2]); String s1[] = br.readLine().split(" "); String s2[] = br.readLine().split(" "); long x,y; for(int i = 0; i<n;i++){ x = Integer.parseInt(s1[i]); y = Integer.parseInt(s2[i]); pq.add(Math.abs(x-y)*-1); } while(k1>0){ x = pq.poll(); pq.add(Math.abs(x+1)*-1); k1--; } while(k2>0){ x = pq.poll(); pq.add(Math.abs(x+1)*-1); k2--; } long ans = 0; while(pq.size()>0){ x = pq.poll(); ans+=(x*x); } out.println(ans); out.close(); } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
f679754d50e93ddf338e5f884b17d89f
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int K = sc.nextInt() + sc.nextInt(); long A[] = new long[N]; long B[] = new long[N]; for(int i=0;i<N;i++){ A[i] = sc.nextLong(); } for(int i=0;i<N;i++){ B[i] = Math.abs(A[i]-sc.nextLong()); } Arrays.sort(B); for(int i=0;K>0;i++){ if(B[N-1]>0){ B[N-1]--; } else{ B[N-1]++; } Arrays.sort(B); K--; } long ans=0; for(int i=0;i<N;i++){ ans = ans + (B[i])*(B[i]); } System.out.println(ans); } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
21959b7f64854b2f9ec5f58cb33b3c78
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.fill; import static java.lang.Math.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; public class B960 { public static int mod = 1000000007; public static long INF = (1L << 60); static FastScanner2 in = new FastScanner2(); static OutputWriter out = new OutputWriter(System.out); static class Pair implements Comparable<Pair> { int a,b; int diff; Pair(int a,int b) { this.a=a; this.b=b; this.diff=abs(a-b); } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return -(this.diff-o.diff); } } public static void main(String[] args) { int n=in.nextInt(); int k1=in.nextInt(); int k2=in.nextInt(); int[] a1=new int[n+1]; for(int i=1;i<=n;i++) { a1[i]=in.nextInt(); } int[] a2=new int[n+1]; for(int i=1;i<=n;i++) { a2[i]=in.nextInt(); } PriorityQueue<Integer> heap=new PriorityQueue<>(10,Collections.reverseOrder()); for(int i=1;i<=n;i++) { heap.add(abs(a1[i]-a2[i])); } int K=k1+k2; boolean flag=false; while(!heap.isEmpty() && K>0) { int p=heap.poll(); if(p==0) { flag=true; break; } heap.add(p-1); K--; } if(flag) { System.out.println((K%2==0)?0:1); return; } long ans=0; while(!heap.isEmpty()) { int p=heap.poll(); ans+=(long)p*(long)p; } out.println(ans); out.close(); } static class FastScanner2 { private byte[] buf = new byte[1024]; private int curChar; private int snumChars; public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 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 nextString() { 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 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 int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } private static boolean oj = System.getProperty("ONLINE_JUDGE") != null; private static void debug(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } private static void tr(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
65b5791723fc151084405b836e05a8b8
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.awt.image.AreaAveragingScaleFilter; import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main { BufferedReader br; StringTokenizer in; PrintWriter pw; Random r; int INF = (int) 1e9; long LNF = (long) 1e18; long mod = (long) (1e9 + 7); int pp = 27; // you shall not hack!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // /*\ // /// /^\ // /// ~~~~ (___) // /// ~~~~~~~~ \\__ // _/_/_ ~/ .& . \~ \\ \ // [____] ~| (__) |~/ \\/ // /_/\ \~|~~~~~~~~~~ /\\ // \ ~~~~~~~~~~ _/ \\ // \ _ ~~ _/\ \\ // / | / \ \\ // | / | \ \\ // / / ___ | \ // /___| | __| |_______\ // _| | | |_ // |____| |____| // P.S this is omnipotent Gandalf ArrayList<Integer> g[]; int n; double eps = 1e-9; void end(String a) { pw.print(a); pw.close(); System.exit(0); } int m = (int) (1e6 + 5 * 1e5); void solve() throws IOException { n = nextInt(); int k1 = nextInt(); int k2 = nextInt(); pair d[] = new pair[n]; int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } TreeSet<pair> g = new TreeSet<>(); for (int i = 0; i < n; i++) { b[i] = nextInt(); d[i] = new pair(Math.abs(a[i] - b[i]), i); g.add(d[i]); } for (int i = 0; i < k1 + k2; i++) { pair p = g.pollLast(); if (p.a == 0) { g.add(p); pair q = g.pollFirst(); q.a = abs(q.a - 1); g.add(q); } else { p.a--; g.add(p); } } long ans = 0; for (pair p : g) { ans += (long)p.a * (long)p.a; } pw.print(ans); } class pair implements Comparable<pair> { int a; int b; public pair(int aa, int bb) { a = aa; b = bb; } @Override public int compareTo(pair o) { if (a != o.a) return a - o.a; return b - o.b; } } String nextToken() throws IOException { while (in == null || !in.hasMoreTokens()) { in = new StringTokenizer(br.readLine()); } return in.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } public void run() throws IOException { r = new Random(5); // br = new BufferedReader(new FileReader("input.txt")); // pw = new PrintWriter(new FileWriter("output.txt")); br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new OutputStreamWriter(System.out)); // br = new BufferedReader(new FileReader("railroad.in")); // pw = new PrintWriter(new FileWriter("railroad.out")); solve(); // z(); pw.close(); } public static void main(String[] args) throws IOException { new Main().run(); } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
0e580cddcb968be9d5a5d843e533e538
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.PriorityQueue; import java.util.StringTokenizer; public class CF_960_B_MINIMIZE_THE_ERROR { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k1 = sc.nextInt(); int k2 = sc.nextInt(); int[] a = new int[n]; int[] b = new int[n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); for (int i = 0; i < n; i++) b[i] = sc.nextInt(); PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder()); for (int i = 0; i < n; i++) pq.add(Math.abs(a[i] - b[i])); for (int i = 0; i < k1 + k2; i++) { int element = pq.poll(); if (element == 0) element++; else element--; pq.add(element); } long res = 0; while (!pq.isEmpty()) res += Math.pow(pq.poll(), 2); System.out.println(res); } static class Pair implements Comparable<Pair> { int a, b; public Pair(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(Pair p) { return Math.abs(p.a - p.b) - Math.abs(this.a - this.b); } @Override public String toString() { return "(" + this.a + " ," + this.b + ")"; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
bf5b606ddd258c6e727476ded6538383
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
//package uva; import java.util.*; import java.io.*; public class Uva { public static void main(String arg[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); int k1 = Integer.parseInt(st.nextToken()); int k2 = Integer.parseInt(st.nextToken()); int A[] = new int[N]; int B[] = new int[N]; st = new StringTokenizer(br.readLine()); for(int i=0;i<N;i++){ A[i] = Integer.parseInt(st.nextToken()); } st = new StringTokenizer(br.readLine()); for(int i=0;i<N;i++){ B[i] = Integer.parseInt(st.nextToken()); } PriorityQueue<Integer> q = new PriorityQueue(new Comparator<Integer>(){ @Override public int compare(Integer a,Integer b){ return b-a; } }); for(int i=0;i<N;i++){ q.add(Math.abs(A[i]-B[i])); } int K = k1+k2; for(int i=0;i<K;i++){ int a = q.poll(); if(a>0) a--; else a++; q.add(a); } long total = 0; while(q.size()>0){ int a = q.poll(); total += (long)a*a; } System.out.println(total); } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
a928a21b5addbf00bdbd771c1b5d409d
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class b960 { static class delta implements Comparable<delta>{ int d; int a; int b; long sqr; public int compareTo(delta d) { if (this.sqr<d.sqr) { return 1; } else if (this.sqr>d.sqr) { return -1; } else { return 0; } } } public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k1 = sc.nextInt(); int k2 = sc.nextInt(); int[] a = new int[n]; for(int i=0; i<n; i++) { a[i]=sc.nextInt(); } int[] b = new int[n]; delta[] c = new delta[n]; for(int i=0; i<n; i++) { b[i]=sc.nextInt(); c[i]=new delta(); c[i].sqr=(long)(a[i]-b[i])*(long)(a[i]-b[i]); c[i].a=a[i]; c[i].b=b[i]; } Arrays.sort(c); int i=0; do { if (c[i].a>c[i].b) { if (k1>0) { c[i].a-=1; k1-=1; } else if (k2>0) { c[i].b+=1; k2-=1; } c[i].sqr=(long)(c[i].a-c[i].b)*(long)(c[i].a-c[i].b); Arrays.sort(c); } else if (c[i].a<c[i].b) { if (k1>0) { c[i].a+=1; k1-=1; } else if (k2>0) { c[i].b-=1; k2-=1; } c[i].sqr=(long)(c[i].a-c[i].b)*(long)(c[i].a-c[i].b); Arrays.sort(c); } else { i+=1; } } while(i<n && (k1>0 || k2>0)); int f=1; while(k1>0 || k2>0) { if (k1>0) { c[n-1].a+=f; k1-=1; } else if (k2>0) { c[n-1].b+=-f; k2-=1; } c[n-1].sqr=(long)(c[n-1].a-c[n-1].b)*(long)(c[n-1].a-c[n-1].b); f*=-1; } long s=0; for(int j=0; j<n; j++) { s+=c[j].sqr; } System.out.println(s); } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
581e7c52d79874e45744d5f9a563ab52
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.util.*; public class Solution { static int search(int arr[] , long key) { int l = 0 , r = arr.length - 2; while(l <= r) { int mid = (l+r)/2; if(key >= arr[mid]) l = mid + 1; else r = mid - 1; } return l; } public static void main(String []args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k1 = sc.nextInt(); int k2 = sc.nextInt(); int k = k1 + k2; long a[] = new long[n]; for(int i = 0 ; i < n ; i++) { a[i] = sc.nextLong(); } long arr[] = new long[n]; for(int i = 0 ; i < n ; i++) { long b = sc.nextLong(); arr[i] = Math.abs(a[i] - b); } while(k > 0) { long max = arr[0]; int pos = 0; for(int i = 0 ; i < n ; i++) { if(arr[i] > max) { max = arr[i]; pos = i; } } if(max != 0) { arr[pos]--; k--; } else break; } if(k != 0) { if(k % 2 == 0) System.out.println(0); else System.out.println(1); } else { long sum = 0; for(int i = 0 ; i < n ; i++) { sum = sum + (arr[i] * arr[i]); } System.out.println(sum); } } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
fca99a3f6e4cbc76254c581cf5682f08
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.PriorityQueue; public class CF_428_DIV2_B { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader (new InputStreamReader(System.in)); int n, c; String[] line = input.readLine().split(" "); n = Integer.parseInt(line[0]); c = Integer.parseInt(line[2]) + Integer.parseInt(line[1]); PriorityQueue<Long> pq = new PriorityQueue<>((a, b) -> { return (int) (b - a); }); long[] A = new long[n]; line = input.readLine().split(" "); for (int i = 0; i < n; i++) { A[i] = Long.parseLong(line[i]); } long[] B = new long[n]; line = input.readLine().split(" "); for (int i = 0; i < n; i++) { B[i] = Long.parseLong(line[i]); } for (int i = 0; i < n; i++) { pq.add(Math.abs(A[i] - B[i])); } long tmp; for (int i= 0, iter = c; i < iter; i++) { tmp = pq.poll(); if (tmp == 0) { break; } pq.add(tmp - 1); c--; } long e = c%2; for (long i : pq) { e += (i*i); } System.out.println(e); input.close(); } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
3942ea71ecf7e8d2d87d02a949604294
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.PriorityQueue; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.Comparator; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { int toggle(int val) { if (val == 0) return 1; return val - 1; } public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.readInt(); int k = in.readInt() + in.readInt(); int[] a = IOUtils.readIntArray(in, n); int[] b = IOUtils.readIntArray(in, n); PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.reverseOrder()); for (int i = 0; i < a.length; i++) { pq.add(Math.abs(a[i] - b[i])); } for (int i = 0; i < k; i++) { int largest = pq.poll(); pq.add(toggle(largest)); } long res = 0; for (int val : pq) { res += (long) val * val; } out.printLine(res); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = in.readInt(); } return array; } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void printLine(long i) { writer.println(i); } } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
a64c7af85e0e0d56354338ab67b563b8
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { TaskB Solver = new TaskB(); Solver.Solve(); } private static class TaskB { private void Solve() { Scanner in = new Scanner(System.in); int n = in.nextInt(); long k1 = in.nextLong(); long k2 = in.nextLong(); long a[] = new long[n]; long b[] = new long[n]; long df[] = new long[n]; for (int i = 0; i < n; i++) a[i] = in.nextLong(); for (int i = 0; i < n; i++) { b[i] = in.nextLong(); df[i] = Math.abs(a[i] - b[i]); } Arrays.sort(df); long s = k1 + k2; boolean ok = false; while (s > 0) { boolean fl = false; for (int i = 0; i < n; i++) { if (df[i] > 0) { fl = true; break; } } if (!fl) { ok = true; break; } long max = df[0]; int indx = 0; for (int j = 1; j < n; j++) if (df[j] > max) { max = df[j]; indx = j; } df[indx]--; s--; } if (ok) System.out.println(s % 2); else { long ans = 0; if ((s != 0) && (s % 2 == 1)) ans++; for (int i = 0; i < n; i++) ans += Math.pow(df[i], 2); System.out.println(ans); } } } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
58eb8567a13c63a0f2675b4f8652f9e2
train_004.jsonl
1523117100
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.util.Arrays; import java.io.IOException; import java.io.InputStreamReader; import java.io.FileNotFoundException; import java.util.StringTokenizer; import java.io.Writer; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Asgar Javadov */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); int k1 = in.nextInt(); int k2 = in.nextInt(); int[] a = in.readIntArray(n); int[] b = in.readIntArray(n); int count = k1 + k2; int[] c = new int[n]; for (int i = 0; i < n; ++i) c[i] = Math.abs(a[i] - b[i]); if (n == 1) { if (c[0] >= k1 + k2) { c[0] -= count; out.println((long) c[0] * c[0]); return; } else if (c[0] % 2 == count % 2) { out.println(0); } else out.println(1); return; } Arrays.sort(c); ArrayUtils.reverse(c, 0, c.length - 1); if (c[0] == 0) { if ((k1 + k2) % 2 == 1) { out.println(1); } else { out.println(0); } return; } int i = 0; while (count > 0) { while (count > 0 && i + 1 < c.length && c[i] > c[i + 1]) { --c[i]; --count; } if (c[0] == 0) { out.println(count % 2); return; } int j = 0; while (j + 1 < c.length && c[j] == c[j + 1]) ++j; while (count > 0 && j >= 0) { --c[j]; --count; --j; } } long res = 0L; for (int ci : c) { res += (long) ci * (long) ci; } out.println(res); } } static class ArrayUtils { public static void swap(int[] array, int i, int j) { if (i == j) return; int temp = array[i]; array[i] = array[j]; array[j] = temp; } public static void reverse(int[] array, int from, int end) { while (from < end) { swap(array, from, end); ++from; --end; } } } static class OutputWriter extends PrintWriter { public OutputWriter(OutputStream outputStream) { super(outputStream); } public OutputWriter(Writer writer) { super(writer); } public OutputWriter(String filename) throws FileNotFoundException { super(filename); } public void close() { super.close(); } } static class InputReader extends BufferedReader { StringTokenizer tokenizer; public InputReader(InputStream inputStream) { super(new InputStreamReader(inputStream), 32768); } public InputReader(String filename) { super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename))); } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(readLine()); } catch (IOException e) { throw new RuntimeException(); } } return tokenizer.nextToken(); } public Integer nextInt() { return Integer.valueOf(next()); } public int[] readIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); return array; } } }
Java
["2 0 0\n1 2\n2 3", "2 1 0\n1 2\n2 2", "2 5 7\n3 4\n14 4"]
1 second
["2", "0", "1"]
NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.
Java 8
standard input
[ "data structures", "sortings", "greedy" ]
88d54818fd8bab2f5d0bd8d95ec860db
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.
1,500
Output a single integer — the minimum possible value of after doing exactly k1 operations on array A and exactly k2 operations on array B.
standard output
PASSED
a59f36b3e013e4f09f15732260637bfb
train_004.jsonl
1339506000
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
256 megabytes
import java.util.*; import static java.lang.System.out; import static java.lang.Math.*; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; public class Main { static int mod = 1000000007; static int MOD = 1000000007; static final long M = (int)1e9+7; static class Pair { int first; int second; public Pair(int first, int second) { this.first = first; this.second = second; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String next() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } int[] readArray(int n) throws IOException { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static boolean isPrime(int n) { if(n == 1) { return false; } for(int i = 2;i*i<=n;i++) { if(n%i == 0) { return false; } } return true; } public static int gcd(int a, int b) { if(b == 0) return a; else return gcd(b,a%b); } public static long LongGCD(long a, long b) { if(b == 0) return a; else return LongGCD(b,a%b); } public static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } public static int phi(int n) //euler totient function { int result = 1; for (int i = 2; i < n; i++) if (gcd(i, n) == 1) result++; return result; } public static int[] computePrefix(int arr[], int n) { int[] prefix = new int[n]; prefix[0] = arr[0]; for(int i = 1;i<n;i++) { prefix[i] = prefix[i-1]+arr[i]; } return prefix; } public static int fastPow(int x, int n) //include mod at each step if asked and in args of fn too { if(n == 0) return 1; else if(n%2 == 0) return fastPow(x*x,n/2); else return x*fastPow(x*x,(n-1)/2); } static int LowerBound(int a[], int x) { int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } static int UpperBound(int a[], int x) { int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static int modInverse(int n, int p) { return power(n, p - 2, p); } //Fermat's little theorem for nCr % p. static int nCrModPFermat(int n, int r, int p) { if (n<r) return 0; if (r == 0) return 1; int[] fac = new int[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } public static void Sort(int[] a) { List<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); //Collections.reverse(l); //Use to Sort decreasingly for (int i=0; i<a.length; i++) a[i]=l.get(i); } public static void main(String[] args) throws IOException { Reader sc = new Reader(); int n = sc.nextInt(), m = sc.nextInt(); int[] arr = sc.readArray(n+1); int[] brr = sc.readArray(m+1); if(n > m) { if(arr[0] * brr[0] > 0) { System.out.println("Infinity"); } else { System.out.println("-Infinity"); } } else if(n < m) { System.out.println("0/1"); } else { int one = abs(arr[0]), two = abs(brr[0]); int deno = gcd(one,two); if(arr[0] * brr[0] < 0) { System.out.print("-" + (one/deno) + "/" + (two/deno)); } else { System.out.print((one/deno) + "/" + (two/deno)); } } } }
Java
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
2 seconds
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
Java 11
standard input
[ "math" ]
37cf6edce77238db53d9658bc92b2cab
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
1,400
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
standard output
PASSED
f2b4dc0e34350bb760fb40ab36148c6f
train_004.jsonl
1339506000
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Solution { // Complete the maximumSum function below. public 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 long gcd(long a, long b) { if (b == 0) return a; long r = a % b; return gcd(b, r); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public class ListNode { int val; ListNode next; ListNode() { } ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next; } } public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode() { } TreeNode(int val) { this.val = val; } TreeNode(int val, TreeNode left, TreeNode right) { this.val = val; this.left = left; this.right = right; } } class Node { public int val; public List<Node> children; public Node() { } public Node(int _val) { val = _val; } public Node(int _val, List<Node> _children) { val = _val; children = _children; } } public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader scanner = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); int d1=scanner.nextInt(); int d2=scanner.nextInt(); int d1c[]=new int[d1+1]; int d2c[]=new int[d2+1]; for(int i=0;i<d1+1;i++) d1c[i]=scanner.nextInt(); for(int i=0;i<d2+1;i++) d2c[i]=scanner.nextInt(); if(d1>d2) { if(d1c[0]>0&&d2c[0]>0) w.println("Infinity"); else if(d1c[0]<0&&d2c[0]<0) w.println("Infinity"); else w.println("-Infinity"); } else if(d1<d2) { d1c[0]=0; w.println(Math.abs(d1c[0])+"/"+1); } else { int a= (int) gcd(Math.abs(d2c[0]),Math.abs(d1c[0])); if(a!=1) { d2c[0]/=a; d1c[0]/=a; } if(d1c[0]<0||d2c[0]<0){ if(d1c[0]<0&&d2c[0]<0){ w.println(Math.abs(d1c[0])+"/"+Math.abs(d2c[0])); } else w.println("-"+Math.abs(d1c[0])+"/"+Math.abs(d2c[0])); } else w.println(d1c[0]+"/"+d2c[0]); } w.close(); } }
Java
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
2 seconds
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
Java 11
standard input
[ "math" ]
37cf6edce77238db53d9658bc92b2cab
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
1,400
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
standard output
PASSED
34e796ae5199d2eee27ee7dfa34ada2e
train_004.jsonl
1339506000
You are given two polynomials: P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm. Calculate limit .
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Limits { public static void fraction(StringBuilder sq) { int indexOfdelimiter=sq.indexOf("/"); int numerator = Integer.parseInt((String) sq.subSequence(0, indexOfdelimiter)); int denominator = Integer.parseInt((String) sq.subSequence(indexOfdelimiter+1,sq.length())); int gcd = getGCD(numerator, denominator); String fraction = Math.abs(numerator / gcd) + "/" + Math.abs(denominator / gcd); if (Math.signum(denominator)!=Math.signum(numerator)) fraction="-"+fraction; System.out.println(fraction); } public static int getGCD(int n1, int n2) { if (n2 == 0) { return n1; } return getGCD(n2, n1 % n2); } public static void main(String[] args) throws IOException , NumberFormatException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(br.readLine()); int dN=Integer.parseInt(st.nextToken()), dD=Integer.parseInt(st.nextToken()); st=new StringTokenizer(br.readLine()); int abovec=Integer.parseInt(st.nextToken()); st=new StringTokenizer(br.readLine()); int belowc=Integer.parseInt(st.nextToken()); if (dN!=dD) System.out.println(dN>dD?(((double)abovec/(double)belowc)<0?"-Infinity":"Infinity"):"0/1"); else if (Math.abs(abovec)>Math.abs(belowc)&&(!((double)abovec%belowc!=0.0))&&Math.abs(getGCD(abovec,belowc))==1) System.out.println(Math.signum(abovec)!=Math.signum(belowc)?"-"+Math.abs(abovec)+"/"+Math.abs(belowc):Math.abs(abovec)+""+"/"+Math.abs(belowc)); else if (Math.abs(abovec)<Math.abs(belowc) &&((double) belowc %abovec!=0)&&Math.abs(getGCD(abovec,belowc))==1) System.out.println(Math.signum(abovec)!=Math.signum(belowc)?"-"+Math.abs(abovec)+"/"+Math.abs(belowc):Math.abs(abovec)+"/"+Math.abs(belowc)); else fraction(new StringBuilder().append(abovec).append('/').append(belowc)); } }
Java
["2 1\n1 1 1\n2 5", "1 0\n-1 3\n2", "0 1\n1\n1 0", "2 2\n2 1 6\n4 5 -7", "1 1\n9 0\n-5 2"]
2 seconds
["Infinity", "-Infinity", "0/1", "1/2", "-9/5"]
NoteLet's consider all samples: You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function
Java 11
standard input
[ "math" ]
37cf6edce77238db53d9658bc92b2cab
The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).
1,400
If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q &gt; 0) is the denominator of the fraction.
standard output
PASSED
bb583e7a04aa7fe529fe4f6c84222286
train_004.jsonl
1453388400
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
256 megabytes
//package cf; import java.io.*; import java.util.*; public final class Cf { public static void main(String[] args) throws Exception { BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512); Reader sc = new Reader(); int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++)a[i]=sc.nextInt(); int i=0; HashSet<Integer>set=new HashSet<>(); ArrayList<pair>ans=new ArrayList<>(); while(i<n) { set=new HashSet<>(); for(int j=i;j<n;j++) { // debug(set.contains(a[j])+" "+a[j]); //debug("set is "+set); if(!set.contains(a[j]))set.add(a[j]); else { ans.add(new pair(i+1,j+1)); i=j+1; break; } if(j==n-1)i=n; } } if(ans.size()==0)out.write("-1"); else { out.write(ans.size()+"\n"); for(int j=0;j<ans.size()-1;j++)out.write(ans.get(j).x+" "+ans.get(j).y+"\n"); out.write(ans.get(ans.size()-1).x+" "+n); } out.flush(); } static class pair{ int x,y; pair(int x,int y) { this.x=x; this.y=y; } } /////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////// static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } ////////////////////////////////////////////////////////////////// static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[1002]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) { return; } din.close(); } } public static void debug(String s) { System.out.println(s); } }
Java
["5\n1 2 3 4 1", "5\n1 2 3 4 5", "7\n1 2 1 3 1 2 1"]
2 seconds
["1\n1 5", "-1", "2\n1 3\n4 7"]
null
Java 11
standard input
[ "greedy" ]
4cacec219e4577b255ddf6d39d308e10
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
1,500
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
standard output
PASSED
0dc7d5c7bc87b5335fa921a11ba1b8ec
train_004.jsonl
1453388400
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
256 megabytes
import java.util.*; import java.io.*; public class c { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n = sc.nextInt(); int[] ar = new int[n+1]; List<List<Integer>> li = new ArrayList<>(); int prev = 1; HashMap<Integer, Integer> map = new HashMap<>(); for (int i=1;i<=n;i++) { ar[i] = sc.nextInt(); if (map.containsKey(ar[i])) { ArrayList<Integer> al = new ArrayList<>(); al.add(prev); al.add(i); prev = i+1; li.add(al); map = new HashMap<>(); } else map.put(ar[i], i); } if (li.size() == 0) { System.out.println(-1); return; } li.get(li.size()-1).set(1, n); System.out.println(li.size()); for (List<Integer> al : li) { System.out.println(al.get(0) + " " + al.get(1)); } out.close(); } 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
["5\n1 2 3 4 1", "5\n1 2 3 4 5", "7\n1 2 1 3 1 2 1"]
2 seconds
["1\n1 5", "-1", "2\n1 3\n4 7"]
null
Java 11
standard input
[ "greedy" ]
4cacec219e4577b255ddf6d39d308e10
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
1,500
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
standard output
PASSED
28fcd376a14f519773413cace3097dbd
train_004.jsonl
1453388400
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class C { public static void process(int test_number)throws IOException { int n = ni(), l = 1, r, cnt = 0; TreeSet<Integer> set = new TreeSet<Integer>(); ArrayList<Integer[]> li = new ArrayList<>(); for(int i = 1; i <= n; i++){ int x = ni(); if(set.contains(x)){ r = i; cnt++; Integer y[] = {l, r}; li.add(y); set.clear(); l = i + 1; } else set.add(x); } if(cnt == 0) pn(-1); else{ Integer y[] = li.get(li.size() - 1); if(y[1] - n != 0) y[1] = n; p(cnt+"\n"); for(Integer tuple[] : li) p(tuple[0]+" "+tuple[1]+"\n"); } } static final long mod = (long)1e9+7l; static FastReader sc; static PrintWriter out; public static void main(String[]args)throws IOException { out = new PrintWriter(System.out); sc = new FastReader(); long s = System.currentTimeMillis(); int t = 1; //t = ni(); for(int i = 1; i <= t; i++) process(i); out.flush(); System.err.println(System.currentTimeMillis()-s+"ms"); } static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); }; static void pn(Object o){ out.println(o); } static void p(Object o){ out.print(o); } static int ni()throws IOException{ return Integer.parseInt(sc.next()); } static long nl()throws IOException{ return Long.parseLong(sc.next()); } static double nd()throws IOException{ return Double.parseDouble(sc.next()); } 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 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(); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["5\n1 2 3 4 1", "5\n1 2 3 4 5", "7\n1 2 1 3 1 2 1"]
2 seconds
["1\n1 5", "-1", "2\n1 3\n4 7"]
null
Java 11
standard input
[ "greedy" ]
4cacec219e4577b255ddf6d39d308e10
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
1,500
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
standard output
PASSED
e59e34fff2b71e9a68e1680c549b2ff6
train_004.jsonl
1453388400
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Training { static Integer a[]= new Integer[1000001]; public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); HashSet<Integer> a= new HashSet<Integer>(); int b[]= new int[300001]; int n = input.nextInt(); int c = 0 ; int p =1 ; for(int i = 0;i<n;i++){ int x = input.nextInt(); if(a.contains(x)){ a.clear(); c++; b[p] = i+1 ; p =i+2; }else{ a.add(x); } } if(c==0){ System.out.println(-1); }else{ System.out.println(c); for(int i = 300000;i>=1;i-- ){ if(b[i]!=0){ b[i]= n; break; } } for(int i =1;i<=300000;i++){ if(b[i]!=0){ System.out.println(i+" "+b[i]); } } } } // end Main } // end Class
Java
["5\n1 2 3 4 1", "5\n1 2 3 4 5", "7\n1 2 1 3 1 2 1"]
2 seconds
["1\n1 5", "-1", "2\n1 3\n4 7"]
null
Java 11
standard input
[ "greedy" ]
4cacec219e4577b255ddf6d39d308e10
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
1,500
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
standard output
PASSED
c21566089cf1c796408a511e3c14decc
train_004.jsonl
1453388400
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
256 megabytes
import java.util.*; import java.io.*; public class Main { static class Pair{ int x; int y; Pair(int x,int y){ this.x=x; this.y=y; } } static class FastReader { BufferedReader br; StringTokenizer st; 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; } } private static boolean isInside(int i, int j, int n, int m){ if(i>=0 && i<n && j>=0 && j<m){ return true; } return false; } public static void main(String[] args) throws IOException { FastReader ip = new FastReader(); OutputStream output = System.out; PrintWriter out = new PrintWriter(output); int n=ip.nextInt(); long arr[]=new long[n]; for(int i=0;i<n;i++){ arr[i]=ip.nextLong(); } ArrayList<Pair> al=new ArrayList<Pair>(); HashSet<Long> hs=new HashSet<>(); int start=0; int end=0; for(int i=0;i<n;i++){ if(hs.contains(arr[i])){ end=i; al.add(new Pair(start,end)); start=i+1; hs=new HashSet<>(); }else{ hs.add(arr[i]); } } if(start!=n){ if(al.size()==0){ out.println(-1); }else{ out.println(al.size()); for(int i=0;i<al.size();i++){ if(i==al.size()-1){ out.println((al.get(i).x+1)+" "+n); }else{ out.println((al.get(i).x+1)+" "+(al.get(i).y+1)); } } } }else{ out.println(al.size()); for(int i=0;i<al.size();i++){ out.println((al.get(i).x+1)+" "+(al.get(i).y+1)); } } out.close(); } }
Java
["5\n1 2 3 4 1", "5\n1 2 3 4 5", "7\n1 2 1 3 1 2 1"]
2 seconds
["1\n1 5", "-1", "2\n1 3\n4 7"]
null
Java 11
standard input
[ "greedy" ]
4cacec219e4577b255ddf6d39d308e10
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
1,500
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
standard output
PASSED
a44b90f4cd2863d2f627166dff235d4d
train_004.jsonl
1453388400
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
256 megabytes
import java.io.BufferedReader; import java.io.EOFException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.UncheckedIOException; import java.lang.reflect.Array; import java.lang.reflect.Field; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; public class Main { public void exec() { int n = stdin.nextInt(); int[] a = stdin.nextIntArray(n); List<Integer> left = new ArrayList<>(); List<Integer> right = new ArrayList<>(); Set<Integer> k = new HashSet<>(); List<Integer> v = new ArrayList<>(); for (int i = 0; i < n; i++) { if (k.contains(a[i])) { left.add(v.get(0)); right.add(i); k.clear(); v.clear(); } else { k.add(a[i]); v.add(i); } } if (left.isEmpty()) { stdout.println(-1); } else { if (!k.isEmpty()) { right.set(right.size() - 1, n - 1); } stdout.println(left.size()); for (int i = 0; i < left.size(); i++) { stdout.println(left.get(i) + 1, right.get(i) + 1); } } } private static final Stdin stdin = new Stdin(); private static final Stdout stdout = new Stdout(); public static void main(String[] args) { try { new Main().exec(); } finally { stdout.flush(); } } public static class Stdin { private BufferedReader stdin; private Deque<String> tokens; private Pattern delim; public Stdin() { stdin = new BufferedReader(new InputStreamReader(System.in)); tokens = new ArrayDeque<>(); delim = Pattern.compile(" "); } public String nextString() { try { if (tokens.isEmpty()) { String line = stdin.readLine(); if (line == null) { throw new UncheckedIOException(new EOFException()); } delim.splitAsStream(line).forEach(tokens::addLast); } return tokens.pollFirst(); } catch (IOException e) { throw new UncheckedIOException(e); } } public int nextInt() { return Integer.parseInt(nextString()); } public double nextDouble() { return Double.parseDouble(nextString()); } public long nextLong() { return Long.parseLong(nextString()); } public String[] nextStringArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = nextString(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nextDoubleArray(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); 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 static class Stdout { private PrintWriter stdout; public Stdout() { stdout = new PrintWriter(System.out, false); } public void printf(String format, Object ... args) { String line = String.format(format, args); if (line.endsWith(System.lineSeparator())) { stdout.print(line); } else { stdout.println(line); } } public void println(Object ... o) { String line = Arrays.stream(o).map(Objects::toString).collect(Collectors.joining(" ")); stdout.println(line); } public void debug(Object ... objs) { String line = Arrays.stream(objs).map(this::deepToString).collect(Collectors.joining(" ")); stdout.printf("DEBUG: %s%n", line); } private String deepToString(Object o) { if (o == null) { return "null"; } Class<?> clazz = o.getClass(); // 配列の場合 if (clazz.isArray()) { int len = Array.getLength(o); String[] tokens = new String[len]; for (int i = 0; i < len; i++) { tokens[i] = deepToString(Array.get(o, i)); } return "{" + String.join(",", tokens) + "}"; } // toStringがOverrideされている場合 if (Arrays.stream(clazz.getDeclaredMethods()).anyMatch(method -> method.getName().equals("toString") && method.getParameterCount() == 0)) { return Objects.toString(o); } // Tupleの場合 (フィールドがすべてpublicのJava Beans) try { List<String> tokens = new ArrayList<>(); for (Field field : clazz.getFields()) { String token = String.format("%s=%s", field.getName(), deepToString(field.get(o))); tokens.add(token); } return String.format("%s:[%s]", clazz.getName(), String.join(",", tokens)); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } } public void flush() { stdout.flush(); } } }
Java
["5\n1 2 3 4 1", "5\n1 2 3 4 5", "7\n1 2 1 3 1 2 1"]
2 seconds
["1\n1 5", "-1", "2\n1 3\n4 7"]
null
Java 11
standard input
[ "greedy" ]
4cacec219e4577b255ddf6d39d308e10
The first line contains integer n (1 ≤ n ≤ 3·105) — the number of pearls in a row. The second line contains n integers ai (1 ≤ ai ≤ 109) – the type of the i-th pearl.
1,500
On the first line print integer k — the maximal number of segments in a partition of the row. Each of the next k lines should contain two integers lj, rj (1 ≤ lj ≤ rj ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment. Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type. If there are several optimal solutions print any of them. You can print the segments in any order. If there are no correct partitions of the row print the number "-1".
standard output
PASSED
3037aacb3afcfe70d077b23206c50485
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.Vector; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Omar-Handouk */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, Scanner in, OutputWriter out) { int n = 2 * in.nextInt(); int[] arr = new int[n]; //Distribute first then see for (int i = 0; i < n; ++i) arr[i] = in.nextInt(); int[] freq = new int[101]; for (int i = 0; i < n; ++i) freq[arr[i]]++; Vector<Integer>[] dist = new Vector[2]; for (int i = 0; i < 2; ++i) dist[i] = new Vector<>(); for (int i = 10; i <= 99; ++i) { int f = freq[i]; if (f > 1) dist[0].add(i); else dist[1].add(i); } int[] ans = new int[n]; for (int e : dist[0]) { int found = 0; for (int i = 0; i < n; ++i) { int c = arr[i]; if (c == e) { if (found == 0) ans[i] = 1; else ans[i] = 2; ++found; } if (found == 2) break; } } boolean first = true; for (int e : dist[1]) { for (int i = 0; i < n; ++i) { if (arr[i] == e) { if (first) ans[i] = 1; else ans[i] = 2; first = !first; } } } int distA = 0; int distB = 0; for (int i = 0; i < n; ++i) { if (ans[i] == 1) ++distA; else if (ans[i] == 2) ++distB; } out.println(distA * distB); int leftA = n / 2 - distA; for (int i = 0; i < n; ++i) { if (ans[i] == 0) { if (leftA != 0) { ans[i] = 1; leftA--; } else ans[i] = 2; } } for (int e : ans) out.print(e + " "); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void close() { writer.close(); } public void println(int i) { writer.println(i); } } static class Scanner { private BufferedReader bufferedReader; private StringTokenizer stringTokenizer; public Scanner(InputStream stream) { bufferedReader = new BufferedReader(new InputStreamReader(stream)); } public String next() { while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { try { stringTokenizer = new StringTokenizer(bufferedReader.readLine()); } catch (IOException Error) { Error.printStackTrace(); ; } } return stringTokenizer.nextToken(); } public int nextInt() { int number = Integer.parseInt(this.next()); return number; } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
4543e8348a73f5753bd2250741e0bc60
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.ArrayList; import java.util.Scanner; import java.util.TreeSet; public class TwoHeaps { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt() * 2; int[] ans = new int[n]; TreeSet<Integer>[] h = new TreeSet[2]; h[0] = new TreeSet<Integer>(); h[1] = new TreeSet<Integer>(); TreeSet<Integer>[] occ = new TreeSet[100]; for(int i = 10; i < 100; i++) occ[i] = new TreeSet<Integer>(); for(int i = 0; i < n; i++) { int x = sc.nextInt(); occ[x].add(i); } ArrayList<Integer> ba2y = new ArrayList<Integer>(); ArrayList<Integer> sing = new ArrayList<Integer>(); ArrayList<Integer> singV = new ArrayList<Integer>(); for(int i = 10; i < 100; i++) { if(occ[i].size() % 2 == 1) if(occ[i].size() == 1) { sing.add(occ[i].pollFirst()); singV.add(i); } else ba2y.add(occ[i].pollFirst()); while(occ[i].size() > 0) { int heap = (occ[i].size() % 2); ans[occ[i].pollFirst()] = heap + 1; h[heap].add(i); } } int sHeap = 0; if(ba2y.size() % 2 == 1) sHeap = 1; for(int i = 0; i < ba2y.size(); i++) { ans[ba2y.get(i)] = (i % 2) + 1; } for(int i = 0; i < sing.size(); i++) { ans[sing.get(i)] = sHeap + 1; h[sHeap].add(singV.get(i)); sHeap = (sHeap + 1) % 2; } System.out.println(h[0].size() * h[1].size()); System.out.print(ans[0]); for(int i = 1; i < n; i++) System.out.print(" " + ans[i]); System.out.println(); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
4d0640bba489cd5d84ce561e610fd826
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; import java.io.*; public class cf353B { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in=new Scanner(System.in); int n=in.nextInt(); int state=0; int arr[]=new int[100]; int ans[]=new int[2*n]; ArrayList<ArrayList<Integer>> count=new ArrayList<ArrayList<Integer>>(); for(int i=0;i<=100;i++) count.add(new ArrayList<Integer>()); for(int i=0;i<(2*n);i++) { int temp=in.nextInt(); arr[temp]++; count.get(temp).add(i); } int left=0, right=0; int dleft=0, dright=0; ArrayList<Integer> mylist=new ArrayList<Integer>(); for(int i=10;i<=99;i++) { if(arr[i]%2==0 && arr[i]>0) { dleft++; dright++; left+=arr[i]/2; right+=arr[i]/2; for(int j=0;j<arr[i]/2;j++) ans[count.get(i).get(j)]=1; for(int j=arr[i]/2;j<arr[i];j++) ans[count.get(i).get(j)]=2; } else if(arr[i]==1) { mylist.addAll(count.get(i)); } else if(arr[i]>0){ int len=arr[i]; int mid=0; if(left<=right) { mid=(len+1)/2; } else { mid=(len-1)/2; } left+=mid; right+=(len-mid); if(mid>0) dleft++; if((len-mid)>0) dright++; for(int j=0;j<mid;j++) ans[count.get(i).get(j)]=1; for(int j=mid;j<len;j++) ans[count.get(i).get(j)]=2; } } if(left<right) { for(int i=0;i<mylist.size();i++) { if(i%2==0) { ans[mylist.get(i)]=1; dleft++; left++; } else { ans[mylist.get(i)]=2; dright++; right++; } } } else { for(int i=0;i<mylist.size();i++) { if(i%2==0) { ans[mylist.get(i)]=2; dright++; right++; } else { ans[mylist.get(i)]=1; dleft++; left++; } } } System.out.println((dleft*dright)); for(Integer i:ans) { System.out.print(i+" "); } /*System.out.println("dleft ="+dleft+" dright="+dright); for(int i=10;i<=99;i++) { if(arr[i]>0) System.out.println(i+"="+arr[i]); } */ } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
1857684bfcc8ecd9adabc6ba34ec6e23
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Q1 { static ArrayList<Integer> adj[],adj2[]; static int color[],cc; static long mod=1000000007; static TreeSet<Integer> ts[]; static boolean b[],visited[],possible,ans1,ans2; static Stack<Integer> s; static int totalnodes,colored,min,minc; static int c[]; static long sum[]; static HashMap<Integer,Integer> hm; public static void main(String[] args) throws IOException { //Scanner sc=new Scanner(System.in); in=new InputReader(System.in); out=new PrintWriter(System.out); int n=in.nextInt(); int freq[]=new int[101]; int a[]=new int[2*n]; Pair pair[]=new Pair[2*n]; adj=new ArrayList[100]; for(int i=0;i<100;i++) adj[i]=new ArrayList<>(); for(int i=0;i<2*n;i++) { a[i]=in.nextInt(); pair[i]=new Pair(a[i],i,0); freq[a[i]]++; adj[a[i]].add(i); } int ans[]=new int[2*n]; int ones=0; int twos=0; boolean flag=true;List<Integer> other=new ArrayList<>(); for(int i=1;i<100;i++) { if(freq[i]==1) { if(flag) { ones++;flag=false; ans[adj[i].get(0)]=1; } else { twos++;flag=true; ans[adj[i].get(0)]=2; } adj[i].clear(); } else if(freq[i]!=0) { ans[adj[i].get(0)]=1; ans[adj[i].get(1)]=2; ones++; twos++; for(int j=2;j<adj[i].size();j++) other.add(adj[i].get(j)); } } out.println(ones*twos); for(int i:other) { if(ones<n) { ones++; ans[i]=1; } else { twos++; ans[i]=2; } } for(int r:ans) { out.print(r+" "); } out.close(); } static InputReader in; static PrintWriter out; static void dfs(int i,int parent) { if(color[i]!=cc) ans1= false; for(int j:adj[i]) { if(j!=parent) { dfs(j,i); } } } /*public static void seive(long n){ b = new boolean[(int) (n+1)]; Arrays.fill(b, true); for(int i = 2;i*i<=n;i++){ if(b[i]){ sum[i]=count[i]; // System.out.println(sum[i]+" wf"); for(int p = 2*i;p<=n;p+=i){ b[p] = false; sum[i]+=count[p]; //System.out.println(sum[i]); } } } }*/ static class Pair implements Comparable<Pair> { int i; int j; int index; public Pair(){ } public Pair(int u, int v,int index) { this.i = u; this.j= v; this.index=index; } public int compareTo(Pair other) { return this.i-other.i; } /*public String toString() { return "[u=" + u + ", v=" + v + "]"; }*/ } static class Node2{ Node2 left = null; Node2 right = null; Node2 parent = null; int data; } //binaryStree static class BinarySearchTree{ Node2 root = null; int height = 0; int max = 0; int cnt = 1; ArrayList<Integer> parent = new ArrayList<>(); HashMap<Integer, Integer> hm = new HashMap<>(); public void insert(int x){ Node2 n = new Node2(); n.data = x; if(root==null){ root = n; } else{ Node2 temp = root,temp2 = null; while(temp!=null){ temp2 = temp; if(x>temp.data) temp = temp.right; else temp = temp.left; } if(x>temp2.data) temp2.right = n; else temp2.left = n; n.parent = temp2; parent.add(temp2.data); } } public Node2 getSomething(int x, int y, Node2 n){ if(n.data==x || n.data==y) return n; else if(n.data>x && n.data<y) return n; else if(n.data<x && n.data<y) return getSomething(x,y,n.right); else return getSomething(x,y,n.left); } public Node2 search(int x,Node2 n){ if(x==n.data){ max = Math.max(max, n.data); return n; } if(x>n.data){ max = Math.max(max, n.data); return search(x,n.right); } else{ max = Math.max(max, n.data); return search(x,n.left); } } public int getHeight(Node2 n){ if(n==null) return 0; height = 1+ Math.max(getHeight(n.left), getHeight(n.right)); return height; } } public static void debug(Object... o) { System.out.println(Arrays.deepToString(o)); } public static String rev(String s) { StringBuilder sb=new StringBuilder(s); sb.reverse(); return sb.toString(); } static long lcm(long a, long b) { return a * (b / gcd(a, b)); } static long gcd(long a, long b) { while (b > 0) { long temp = b; b = a % b; // % is remainder a = temp; } return a; } public static long max(long x, long y, long z){ if(x>=y && x>=z) return x; if(y>=x && y>=z) return y; return z; } static int[] sieve(int n,int[] arr) { for(int i=2;i*i<=n;i++) { if(arr[i]==0) { for(int j=i*2;j<=n;j+=i) arr[j]=1; } } return arr; } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { return nextIntArray(n, 0); } public int[] nextIntArray(int n, int off) { int[] arr = new int[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextInt(); } return arr; } public long[] nextLongArray(int n) { return nextLongArray(n, 0); } public long[] nextLongArray(int n, int off) { long[] arr = new long[n + off]; for (int i = 0; i < n; i++) { arr[i + off] = nextLong(); } return arr; } public String readString() { int c = snext(); while (isSpaceChar(c)) { c = snext(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isEndOfLine(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; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
5b18c1cfe2fa38b883190b08cd4c3842
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
// ~/BAU/ACM-ICPC/Teams/A++/BlackBurn95 // ~/sudo apt-get Accpeted import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.Double.parseDouble; import static java.lang.String.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuilder out = new StringBuilder(); StringTokenizer tk; int n = parseInt(in.readLine()); int [] a = new int[2*n]; int [] ans = new int[2*n]; Set<Integer> A = new HashSet<>(),B = new HashSet<>(); tk = new StringTokenizer(in.readLine()); List<Integer> [] f = new List[101]; for(int i=10; i<=99; i++) f[i] = new ArrayList<>(); for(int i=0; i<a.length; i++) { a[i] = parseInt(tk.nextToken()); f[a[i]].add(i); } int totA=0,totB=0; for(int i=10,c=0; i<=99; i++) { if(f[i].size()==1) { if(c==0) { A.add(i); ans[f[i].get(0)] = 1; totA++; } else { B.add(i); ans[f[i].get(0)] = 2; totB++; } c ^= 1; f[i].clear(); } } List<Integer> other = new ArrayList<>(); for(int i=10; i<=99; i++) { if(f[i].size() >= 2) { A.add(i); B.add(i); ans[f[i].get(0)] = 1; ans[f[i].get(1)] = 2; totA++; totB++; for(int j=2; j<f[i].size(); j++) other.add(f[i].get(j)); } } for(int i : other) { if(totA < n) { totA++; ans[i] = 1; } else { totB++; ans[i] = 2; } } System.out.println(A.size()*B.size()); for(int i=0; i<2*n; i++) out.append(ans[i]).append(" "); System.out.println(out); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
1571b3680d6548c9f670948e2561525f
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.Collection; import java.util.Set; import java.util.InputMismatchException; import java.io.IOException; import java.util.stream.Collectors; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.AbstractCollection; import java.util.stream.Stream; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Arthur Gazizov - Kazan FU #4.3 [2oo7] */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { private static final int LIMIT = 101; public void solve(int testNumber, InputReader in, OutputWriter out) { int n = in.nextInt(); int[] a = IOUtils.readIntArray(in, 2 * n); List<Integer>[] map = new List[LIMIT]; for (int i = 0; i < LIMIT; i++) { map[i] = new ArrayList<>(); } for (int i = 0; i < a.length; i++) { map[a[i]].add(i); } ArrayList<IntIntPair> first = new ArrayList<>(), second = new ArrayList<>(); boolean add = true; for (int i = 0; i < LIMIT; i++) { if (map[i].size() >= 2) { first.add(new IntIntPair(i, map[i].remove(map[i].size() - 1))); second.add(new IntIntPair(i, map[i].remove(map[i].size() - 1))); } else if (map[i].size() == 1) { if (add) { first.add(new IntIntPair(i, map[i].remove(0))); add = !add; } else { second.add(new IntIntPair(i, map[i].remove(0))); add = !add; } } } for (int i = 0; i < LIMIT; i++) { while (map[i].size() > 0) { if (first.size() < n) { first.add(new IntIntPair(i, map[i].remove(map[i].size() - 1))); } else { second.add(new IntIntPair(i, map[i].remove(map[i].size() - 1))); } } } HashSet<Integer> resultBuilder = new HashSet(); for (IntIntPair intPair : first) { resultBuilder.addAll(second.stream().map(pair -> 100 * intPair.first + pair.first).collect(Collectors.toList())); } out.printLine(resultBuilder.size()); Set<Integer> set = first.stream().map(pair -> pair.second).collect(Collectors.toSet()); for (int i = 0; i < n + n; i++) { out.print(set.contains(i) ? "1 " : "2 "); } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int 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) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class IntIntPair implements Comparable<IntIntPair> { public final int first; public final int second; public IntIntPair(int first, int second) { this.first = first; this.second = second; } public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } IntIntPair pair = (IntIntPair) o; return first == pair.first && second == pair.second; } public int hashCode() { int result = first; result = 31 * result + second; return result; } public String toString() { return "(" + first + "," + second + ")"; } @SuppressWarnings({"unchecked"}) public int compareTo(IntIntPair o) { int value = Integer.compare(first, o.first); if (value != 0) { return value; } return Integer.compare(second, o.second); } } static class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = in.nextInt(); } return array; } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
0b2498cb6f4e33f52bd82747609c1cb6
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.*; public class CF353B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] kk = new int[100]; int[] pp = new int[100]; int[] qq = new int[100]; StringTokenizer st = new StringTokenizer(br.readLine()); int[] aa = new int[n + n]; for (int i = 0; i < n + n; i++) { int a = Integer.parseInt(st.nextToken()); kk[a]++; aa[i] = a; } int p = 0, q = 0; for (int a = 10; a <= 99; a++) if (kk[a] >= 2) { p++; q++; pp[a]++; qq[a]++; kk[a] -= 2; } else if (kk[a] >= 1 && p <= q) { p++; pp[a]++; kk[a]--; } else if (kk[a] >= 1 && p > q) { q++; qq[a]++; kk[a]--; } int m = p * q; for (int a = 10; a <= 99; a++) while (kk[a] > 0) if (p <= q) { p++; pp[a]++; kk[a]--; } else { q++; qq[a]++; kk[a]--; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n + n; i++) { int a = aa[i], g; if (pp[a] > 0) { g = 1; pp[a]--; } else { g = 2; qq[a]--; } sb.append(g + " "); } System.out.println(m); System.out.println(sb); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
7c318cd0979540ddda48a5272420de4b
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.*; public class CF353B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] kk = new int[100]; int[] pp = new int[100]; int[] qq = new int[100]; StringTokenizer st = new StringTokenizer(br.readLine()); int[] aa = new int[n + n]; for (int i = 0; i < n + n; i++) { int a = Integer.parseInt(st.nextToken()); kk[a]++; aa[i] = a; } int p = 0, q = 0; for (int a = 10; a <= 99; a++) if (kk[a] >= 2) { p++; q++; pp[a]++; qq[a]++; kk[a] -= 2; } else if (kk[a] >= 1 && p <= q) { p++; pp[a]++; kk[a]--; } else if (kk[a] >= 1 && p > q) { q++; qq[a]++; kk[a]--; } int m = p * q; for (int a = 10; a <= 99; a++) while (kk[a] > 0) if (p <= q) { p++; pp[a]++; kk[a]--; } else { q++; qq[a]++; kk[a]--; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n + n; i++) { int a = aa[i], g; if (pp[a] > 0) { g = 1; pp[a]--; } else { g = 2; qq[a]--; } sb.append(g + " "); } System.out.println(m); System.out.println(sb); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
fef53d0b0299783774c02ef3e7b3a793
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.util.*; import java.io.*; /** * * @author TRUE */ public class Main { public static int a[] = new int[211]; public static int b[] = new int[211]; public static int c[] = new int[211]; public static int d[] = new int[211]; public static void main(String[] args) { Scanner cin = new Scanner(System.in); PrintStream cout = System.out; int n; n=cin.nextInt(); int n1=0, n2=0; for(int i=1; i<=2*n; i++) { a[i] = cin.nextInt(); c[i]=0; d[i]=0; } for(int i=1; i<=2*n; i++) { b[a[i]]=i; for(int j=1; j<=2*n; j++) { if(a[j] == a[i]) { c[i]=c[i]+1; } } } for(int i=1; i<=2*n; i++) { if(c[i]>1 && b[a[i]] == i) { for(int j=1; j<i; j++) { if(a[j] == a[i]) { d[j]=1; n1=n1+1; d[i]=2; n2=n2+1; break; } } } } for(int i=1; i<=2*n; i++) { if(d[i] == 0 && c[i] == 1) { if(n1<n2) { d[i]=1; n1=n1+1; }else { d[i]=2; n2=n2+1; } } } cout.println(n1*n2); for(int i=1; i<=2*n; i++) { if(d[i] == 0) { if(n1<n2) { d[i]=1; n1=n1+1; }else { d[i]=2; n2=n2+1; } } } for(int i=1; i<=2*n; i++) { cout.print(d[i]); if(i<2*n) { cout.print(' '); }else { cout.print('\n'); } } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
521420e25b4f8e45fe3fec2e18be6d0c
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
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; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); b353 solver = new b353(); solver.solve(1, in, out); out.close(); } static class b353 { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int[] a = new int[2 * n]; int[] aCnt = new int[100]; for (int i = 0; i < 2 * n; i++) { a[i] = in.nextInt(); aCnt[a[i]]++; } int[] aCntHeap = new int[100]; int[] aCntTrash = new int[100]; int[] ans = new int[2 * n]; int sum = 0; for (int i = 10; i < 100; i++) { aCntHeap[i] = Math.min(aCnt[i], 2); aCntTrash[i] = aCnt[i] - aCntHeap[i]; sum += aCntHeap[i]; } int[] aCntHeap1 = new int[100]; int[] aCntHeap2 = new int[100]; int curHeap = 1; for (int i = 0; i < 2 * n; i++) { if (aCntHeap[a[i]] == 1) { if (curHeap == 1) { aCntHeap1[a[i]] = 1; curHeap = 2; } else { aCntHeap2[a[i]] = 1; curHeap = 1; } } if (aCntHeap[a[i]] == 2) { aCntHeap1[a[i]] = 1; aCntHeap2[a[i]] = 1; } aCntHeap[a[i]] = 0; } for (int i = 0; i < 2 * n; i++) { if (aCntHeap1[a[i]] > 0) { aCntHeap1[a[i]] = 0; ans[i] = 1; } else if (aCntHeap2[a[i]] > 0) { aCntHeap2[a[i]] = 0; ans[i] = 2; } } for (int i = 0; i < 2 * n; i++) { if (ans[i] == 0) { ans[i] = curHeap; if (curHeap == 1) curHeap = 2; else curHeap = 1; } } out.println((sum / 2) * (sum - sum / 2)); for (int i = 0; i < 2 * n; i++) { out.print(ans[i] + " "); } } } static 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(); } catch (IOException e) { return null; } } public String next() { while (stt == null || !stt.hasMoreTokens()) { stt = new StringTokenizer(nextLine()); } return stt.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
85d11a8ee883ce333337bb6915a586d1
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Template implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } catch (Exception e) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } } class GraphBuilder { int n, m; int[] x, y; int index; int[] size; GraphBuilder(int n, int m) { this.n = n; this.m = m; x = new int[m]; y = new int[m]; size = new int[n]; } void add(int u, int v) { x[index] = u; y[index] = v; size[u]++; size[v]++; index++; } int[][] build() { int[][] graph = new int[n][]; for (int i = 0; i < n; i++) { graph[i] = new int[size[i]]; } for (int i = index - 1; i >= 0; i--) { int u = x[i]; int v = y[i]; graph[u][--size[u]] = v; graph[v][--size[v]] = u; } return graph; } } String readString() throws IOException { while (!tok.hasMoreTokens()) { try { tok = new StringTokenizer(in.readLine()); } catch (Exception e) { return null; } } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } int[] readIntArray(int size) throws IOException { int[] res = new int[size]; for (int i = 0; i < size; i++) { res[i] = readInt(); } return res; } long[] readLongArray(int size) throws IOException { long[] res = new long[size]; for (int i = 0; i < size; i++) { res[i] = readLong(); } return res; } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } <T> List<T>[] createGraphList(int size) { List<T>[] list = new List[size]; for (int i = 0; i < size; i++) { list[i] = new ArrayList<>(); } return list; } public static void main(String[] args) { new Template().run(); // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start(); } long timeBegin, timeEnd; void time() { timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } long memoryTotal, memoryFree; void memory() { memoryFree = Runtime.getRuntime().freeMemory(); System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB"); } public void run() { try { timeBegin = System.currentTimeMillis(); memoryTotal = Runtime.getRuntime().freeMemory(); init(); solve(); out.close(); if (System.getProperty("ONLINE_JUDGE") == null) { time(); memory(); } } catch (Exception e) { e.printStackTrace(); System.exit(-1); } } void solve() throws IOException { int n = readInt(); Deque<Integer>[] deques = new Deque[101]; for (int i = 0; i < deques.length; i++) { deques[i] = new ArrayDeque<>(); } for (int i = 0; i < 2 * n; i++) { int x = readInt(); deques[x].add(i); } int countA = 0; int countB = 0; int[] answer = new int[2 * n]; for (int i = 0; i < deques.length; i++) { if (deques[i].size() >= 2) { int a = deques[i].poll(); int b = deques[i].poll(); answer[a] = 1; answer[b] = 2; countA++; countB++; } else if (deques[i].size() == 1) { if (countA < countB) { countA++; answer[deques[i].poll()] = 1; } else { countB++; answer[deques[i].poll()] = 2; } } } int result = countA * countB; for (int i = 0; i < deques.length; i++) { while (deques[i].size() > 0) { int x = deques[i].poll(); if (countA < countB) { countA++; answer[x] = 1; } else { countB++; answer[x] = 2; } } } out.println(result); for (int x : answer) { out.print(x + " "); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
10eece30ab47427d8f54ab4799c67707
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public void solve() { int n = ni(); Number[] ns = new Number[2 * n]; for (int i = 0; i < 2 * n; i++) { ns[i] = new Number(i, ni()); } Arrays.sort(ns); int[] ans = new int[2 * n]; int cf = 0, cs = 0, l = -1; for (int i = 0; i < 2*n; i++) { if ((ns[i].v != l) && ((i == 2*n - 1 ) || (ns[i + 1].v != ns[i].v))) { if (cf < cs) { ans[ns[i].i] = 1; cf++; } else { ans[ns[i].i] = 2; cs++; } l = ns[i].v; ns[i] = null; } else { l = ns[i].v; } } int lf = cf, ls = cs, pf = -1, ps = -1; for (int i = 0; i < 2*n; i++) { if (ns[i] == null) continue; if (lf < ls) { ans[ns[i].i] = 1; lf++; if (ns[i].v != pf) { cf++; } pf = ns[i].v; } else { ans[ns[i].i] = 2; ls++; if (ns[i].v != ps) { cs++; } ps = ns[i].v; } } write(cf * cs + "\n"); for (int j = 0; j < 2 * n; j++) { write(ans[j] + " "); } } public static void main(String[] args){ Main m = new Main(); m.solve(); try { m.writer.close(); } catch (IOException e) {}; } BufferedReader reader; BufferedWriter writer; StringTokenizer tokenizer; public Main() { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new BufferedWriter(new OutputStreamWriter(System.out)); } int ni() { return Integer.parseInt(n()); } String n() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) {} } return tokenizer.nextToken(); } void write(String s) { try { writer.write(s); } catch(IOException e) {}; } } class Number implements Comparable<Number>{ public int i; public int v; public Number (int i, int v) { this.i = i; this.v = v; } @Override public int compareTo(Number number) { return Integer.compare(this.v, number.v); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
6a1a73719182a88b45554ca2968cd00d
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.HashMap; import java.util.Comparator; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.HashSet; import java.util.Map; import java.util.List; import java.util.function.Function; import java.io.IOException; import java.util.Arrays; import java.util.InputMismatchException; import java.util.ArrayList; import java.util.Set; import java.util.NoSuchElementException; import java.math.BigInteger; import java.util.Collections; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Alex */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out){ int n = in.ri(); HashMap<Integer, ArrayList<Integer>> values = new HashMap<>(); for(int i = 0; i < 2 * n; i++) { int temp = in.ri(); if (values.containsKey(temp)) values.get(temp).add(i); else values.put(temp, new ArrayList<>(Arrays.asList(i))); } ArrayList<IntPair> first = new ArrayList<>(), second = new ArrayList<>(); int xor = 0; for(Map.Entry<Integer, ArrayList<Integer>> e : values.entrySet()) { if (e.getValue().size() >= 2){ first.add(new IntPair(e.getKey(), e.getValue().remove(e.getValue().size()-1))); second.add(new IntPair(e.getKey(), e.getValue().remove(e.getValue().size() - 1))); } else if (e.getValue().size() == 1){ if (xor == 0){ first.add(new IntPair(e.getKey(), e.getValue().remove(0))); xor ^= 1; } else{ second.add(new IntPair(e.getKey(), e.getValue().remove(0))); xor ^= 1; } } } for(Map.Entry<Integer, ArrayList<Integer>> e : values.entrySet()) { while(e.getValue().size() > 0){ if (first.size() < n) first.add(new IntPair(e.getKey(), e.getValue().remove(e.getValue().size()-1))); else second.add(new IntPair(e.getKey(), e.getValue().remove(e.getValue().size() - 1))); } } HashSet<Integer> hm = new HashSet(); for(int i = 0; i < first.size(); i++) { for(int j = 0; j < second.size(); j++) { int num = 100 * first.get(i).first + second.get(j).first; hm.add(num); } } out.printLine(hm.size()); ArrayList<IntPair> res = new ArrayList<>(); for(IntPair p : first) res.add(new IntPair(p.second, 1)); for(IntPair p : second) res.add(new IntPair(p.second, 2)); Collections.sort(res, Comparator.comparing((IntPair ip)-> ip.first)); for(IntPair ip : res) out.print(ip.second + " "); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int ri(){ return readInt(); } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } } class IntPair implements Comparable<IntPair> { public int first, second; public IntPair(int first, int second) { this.first = first; this.second = second; } public String toString() { return "(" + first + "," + second + ")"; } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; IntPair intPair = (IntPair) o; return first == intPair.first && second == intPair.second; } public int hashCode() { int result = first; result = 31 * result + second; return result; } public int compareTo(IntPair o) { if (first < o.first) return -1; if (first > o.first) return 1; if (second < o.second) return -1; if (second > o.second) return 1; return 0; } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
4a8145f64dfdf0dd31fa3a5314e95d8a
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; import java.io.*; public class B { Reader in; PrintWriter out; int i = 0, j = 0; void solve() { //START// int n = in.nextInt(); int[] arr = new int[2*n]; int[] cnt = new int[100]; for (i = 0; i < 2*n; i++) { arr[i] = in.nextInt(); cnt[arr[i]]++; } int[] list1 = new int[100], list2 = new int[100]; ArrayList<Integer> extra = new ArrayList<Integer>(); int l1Size = 0, l2Size = 0; for (i = 10; i <= 99; i++) { if (cnt[i] > 0) { if (cnt[i] == 1) { if (l1Size > l2Size) { list2[i]++; l2Size++; } else { list1[i]++; l1Size++; } } else { cnt[i]-=2; list1[i]++; list2[i]++; l1Size++; l2Size++; for (j = 0; j < cnt[i]; j++) extra.add(i); } } } int sol = l1Size*l2Size; for (i = 0; i < extra.size(); i++) { if (l1Size < n) { list1[extra.get(i)]++; l1Size++; } else { list2[extra.get(i)]++; } } out.println(sol); for (i = 0; i < arr.length; i++) { if (list1[arr[i]] > 0) { out.print("1 "); list1[arr[i]]--; } else { out.print("2 "); list2[arr[i]]--; } } out.println(); //END } void runIO() { in = new Reader(); out = new PrintWriter(System.out, false); solve(); out.close(); } public static void main(String[] args) { new B().runIO(); } // input/output static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public final String next() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.append((char) c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int nextInt() { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10); if (neg) return -ret; return ret; } public int[] readIntArray(int size) { int[] arr = new int[size]; for (int i = 0; i < size; i++) arr[i] = nextInt(); return arr; } public long[] readLongArray(int size) { long[] arr = new long[size]; for (int i = 0; i < size; i++) arr[i] = nextInt(); return arr; } private void fillBuffer() { try { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); } catch (IOException e) { } if (bytesRead == -1) buffer[0] = -1; } private byte read() { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
99639aff91d6388ffed73bd3a2f2f985
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Main { public void solve() throws IOException{ int n = in.nextInt(); List<List<Integer>> count = new ArrayList<>(); for(int i = 0; i <= 100; i++){ count.add(new ArrayList<>()); } for(int i = 0; i < 2 * n; i++){ int num = in.nextInt(); count.get(num).add(i); } List<Set<Integer>> ls = new ArrayList<>(); ls.add(new HashSet<>()); ls.add(new HashSet<>()); int cur = 0; int[] visited = new int[2 * n]; for(int i = 10; i <= 99; i++){ List<Integer> cnt = count.get(i); if(cnt.size() >= 2){ int n1 = cnt.get(0); int n2 = cnt.get(1); ls.get(0).add(i); ls.get(1).add(i); visited[n1] = 1; visited[n2] = 2; }else if(cnt.size() == 1){ int n1 = cnt.get(0); ls.get(cur).add(i); visited[n1] = cur + 1; cur = 1 - cur; } } for(int i = 10; i <= 99; i++){ List<Integer> cnt = count.get(i); for(int j = 0; j < cnt.size(); j++){ if(visited[cnt.get(j)] == 0){ ls.get(cur).add(i); visited[cnt.get(j)] = cur + 1; cur = 1 - cur; } } } out.println(ls.get(0).size() * ls.get(1).size()); for(int i = 0; i < 2 * n; i++){ out.print(visited[i] + " "); } return; } public BigInteger gcdBigInt(BigInteger a, BigInteger b){ if(a.compareTo(BigInteger.valueOf(0L)) == 0){ return b; }else{ return gcdBigInt(b.mod(a), a); } } FastScanner in; PrintWriter out; static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = null; } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } String nextLine() throws IOException { if (st == null || !st.hasMoreTokens()) return br.readLine(); StringBuilder result = new StringBuilder(st.nextToken()); while (st.hasMoreTokens()) { result.append(" "); result.append(st.nextToken()); } return result.toString(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } } void run() throws IOException { in = new FastScanner(System.in); out = new PrintWriter(System.out, false); solve(); out.close(); } public static void main(String[] args) throws IOException{ new Main().run(); } public void printArr(int[] arr){ for(int i = 0; i < arr.length; i++){ out.print(arr[i] + " "); } out.println(); } public long gcd(long a, long b){ if(a == 0) return b; return gcd(b % a, a); } public boolean isPrime(long num){ if(num == 0 || num == 1){ return false; } for(int i = 2; i * i <= num; i++){ if(num % i == 0){ return false; } } return true; } public class Pair<A, B>{ public A x; public B y; Pair(A x, B y){ this.x = x; this.y = y; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; if (!x.equals(pair.x)) return false; return y.equals(pair.y); } @Override public int hashCode() { int result = x.hashCode(); result = 31 * result + y.hashCode(); return result; } } class Tuple{ int x; int y; int z; Tuple(int ix, int iy, int iz){ x = ix; y = iy; z = iz; } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
82a570ccb19f1b7c74a76db4a76ca781
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
//package round205; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class B { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); int[] a = na(2*n); int[] f = new int[100]; for(int i = 0;i < 2*n;i++){ f[a[i]]++; } int s = 0, t = 0; boolean[] st = new boolean[100]; for(int i = 10;i <= 99;i++){ if(f[i] == 1){ if(s < t){ s++; st[i] = false; }else{ t++; st[i] = true; } }else if(f[i] >= 2){ s++; t++; } } int[] g = Arrays.copyOf(f, 100); out.println(s * t); StringBuilder sb = new StringBuilder(); for(int i = 0;i < 2*n;i++){ if(f[a[i]] == 1){ if(st[a[i]]){ sb.append(" 2"); }else{ sb.append(" 1"); } }else if(f[a[i]] >= 2){ if(g[a[i]] == f[a[i]]){ sb.append(" 1"); }else if(g[a[i]] == f[a[i]]-1){ sb.append(" 2"); }else if(s < n){ sb.append(" 1"); s++; }else{ sb.append(" 2"); } } g[a[i]]--; } out.println(sb.substring(1)); } void run() throws Exception { is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new B().run(); } private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
8cee8307903c551b3cc28ebe7ad8cf8f
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.awt.*; import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.util.List; import java.util.Queue; import static java.lang.Math.max; import static java.lang.Math.min; public class B implements Runnable{ // SOLUTION!!! // HACK ME PLEASE IF YOU CAN!!! // PLEASE!!! // PLEASE!!! // PLEASE!!! private final static Random rnd = new Random(); private final static String fileName = ""; private final static long MODULO = 1000 * 1000 * 1000 + 7; private void solve() { int n = readInt(); int[] a = readIntArray(n + n); int[] answer = new int[n + n]; int[] counts = new int[100]; for (int value : a) counts[value]++; Set<Integer> first = new HashSet<Integer>(); Set<Integer> second = new HashSet<Integer>(); int firstSize = 0, secondSize = 0; for (int i = 0; i < a.length; ++i) { int value = a[i]; if (counts[value] > 1) { if (!first.contains(value)) { first.add(value); answer[i] = 1; ++firstSize; continue; } else if (!second.contains(value)) { second.add(value); answer[i] = 2; ++secondSize; continue; } else { continue; } } } for (int i = 0; i < a.length; ++i) { int value = a[i]; if (answer[i] == 0 && counts[value] == 1) { if (first.size() < second.size()) { first.add(value); answer[i] = 1; ++firstSize; } else { second.add(value); answer[i] = 2; ++secondSize; } } } for (int i = 0; i < a.length; ++i) { int value = a[i]; if (answer[i] == 0) { if (firstSize < secondSize) { first.add(value); answer[i] = 1; ++firstSize; } else { second.add(value); answer[i] = 2; ++secondSize; } } } out.println(first.size() * second.size()); for (int value : answer) { out.print(value + " "); } out.println(); } ///////////////////////////////////////////////////////////////////// private static long add(long a, long b) { return (a + b) % MODULO; } private static long subtract(long a, long b) { return add(a, MODULO - b) % MODULO; } private static long mult(long a, long b) { return (a * b) % MODULO; } ///////////////////////////////////////////////////////////////////// private final static boolean FIRST_INPUT_STRING = false; private final static boolean MULTIPLE_TESTS = true; private final boolean ONLINE_JUDGE = !new File("input.txt").exists(); // private final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; private final static int MAX_STACK_SIZE = 128; private final static boolean OPTIMIZE_READ_NUMBERS = false; ///////////////////////////////////////////////////////////////////// public void run(){ try{ timeInit(); Locale.setDefault(Locale.US); init(); if (ONLINE_JUDGE) { solve(); } else { do { try { timeInit(); solve(); time(); out.println(); } catch (NumberFormatException e) { break; } catch (NullPointerException e) { if (FIRST_INPUT_STRING) break; else throw e; } } while (MULTIPLE_TESTS); } out.close(); time(); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } ///////////////////////////////////////////////////////////////////// private BufferedReader in; private OutputWriter out; private StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args){ new Thread(null, new B(), "", MAX_STACK_SIZE * (1L << 20)).start(); } ///////////////////////////////////////////////////////////////////// private void init() throws FileNotFoundException{ Locale.setDefault(Locale.US); if (ONLINE_JUDGE){ if (fileName.isEmpty()) { in = new BufferedReader(new InputStreamReader(System.in)); out = new OutputWriter(System.out); } else { in = new BufferedReader(new FileReader(fileName + ".in")); out = new OutputWriter(fileName + ".out"); } }else{ in = new BufferedReader(new FileReader("input.txt")); out = new OutputWriter("output.txt"); } } //////////////////////////////////////////////////////////////// private long timeBegin; private void timeInit() { this.timeBegin = System.currentTimeMillis(); } private void time(){ long timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } private void debug(Object... objects){ if (ONLINE_JUDGE){ for (Object o: objects){ System.err.println(o.toString()); } } } ///////////////////////////////////////////////////////////////////// private String delim = " "; private String readLine() { try { return in.readLine(); } catch (IOException e) { throw new RuntimeIOException(e); } } private String readString() { try { while(!tok.hasMoreTokens()){ tok = new StringTokenizer(readLine(), delim); } return tok.nextToken(delim); } catch (NullPointerException e) { return null; } } ///////////////////////////////////////////////////////////////// private final char NOT_A_SYMBOL = '\0'; private char readChar() { try { int intValue = in.read(); if (intValue == -1){ return NOT_A_SYMBOL; } return (char) intValue; } catch (IOException e) { throw new RuntimeIOException(e); } } private char[] readCharArray() { return readLine().toCharArray(); } private char[][] readCharField(int rowsCount) { char[][] field = new char[rowsCount][]; for (int row = 0; row < rowsCount; ++row) { field[row] = readCharArray(); } return field; } ///////////////////////////////////////////////////////////////// private long optimizedReadLong() { int sign = 1; long result = 0; boolean started = false; while (true) { try { int j = in.read(); if (-1 == j) { if (started) return sign * result; throw new NumberFormatException(); } if (j == '-') { if (started) throw new NumberFormatException(); sign = -sign; } if ('0' <= j && j <= '9') { result = result * 10 + j - '0'; started = true; } else if (started) { return sign * result; } } catch (IOException e) { throw new RuntimeIOException(e); } } } private int readInt() { if (!OPTIMIZE_READ_NUMBERS) { return Integer.parseInt(readString()); } else { return (int) optimizedReadLong(); } } private int[] readIntArray(int size) { int[] array = new int[size]; for (int index = 0; index < size; ++index){ array[index] = readInt(); } return array; } private int[] readSortedIntArray(int size) { Integer[] array = new Integer[size]; for (int index = 0; index < size; ++index) { array[index] = readInt(); } Arrays.sort(array); int[] sortedArray = new int[size]; for (int index = 0; index < size; ++index) { sortedArray[index] = array[index]; } return sortedArray; } private int[] readIntArrayWithDecrease(int size) { int[] array = readIntArray(size); for (int i = 0; i < size; ++i) { array[i]--; } return array; } /////////////////////////////////////////////////////////////////// private int[][] readIntMatrix(int rowsCount, int columnsCount) { int[][] matrix = new int[rowsCount][]; for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) { matrix[rowIndex] = readIntArray(columnsCount); } return matrix; } private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) { int[][] matrix = new int[rowsCount][]; for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) { matrix[rowIndex] = readIntArrayWithDecrease(columnsCount); } return matrix; } /////////////////////////////////////////////////////////////////// private long readLong() { if (!OPTIMIZE_READ_NUMBERS) { return Long.parseLong(readString()); } else { return optimizedReadLong(); } } private long[] readLongArray(int size) { long[] array = new long[size]; for (int index = 0; index < size; ++index){ array[index] = readLong(); } return array; } //////////////////////////////////////////////////////////////////// private double readDouble() { return Double.parseDouble(readString()); } private double[] readDoubleArray(int size) { double[] array = new double[size]; for (int index = 0; index < size; ++index){ array[index] = readDouble(); } return array; } //////////////////////////////////////////////////////////////////// private BigInteger readBigInteger() { return new BigInteger(readString()); } private BigDecimal readBigDecimal() { return new BigDecimal(readString()); } ///////////////////////////////////////////////////////////////////// private Point readPoint() { int x = readInt(); int y = readInt(); return new Point(x, y); } private Point[] readPointArray(int size) { Point[] array = new Point[size]; for (int index = 0; index < size; ++index){ array[index] = readPoint(); } return array; } ///////////////////////////////////////////////////////////////////// @Deprecated private List<Integer>[] readGraph(int vertexNumber, int edgeNumber) { @SuppressWarnings("unchecked") List<Integer>[] graph = new List[vertexNumber]; for (int index = 0; index < vertexNumber; ++index){ graph[index] = new ArrayList<Integer>(); } while (edgeNumber-- > 0){ int from = readInt() - 1; int to = readInt() - 1; graph[from].add(to); graph[to].add(from); } return graph; } private static class GraphBuilder { final int size; final List<Integer>[] edges; static GraphBuilder createInstance(int size) { List<Integer>[] edges = new List[size]; for (int v = 0; v < size; ++v) { edges[v] = new ArrayList<Integer>(); } return new GraphBuilder(edges); } private GraphBuilder(List<Integer>[] edges) { this.size = edges.length; this.edges = edges; } public void addEdge(int from, int to) { addDirectedEdge(from, to); addDirectedEdge(to, from); } public void addDirectedEdge(int from, int to) { edges[from].add(to); } public int[][] build() { int[][] graph = new int[size][]; for (int v = 0; v < size; ++v) { List<Integer> vEdges = edges[v]; graph[v] = castInt(vEdges); } return graph; } } private final static int ZERO_INDEXATION = 0, ONE_INDEXATION = 1; private int[][] readUnweightedGraph(int vertexNumber, int edgesNumber) { return readUnweightedGraph(vertexNumber, edgesNumber, ONE_INDEXATION, false); } private int[][] readUnweightedGraph(int vertexNumber, int edgesNumber, int indexation, boolean directed ) { GraphBuilder graphBuilder = GraphBuilder.createInstance(vertexNumber); for (int i = 0; i < edgesNumber; ++i) { int from = readInt() - indexation; int to = readInt() - indexation; if (directed) graphBuilder.addDirectedEdge(from, to); else graphBuilder.addEdge(from, to); } return graphBuilder.build(); } private static class Edge { int to; int w; Edge(int to, int w) { this.to = to; this.w = w; } } private Edge[][] readWeightedGraph(int vertexNumber, int edgesNumber) { return readWeightedGraph(vertexNumber, edgesNumber, ONE_INDEXATION, false); } private Edge[][] readWeightedGraph(int vertexNumber, int edgesNumber, int indexation, boolean directed) { @SuppressWarnings("unchecked") List<Edge>[] graph = new List[vertexNumber]; for (int v = 0; v < vertexNumber; ++v) { graph[v] = new ArrayList<Edge>(); } while (edgesNumber --> 0) { int from = readInt() - indexation; int to = readInt() - indexation; int w = readInt(); graph[from].add(new Edge(to, w)); if (!directed) graph[to].add(new Edge(from, w)); } Edge[][] graphArrays = new Edge[vertexNumber][]; for (int v = 0; v < vertexNumber; ++v) { graphArrays[v] = graph[v].toArray(new Edge[0]); } return graphArrays; } ///////////////////////////////////////////////////////////////////// private static class IntIndexPair { static Comparator<IntIndexPair> increaseComparator = new Comparator<IntIndexPair>() { @Override public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) { int value1 = indexPair1.value; int value2 = indexPair2.value; if (value1 != value2) return value1 - value2; int index1 = indexPair1.index; int index2 = indexPair2.index; return index1 - index2; } }; static Comparator<IntIndexPair> decreaseComparator = new Comparator<IntIndexPair>() { @Override public int compare(IntIndexPair indexPair1, IntIndexPair indexPair2) { int value1 = indexPair1.value; int value2 = indexPair2.value; if (value1 != value2) return -(value1 - value2); int index1 = indexPair1.index; int index2 = indexPair2.index; return index1 - index2; } }; static IntIndexPair[] from(int[] array) { IntIndexPair[] iip = new IntIndexPair[array.length]; for (int i = 0; i < array.length; ++i) { iip[i] = new IntIndexPair(array[i], i); } return iip; } int value, index; IntIndexPair(int value, int index) { super(); this.value = value; this.index = index; } int getRealIndex() { return index + 1; } } private IntIndexPair[] readIntIndexArray(int size) { IntIndexPair[] array = new IntIndexPair[size]; for (int index = 0; index < size; ++index) { array[index] = new IntIndexPair(readInt(), index); } return array; } ///////////////////////////////////////////////////////////////////// private static class OutputWriter extends PrintWriter { final int DEFAULT_PRECISION = 12; private int precision; private String format, formatWithSpace; { precision = DEFAULT_PRECISION; format = createFormat(precision); formatWithSpace = format + " "; } OutputWriter(OutputStream out) { super(out); } OutputWriter(String fileName) throws FileNotFoundException { super(fileName); } int getPrecision() { return precision; } void setPrecision(int precision) { precision = max(0, precision); this.precision = precision; format = createFormat(precision); formatWithSpace = format + " "; } String createFormat(int precision){ return "%." + precision + "f"; } @Override public void print(double d){ printf(format, d); } void printWithSpace(double d){ printf(formatWithSpace, d); } void printAll(double...d){ for (int i = 0; i < d.length - 1; ++i){ printWithSpace(d[i]); } print(d[d.length - 1]); } @Override public void println(double d){ printlnAll(d); } void printlnAll(double... d){ printAll(d); println(); } } ///////////////////////////////////////////////////////////////////// private static class RuntimeIOException extends RuntimeException { /** * */ private static final long serialVersionUID = -6463830523020118289L; RuntimeIOException(Throwable cause) { super(cause); } } ///////////////////////////////////////////////////////////////////// //////////////// Some useful constants andTo functions //////////////// ///////////////////////////////////////////////////////////////////// private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; private static final int[][] steps8 = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, 1}, {1, -1}, {-1, 1} }; private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) { return checkIndex(row, rowsCount) && checkIndex(column, columnsCount); } private static boolean checkIndex(int index, int lim){ return (0 <= index && index < lim); } ///////////////////////////////////////////////////////////////////// private static int getBit(long mask, int bit) { return (int)((mask >> bit) & 1); } private static boolean checkBit(long mask, int bit){ return getBit(mask, bit) != 0; } ///////////////////////////////////////////////////////////////////// private static long getSum(int[] array) { long sum = 0; for (int value: array) { sum += value; } return sum; } private static Point getMinMax(int[] array) { int min = array[0]; int max = array[0]; for (int index = 0, size = array.length; index < size; ++index, ++index) { int value = array[index]; if (index == size - 1) { min = min(min, value); max = max(max, value); } else { int otherValue = array[index + 1]; if (value <= otherValue) { min = min(min, value); max = max(max, otherValue); } else { min = min(min, otherValue); max = max(max, value); } } } return new Point(min, max); } ///////////////////////////////////////////////////////////////////// private static int[] getPrimes(int n) { boolean[] used = new boolean[n]; used[0] = used[1] = true; int size = 0; for (int i = 2; i < n; ++i) { if (!used[i]) { ++size; for (int j = 2 * i; j < n; j += i) { used[j] = true; } } } int[] primes = new int[size]; for (int i = 0, cur = 0; i < n; ++i) { if (!used[i]) { primes[cur++] = i; } } return primes; } ///////////////////////////////////////////////////////////////////// int[] getDivisors(int value) { List<Integer> divisors = new ArrayList<Integer>(); for (int divisor = 1; divisor * divisor <= value; ++divisor) { if (value % divisor == 0) { divisors.add(divisor); if (divisor * divisor != value) { divisors.add(value / divisor); } } } return castInt(divisors); } ///////////////////////////////////////////////////////////////////// private static long lcm(long a, long b) { return a / gcd(a, b) * b; } private static long gcd(long a, long b) { return (a == 0 ? b : gcd(b % a, a)); } ///////////////////////////////////////////////////////////////////// private interface MultiSet<ValueType> { int size(); void inc(ValueType value); boolean dec(ValueType value); int count(ValueType value); } private static abstract class MultiSetImpl <ValueType, MapType extends Map<ValueType, Integer>> implements MultiSet<ValueType> { protected final MapType map; protected int size; protected MultiSetImpl(MapType map) { this.map = map; this.size = 0; } public int size() { return size; } public void inc(ValueType value) { int count = count(value); map.put(value, count + 1); ++size; } public boolean dec(ValueType value) { int count = count(value); if (count == 0) return false; if (count == 1) map.remove(value); else map.put(value, count - 1); --size; return true; } public int count(ValueType value) { Integer count = map.get(value); return (count == null ? 0 : count); } } private static class HashMultiSet<ValueType> extends MultiSetImpl<ValueType, Map<ValueType, Integer>> { public static <ValueType> MultiSet<ValueType> createMultiSet() { Map<ValueType, Integer> map = new HashMap<ValueType, Integer>(); return new HashMultiSet<ValueType>(map); } HashMultiSet(Map<ValueType, Integer> map) { super(map); } } ///////////////////////////////////////////////////////////////////// private interface SortedMultiSet<ValueType> extends MultiSet<ValueType> { ValueType min(); ValueType max(); ValueType pollMin(); ValueType pollMax(); ValueType lower(ValueType value); ValueType floor(ValueType value); ValueType ceiling(ValueType value); ValueType higher(ValueType value); } private static abstract class SortedMultiSetImpl<ValueType> extends MultiSetImpl<ValueType, NavigableMap<ValueType, Integer>> implements SortedMultiSet<ValueType> { SortedMultiSetImpl(NavigableMap<ValueType, Integer> map) { super(map); } @Override public ValueType min() { return (size == 0 ? null : map.firstKey()); } @Override public ValueType max() { return (size == 0 ? null : map.lastKey()); } @Override public ValueType pollMin() { ValueType first = min(); if (first != null) dec(first); return first; } @Override public ValueType pollMax() { ValueType last = max(); dec(last); return last; } @Override public ValueType lower(ValueType value) { return map.lowerKey(value); } @Override public ValueType floor(ValueType value) { return map.floorKey(value); } @Override public ValueType ceiling(ValueType value) { return map.ceilingKey(value); } @Override public ValueType higher(ValueType value) { return map.higherKey(value); } } private static class TreeMultiSet<ValueType> extends SortedMultiSetImpl<ValueType> { public static <ValueType> SortedMultiSet<ValueType> createMultiSet() { NavigableMap<ValueType, Integer> map = new TreeMap<ValueType, Integer>(); return new TreeMultiSet<ValueType>(map); } TreeMultiSet(NavigableMap<ValueType, Integer> map) { super(map); } } ///////////////////////////////////////////////////////////////////// private static class IdMap<KeyType> extends HashMap<KeyType, Integer> { /** * */ private static final long serialVersionUID = -3793737771950984481L; public IdMap() { super(); } int register(KeyType key) { Integer id = super.get(key); if (id == null) { super.put(key, id = size()); } return id; } int getId(KeyType key) { return get(key); } } ///////////////////////////////////////////////////////////////////// private static class SortedIdMapper<ValueType extends Comparable<ValueType>> { private final List<ValueType> values; public SortedIdMapper() { this.values = new ArrayList<ValueType>(); } void addValue(ValueType value) { values.add(value); } IdMap<ValueType> build() { Collections.sort(values); IdMap<ValueType> ids = new IdMap<ValueType>(); for (int index = 0; index < values.size(); ++index) { ValueType value = values.get(index); if (index == 0 || values.get(index - 1).compareTo(value) != 0) { ids.register(value); } } return ids; } } ///////////////////////////////////////////////////////////////////// private static int[] castInt(List<Integer> list) { int[] array = new int[list.size()]; for (int i = 0; i < array.length; ++i) { array[i] = list.get(i); } return array; } private static long[] castLong(List<Long> list) { long[] array = new long[list.size()]; for (int i = 0; i < array.length; ++i) { array[i] = list.get(i); } return array; } ///////////////////////////////////////////////////////////////////// /** * Generates list with keys 0..<n * @param n - exclusive limit of sequence */ private static List<Integer> order(int n) { List<Integer> sequence = new ArrayList<Integer>(); for (int i = 0; i < n; ++i) { sequence.add(i); } return sequence; } ///////////////////////////////////////////////////////////////////// interface Rmq { int getMin(int left, int right); int getMinIndex(int left, int right); } private static class SparseTable implements Rmq { private static final int MAX_BIT = 20; int n; int[] array; SparseTable(int[] array) { this.n = array.length; this.array = array; } int[] lengthMaxBits; int[][] table; int getIndexOfLess(int leftIndex, int rightIndex) { return (array[leftIndex] <= array[rightIndex]) ? leftIndex : rightIndex; } SparseTable build() { this.lengthMaxBits = new int[n + 1]; lengthMaxBits[0] = 0; for (int i = 1; i <= n; ++i) { lengthMaxBits[i] = lengthMaxBits[i - 1]; int length = (1 << lengthMaxBits[i]); if (length + length <= i) ++lengthMaxBits[i]; } this.table = new int[MAX_BIT][n]; table[0] = castInt(order(n)); for (int bit = 0; bit < MAX_BIT - 1; ++bit) { for (int i = 0, j = (1 << bit); j < n; ++i, ++j) { table[bit + 1][i] = getIndexOfLess( table[bit][i], table[bit][j] ); } } return this; } @Override public int getMinIndex(int left, int right) { int length = (right - left + 1); int bit = lengthMaxBits[length]; int segmentLength = (1 << bit); return getIndexOfLess( table[bit][left], table[bit][right - segmentLength + 1] ); } @Override public int getMin(int left, int right) { return array[getMinIndex(left, right)]; } } private static Rmq createRmq(int[] array) { return new SparseTable(array).build(); } ///////////////////////////////////////////////////////////////////// interface Lca { Lca build(int root); int lca(int a, int b); int height(int v); } private static class LcaRmq implements Lca { int n; int[][] graph; LcaRmq(int[][] graph) { this.n = graph.length; this.graph = graph; } int time; int[] order; int[] heights; int[] first; Rmq rmq; @Override public LcaRmq build(int root) { this.order = new int[n + n]; this.heights = new int[n]; this.first = new int[n]; Arrays.fill(first, -1); this.time = 0; dfs(root, 0); int[] orderedHeights = new int[n + n]; for (int i = 0; i < order.length; ++i) { orderedHeights[i] = heights[order[i]]; } this.rmq = createRmq(orderedHeights); return this; } void dfs(int from, int height) { first[from] = time; order[time] = from; heights[from] = height; ++time; for (int to : graph[from]) { if (first[to] == -1) { dfs(to, height + 1); order[time] = from; ++time; } } } @Override public int lca(int a, int b) { int aFirst = first[a], bFirst = first[b]; int left = min(aFirst, bFirst), right = max(aFirst, bFirst); int orderIndex = rmq.getMinIndex(left, right); return order[orderIndex]; } @Override public int height(int v) { return heights[v]; } } private static class LcaBinary implements Lca { private static final int MAX_BIT = 20; int n; int[][] graph; int[] h; int[][] parents; LcaBinary(int[][] graph) { this.n = graph.length; this.graph = graph; } @Override public Lca build(int root) { this.h = new int[n]; this.parents = new int[MAX_BIT][n]; Arrays.fill(parents[0], -1); Queue<Integer> queue = new ArrayDeque<Integer>(); queue.add(root); add(root, root); while (queue.size() > 0) { int from = queue.poll(); for (int to : graph[from]) { if (parents[0][to] == -1) { add(from, to); queue.add(to); } } } return this; } void add(int parent, int v) { h[v] = h[parent] + 1; parents[0][v] = parent; for (int bit = 0; bit < MAX_BIT - 1; ++bit) { parents[bit + 1][v] = parents[bit][parents[bit][v]]; } } @Override public int lca(int a, int b) { if (h[a] < h[b]) { int tmp = a; a = b; b = tmp; } int delta = h[a] - h[b]; for (int bit = MAX_BIT - 1; bit >= 0; --bit) { if (delta >= (1 << bit)) { delta -= (1 << bit); a = parents[bit][a]; } } if (a == b) return a; for (int bit = MAX_BIT - 1; bit >= 0; --bit) { int nextA = parents[bit][a], nextB = parents[bit][b]; if (nextA != nextB) { a = nextA; b = nextB; } } return parents[0][a]; } @Override public int height(int v) { return h[v]; } } private static Lca createLca(int[][] graph, int root) { return new LcaRmq(graph).build(root); } ///////////////////////////////////////////////////////////////////// private static class BiconnectedGraph { int n; int[][] graph; BiconnectedGraph(int[][] graph) { this.n = graph.length; this.graph = graph; } int time; int[] tin, up; boolean[] used; BiconnectedGraph build() { calculateTimes(); condensateComponents(); return this; } void calculateTimes() { this.tin = new int[n]; this.up = new int[n]; this.time = 0; this.used = new boolean[n]; timeDfs(0, -1); } void timeDfs(int from, int parent) { used[from] = true; up[from] = tin[from] = time; ++time; for (int to : graph[from]) { if (to == parent) continue; if (used[to]) { up[from] = min(up[from], tin[to]); } else { timeDfs(to, from); up[from] = min(up[from], up[to]); } } } int[] components; int[][] componentsGraph; int component(int v) { return components[v]; } int[][] toGraph() { return componentsGraph; } void condensateComponents() { this.components = new int[n]; Arrays.fill(components, -1); for (int v = 0; v < n; ++v) { if (components[v] == -1) { componentsDfs(v, v); } } GraphBuilder graphBuilder = GraphBuilder.createInstance(n); Set<Point> edges = new HashSet<Point>(); for (int from = 0; from < n; ++from) { int fromComponent = components[from]; for (int to : graph[from]) { int toComponent = components[to]; if (fromComponent == toComponent) continue; Point edge = new Point(fromComponent, toComponent); if (edges.add(edge)) graphBuilder.addDirectedEdge(fromComponent, toComponent); } } this.componentsGraph = graphBuilder.build(); } void componentsDfs(int from, int color) { components[from] = color; for (int to : graph[from]) { if (components[to] != -1) continue; if (tin[from] >= up[to] && tin[to] >= up[from]) { componentsDfs(to, color); } } } } ///////////////////////////////////////////////////////////////////// private static class VertexBiconnectedGraph { static class Edge { int to; int index; Edge(int to, int index) { this.to = to; this.index = index; } } int n, m; List<Edge>[] graph; List<Edge> edges; VertexBiconnectedGraph(int n) { this.n = n; this.m = 0; this.graph = new List[n]; for (int v = 0; v < n; ++v) { graph[v] = new ArrayList<Edge>(); } this.edges = new ArrayList<Edge>(); } void addEdge(int from, int to) { Edge fromToEdge = new Edge(to, m); Edge toFromEdge = new Edge(from, m + 1); edges.add(fromToEdge); edges.add(toFromEdge); graph[from].add(fromToEdge); graph[to].add(toFromEdge); m += 2; } int time; boolean[] used; int[] tin, up; int[] parents; boolean[] isArticulation; boolean[] findArticulationPoints() { this.isArticulation = new boolean[n]; this.used = new boolean[n]; this.parents = new int[n]; Arrays.fill(parents, -1); this.tin = new int[n]; this.up = new int[n]; this.time = 0; for (int v = 0; v < n; ++v) { if (!used[v]) { articulationDfs(v, -1); } } return isArticulation; } void articulationDfs(int from, int parent) { used[from] = true; parents[from] = parent; ++time; up[from] = tin[from] = time; int childrenCount = 0; for (Edge e : graph[from]) { int to = e.to; if (to == parent) continue; if (used[to]) { up[from] = min(up[from], tin[to]); } else { ++childrenCount; articulationDfs(to, from); up[from] = min(up[from], up[to]); if (up[to] >= tin[from] && parent != -1) { isArticulation[from] = true; } } } if (parent == -1 && childrenCount > 1) { isArticulation[from] = true; } } int[] edgeColors; int maxEdgeColor; int[] paintEdges() { this.edgeColors = new int[m]; Arrays.fill(edgeColors, -1); this.maxEdgeColor = -1; this.used = new boolean[n]; for (int v = 0; v < n; ++v) { if (!used[v]) { ++maxEdgeColor; paintDfs(v, maxEdgeColor, -1); } } return edgeColors; } void paintEdge(int edgeIndex, int color) { if (edgeColors[edgeIndex] != -1) return; edgeColors[edgeIndex] = edgeColors[edgeIndex ^ 1] = color; } void paintDfs(int from, int color, int parent) { used[from] = true; for (Edge e : graph[from]) { int to = e.to; if (to == parent) continue; if (!used[to]) { if (up[to] >= tin[from]) { int newColor = ++maxEdgeColor; paintEdge(e.index, newColor); paintDfs(to, newColor, from); } else { paintEdge(e.index, color); paintDfs(to, color, from); } } else if (up[to] <= tin[from]){ paintEdge(e.index, color); } } } Set<Integer>[] collectVertexEdgeColors() { Set<Integer>[] vertexEdgeColors = new Set[n]; for (int v = 0; v < n; ++v) { vertexEdgeColors[v] = new HashSet<Integer>(); for (Edge e : graph[v]) { vertexEdgeColors[v].add(edgeColors[e.index]); } } return vertexEdgeColors; } VertexBiconnectedGraph build() { findArticulationPoints(); paintEdges(); createComponentsGraph(); return this; } int[][] componentsGraph; void createComponentsGraph() { Set<Integer>[] vertexEdgeColors = collectVertexEdgeColors(); int edgeColorShift = vertexEdgeColors.length; int size = vertexEdgeColors.length + maxEdgeColor + 1; GraphBuilder graphBuilder = GraphBuilder.createInstance(size); for (int v = 0; v < vertexEdgeColors.length; ++v) { for (int edgeColor : vertexEdgeColors[v]) { graphBuilder.addEdge(v, edgeColor + edgeColorShift); } } this.componentsGraph = graphBuilder.build(); } int[][] toGraph() { return componentsGraph; } } ///////////////////////////////////////////////////////////////////// private static class DSU { int[] sizes; int[] ranks; int[] parents; static DSU createInstance(int size) { int[] sizes = new int[size]; Arrays.fill(sizes, 1); return new DSU(sizes); } DSU(int[] sizes) { this.sizes = sizes; int size = sizes.length; this.ranks = new int[size]; Arrays.fill(ranks, 1); this.parents = castInt(order(size)); } int get(int v) { if (v == parents[v]) return v; return parents[v] = get(parents[v]); } boolean union(int a, int b) { a = get(a); b = get(b); if (a == b) return false; if (ranks[a] < ranks[b]) { int tmp = a; a = b; b = tmp; } parents[b] = a; sizes[a] += sizes[b]; if (ranks[a] == ranks[b]) ++ranks[a]; return true; } } ///////////////////////////////////////////////////////////////////// }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
e3dce48aeb32474662c5c89f2b800953
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.*; public class Solution { private static PrintWriter out; public static void main(String[] args) throws Exception { out = new PrintWriter(System.out); new Solution().solve(); out.close(); } private BufferedReader reader; private StringTokenizer st; private int n; private int[] color, data, amount, nextColor, heap; private void solve() throws Exception { reader = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(reader.readLine()); data = new int[2 * n]; color = new int[2 * n]; amount = new int[100]; nextColor = new int[100]; heap = new int[2]; Arrays.fill(nextColor, 1); st = new StringTokenizer(reader.readLine()); for (int i = 0; i < 2 * n; ++i) { data[i] = Integer.parseInt(st.nextToken()); } reader.close(); for (int i = 0; i < 2 * n; ++i) { amount[data[i]]++; } int cnt1 = 0; int cnt2 = 0; for (int i = 10; i < 100; ++i) { if (amount[i] == 1) { ++cnt1; } else if (amount[i] > 1) { ++cnt2; } } int lastColor = 1; for (int i = 0; i < 2 * n; ++i) { if (amount[data[i]] == 1) { color[i] = lastColor; heap[lastColor - 1]++; lastColor = (lastColor == 1) ? 2 : 1; amount[data[i]] = 0; } } for (int i = 0; i < 2 * n; ++i) { if (amount[data[i]] == 0 || nextColor[data[i]] > 2) { continue; } amount[data[i]]--; color[i] = nextColor[data[i]]; heap[nextColor[data[i]] - 1]++; nextColor[data[i]]++; } for (int i = 0; i < 2 * n; ++i) { if (amount[data[i]] == 0 || color[i] != 0) { continue; } color[i] = (heap[0] > heap[1]) ? 2 : 1; heap[color[i] - 1]++; amount[data[i]]--; } int ans = cnt2 + (cnt1 / 2); if (cnt1 % 2 == 1) { ans = (ans * ans) + ans; } else { ans = (ans * ans); } out.println(ans); for (int i = 0; i < 2 * n; ++i) { out.print(color[i] + " "); // out.printf("data[%d]=%d, color[%d]=%d%n", i, data[i], i, color[i]); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
73c56692eb481c8c9ca19ed6a3a144b7
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
//package c205; import java.util.Arrays; import java.util.Scanner; import java.util.Stack; public class q2_2 { public static void main(String args[]) { Scanner s=new Scanner(System.in); int n=s.nextInt(); int[] a=new int[2*n]; int[] so=new int[2*n]; int[] f=new int[100]; int one=0; int two=0; int ans[] =new int[2*n]; boolean[] b=new boolean[2*n]; Stack<Integer> st=new Stack<>(); int sosize=0; for(int i=0;i<2*n;i++) { int tmp=s.nextInt(); if(f[tmp]<2) { so[i]=tmp; sosize++; } else { st.push(tmp); } a[i]=tmp; f[tmp]++; } Arrays.sort(so); for(int i=0;i<2*n;i++) { if(so[i]==0) continue; else { for(int j=0;j<2*n;j++) { if(a[j]==so[i] && !b[j]) { ans[j]=i%2+1; if(i%2==0) one++; else two++; b[j]=true; break; } } } } System.out.println(one*two); while(!st.isEmpty()) { int tmp=st.pop(); if(one<n) { for(int i=0;i<2*n;i++) { if(a[i]==tmp && !b[i]) { ans[i]=1; b[i]=true; one++; break; } } } else { for(int i=0;i<2*n;i++) { if(a[i]==tmp && !b[i]) { ans[i]=2; b[i]=true; two++; break; } } } } //System.out.println(one+" "+two); for(int i=0;i<2*n;i++) { System.out.print(ans[i]+" "); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
8c4759d39a2166a3cab0790e365f9283
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.*; public class ProblemB { InputReader in; PrintWriter out; public static class Cube { int num; int position; int h = 0; Cube(int num, int position) { this.num = num; this.position = position; } } void solve() { int n = in.nextInt(); List<Cube> cubes = new ArrayList<Cube>(); List<List<Cube> > byNum = new ArrayList<List<Cube>>(); for (int i = 0; i < 200; i++) { byNum.add(new ArrayList<Cube>()); } for (int i = 0; i < 2 * n; i++) { int num = in.nextInt(); Cube cube = new Cube(num, i); cubes.add(cube); byNum.get(num).add(cube); } int k1 = 0; int k2 = 0; for (int i = 0; i < 200; i++) { if (byNum.get(i).size() > 1) { byNum.get(i).get(0).h = 1; byNum.get(i).get(1).h = 2; k1++; k2++; } } int k = 0; for (int i = 0; i < 200; i++) { if (byNum.get(i).size() == 1) { byNum.get(i).get(0).h = 1 + k % 2; k++; if (byNum.get(i).get(0).h == 1) { k1++; } else { k2++; } } } for (Cube cube : cubes) { if (cube.h == 0) { if (k1 < n) { cube.h = 1; k1++; } else { cube.h = 2; k2++; } } } Set<Integer> nums1 = new HashSet<Integer>(); Set<Integer> nums2 = new HashSet<Integer>(); for (Cube cube : cubes) { if (cube.h == 1) { nums1.add(cube.num); } else { nums2.add(cube.num); } } out.println(nums1.size() * nums2.size()); for (Cube cube : cubes) { out.print(cube.h + " "); } out.println(); } ProblemB(){ boolean oj = System.getProperty("ONLINE_JUDGE") != null; try { if (oj) { in = new InputReader(System.in); out = new PrintWriter(System.out); } else { Writer w = new FileWriter("output.txt"); in = new InputReader(new FileReader("input.txt")); out = new PrintWriter(w); } } catch(Exception e) { throw new RuntimeException(e); } solve(); out.close(); } public static void main(String[] args){ new ProblemB(); } } class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public InputReader(FileReader fr) { reader = new BufferedReader(fr); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
d5be6bafcd6c53cf94b6b4b2b6a9586c
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.Map.Entry; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.Vector; public class Main { public static void main(String[] args) throws IOException{ FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int n =sc.nextInt(); int a[]=new int[2*n];int cnt[]=new int[10000]; for(int i=0;i<n*2;i++){ a[i]=sc.nextInt(); cnt[a[i]]++; } ArrayList<Integer>a1 =new ArrayList<Integer>(); ArrayList<Integer>a2 =new ArrayList<Integer>(); HashSet<Integer> s1 =new HashSet<Integer>(); HashSet<Integer> s2 =new HashSet<Integer>(); int c =0 ; for(int i=0;i<2*n;i++){ if(cnt[a[i]]>1 && cnt[a[i]]%2==1){ if(c%2==0){ a1.add(a[i]); s1.add(a[i]); }else{ a2.add(a[i]);s2.add(a[i]); } cnt[a[i]]--; c++; } } for(int i=0;i<2*n;i++){ if(cnt[a[i]]>1){ int j = cnt[a[i]]/2; for(int l=1;l<=j;l++){ a1.add(a[i]); s1.add(a[i]); a2.add(a[i]); s2.add(a[i]); } cnt[a[i]]=0; } } for(int i=0;i<2*n;i++){ if(cnt[a[i]]==1){ if(a1.size()<n){ a1.add(a[i]); s1.add(a[i]); }else{ a2.add(a[i]); s2.add(a[i]); } cnt[a[i]]--; } } int ans[]=new int[2*n]; Arrays.fill(ans, -1); for(int i=0;i<n;i++){ int x = a1.get(i); for(int l=0;l<2*n;l++) if(a[l]==x && ans[l]==-1){ ans[l]=1; break; } } for(int i=0;i<n;i++){ int x = a2.get(i); for(int l=0;l<2*n;l++) if(a[l]==x && ans[l]==-1){ ans[l]=2; break; } } out.println(s1.size()*s2.size()); for(Integer i:ans){ out.print(i+" "); } out.close(); } static void generate(int[] p, int L, int R) { if (L == R) { }else { for (int i = L; i <= R; i++) { int tmp = p[L]; p[L] = p[i]; p[i] = tmp;//swap generate(p, L+1, R);//recurse tmp = p[L]; p[L] = p[i]; p[i] = tmp;//unswap } } } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { e.printStackTrace(); } } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 8
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
accd48a38e20c16e2d2f5bc1136dac8a
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Cubes { public static void main(String[] args) throws IOException{ BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(reader.readLine()); String [] str = reader.readLine().split(" "); TreeMap<Integer, ArrayList<Integer>> set = new TreeMap<Integer, ArrayList<Integer>>(); for(int i=0;i<2*n;i++){ int a = Integer.parseInt(str[i]); if(set.containsKey(a)){ set.get(a).add(i); }else{ ArrayList<Integer> l = new ArrayList<Integer>(); l.add(i); set.put(a, l); } } int[] answer = new int[n*2]; boolean first = false; int left=0; int right=0; for(Integer val:set.keySet()){ ArrayList<Integer> l = set.get(val); if(l.size() >=2){ answer[l.get(0)]=1; l.remove(0); answer[l.get(0)]=2; l.remove(0); left++; right++; }else if(l.size()==1){ if(!first){ answer[l.get(0)]=1; left++; }else{ answer[l.get(0)]=2; right++; } l.remove(0); first = !first; } } int rest = n - left; for(Integer val:set.keySet()){ ArrayList<Integer> l = set.get(val); while(l.size()>0){ if(rest >0){ answer[l.get(0)]=1; }else{ answer[l.get(0)]=2; } l.remove(0); rest--; } } System.out.println(left*right); for(Integer v:answer) System.out.print(v + " "); System.out.println(); } finally { if(reader != null) reader.close(); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
b17df2c99270e940a3c72f55e3683458
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; /* br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); */ public class Main { private static BufferedReader br; private static StringTokenizer st; private static PrintWriter pw; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); //int qq = 1; int qq = Integer.MAX_VALUE; //int qq = readInt(); for(int casenum = 1; casenum <= qq; casenum++) { int n = readInt(); n *= 2; int[] list = new int[n]; for(int i = 0; i < n; i++) { list[i] = readInt(); } int[] ret = new int[n]; int index = 1; for(int val = 10; val <= 99; val++) { int place = 0; for(int i = 0; i < n; i++) { if(list[i] == val) { ret[i] = index; if(++index == 3) index = 1; if(++place == 2) { break; } } } } for(int i = 0; i < n; i++) { if(ret[i] == 0) { ret[i] = index; if(++index == 3) index = 1; } } Set<Integer> set = new HashSet<Integer>(); for(int i = 0; i < n; i++) { if(ret[i] == 1) { for(int j = 0; j < n; j++) { if(ret[j] == 2) { set.add(100 * list[i] + list[j]); } } } } pw.println(set.size()); StringBuilder sb = new StringBuilder(); for(int out: ret) { sb.append(out + " "); } pw.println(sb.toString().trim()); } pw.close(); } private static void exitImmediately() { pw.close(); System.exit(0); } private static long readLong() throws IOException { return Long.parseLong(nextToken()); } private static double readDouble() throws IOException { return Double.parseDouble(nextToken()); } private static int readInt() throws IOException { return Integer.parseInt(nextToken()); } private static String nextToken() throws IOException { while(st == null || !st.hasMoreTokens()) { if(!br.ready()) { exitImmediately(); } st = new StringTokenizer(br.readLine().trim()); } return st.nextToken(); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
e31baa527d3c8824eb63ca405a793c40
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; import java.io.*; public class Main{ BufferedReader in; StringTokenizer str = null; PrintWriter out; private String next() throws Exception{ if (str == null || !str.hasMoreElements()) str = new StringTokenizer(in.readLine()); return str.nextToken(); } private int nextInt() throws Exception{ return Integer.parseInt(next()); } public void run() throws Exception{ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int n = nextInt(); int c[] = new int[100]; Queue<Integer> []q = new LinkedList[100]; for(int i=0;i<100;i++){ q[i] = new LinkedList<Integer>(); } for(int i=0;i<2*n;i++){ int x = nextInt(); c[x]++; q[x].add(i); } int h[][] = new int[2][100]; int cnt1 = 0, cnt2 = 0; for(int i=10;i<100;i++){ if (c[i] > 1) { h[0][i]++; h[1][i]++; c[i]-=2; cnt1++; cnt2++; }else if (c[i] == 1) { if (cnt1 > cnt2) { h[1][i]++; cnt2++; }else{ h[0][i]++; cnt1++; } c[i] = 0; } } for(int i=10;i<100;i++){ h[0][i]+=c[i]/2; h[1][i]+=c[i]/2; cnt1+=c[i]/2; cnt2+=c[i]/2; if (c[i] % 2 == 1) { if (cnt1 > cnt2) { h[1][i]++; cnt2++; }else{ h[0][i]++; cnt1++; } } } int f = 0, s = 0; for(int i=10;i<100;i++){ if (h[0][i] > 0) f++; if (h[1][i] > 0) s++; } out.println(s * f); boolean used[] = new boolean[2*n]; for(int i=10;i<100;i++){ for(int j=0;j<h[1][i];j++){ int idx = q[i].poll(); used[idx] = true; } } for(int i=0;i<2*n;i++){ if (used[i]) { out.print("1 "); }else{ out.print("2 "); } } out.println(); out.close(); } public static void main(String args[]) throws Exception{ new Main().run(); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
a5d3c1849b773e1a0364732828845000
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; import java.util.List; public class C { public static void main(String[] args)throws Exception{ // TODO Auto-generated method stub new C().run(); } int[] getArray(String line){ String[] array=line.split(" "); int[] res=new int[array.length]; for(int i=0;i<res.length;i++) res[i]=Integer.parseInt(array[i]); return res; } void run() throws Exception{ BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); int n=Integer.parseInt(reader.readLine()); int [] vals=getArray(reader.readLine()); int[] res=new int[2*n]; System.out.println(getMax(n, vals, res)); for(int i=0;i<2*n;i++){ System.out.print(res[i]); if(i==2*n-1) System.out.println(); else System.out.print(" "); } System.out.flush(); reader.close(); } long getMax(int n, int[] vals, int[] res){ int[] cnts=new int[100]; int diff=0; for(int i:vals){ if(cnts[i]==0) diff++; cnts[i]++; } int dop=0; int einzeln=0; for(int i:cnts) if(i==1) einzeln++; else if(i>1) dop++; int n1=dop+einzeln/2; int n2=dop+(einzeln+1)/2; long r=n1*n2; int cnt1=0; int cnt2=0; int[] cnts1=new int[100]; int[] cnts2=new int[100]; for(int i=0;i<100;i++) if(cnts[i]>=2){ cnts1[i]++; cnts2[i]++; cnt1++; cnt2++; cnts[i]-=2; } else if(cnts[i]==1){ if(cnt1>cnt2){ cnts2[i]++; cnt2++; } else{ cnts1[i]++; cnt1++; } cnts[i]--; } for(int i=0;i<100;i++){ while(cnts[i]>0){ if(cnt1>cnt2){ cnts2[i]++; cnt2++; } else{ cnts1[i]++; cnt1++; } cnts[i]--; } } for(int i=0;i<2*n;i++){ if(cnts1[vals[i]]>0){ cnts1[vals[i]]--; res[i]=1; } else{ res[i]=2; } } return r; } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
d1dbd8e551dfcefebc8dd6428170bf3e
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class TwoHeaps { public static void main(String[] args) throws IOException { Init(System.in); int n = nextInt(); int end = n + n; int[] arr = new int[2 * n]; int[] count = new int[100]; for (int i = 0; i < end; ++i) { arr[i] = nextInt(); count[arr[i]]++; } int[] countC = new int[100]; int countunique = 0; int countR = 0; long result = 0; for (int i = 10; i < 100; ++i) { if (count[i] == 1) { countunique++; } else if (count[i] > 1) { countR++; } } int right; int left; left = countunique / 2; right = countunique - left; result = (left + countR) * (right + countR); System.out.println(result); StringBuilder temp = new StringBuilder(); int remaining = n - left - countR; for (int i = 0; i < end; ++i) { if (count[arr[i]] == 0) { continue; } if (count[arr[i]] == 1) { if (left > 0) { // System.out.print(1 + " "); temp.append(1 + " "); left--; } else { // System.out.print(2 + " "); temp.append(2 + " "); } } else { if (countC[arr[i]] == 0 || (countC[arr[i]] < count[arr[i]] - 1 && remaining > 0)) { temp.append(1 + " "); if (countC[arr[i]] != 0) { remaining--; } countC[arr[i]]++; } else { temp.append(2 + " "); } } } System.out.println(temp); } static BufferedReader reader; static StringTokenizer tokenizer; static void Init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static long nextLong() throws IOException { return Long.parseLong(next()); } static int nextInt() throws IOException { return Integer.parseInt(next()); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
2bf078d6cc70e8b79e95c1b946f78733
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.*; public class B implements Runnable { private void solve() throws IOException { int n = nextInt(); int[] a = new int[n * 2], cnt = new int[100]; for (int i = 0; i < n * 2; i++) { a[i] = nextInt(); cnt[a[i]]++; } int[] used = new int[100], ans = new int[n * 2], dif = new int[3]; for (int i = 0; i < n * 2; i++) if (cnt[a[i]] >= 2) { if (used[a[i]] == 0) { ans[i] = 1; used[a[i]]++; dif[1]++; } else if (used[a[i]] == 1) { ans[i] = 2; used[a[i]]++; dif[2]++; } } int cur = 1; for (int i = 0; i < n * 2; i++) if (cnt[a[i]] == 1) { ans[i] = cur; dif[cur]++; cur = 3 - cur; } for (int i = 0; i < n * 2; i++) if (ans[i] == 0) { ans[i] = cur; cur = 3 - cur; } System.out.println(dif[1] * dif[2]); for (int i = 0; i < n * 2; i++) { if (i != 0) System.out.print(' '); System.out.print(ans[i]); } } public static void main(String[] args) { new B().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() { try { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); solve(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(261); } } void halt() { writer.close(); System.exit(0); } void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } void println(Object... objects) { print(objects); writer.println(); } String nextLine() throws IOException { return reader.readLine(); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(nextLine()); return tokenizer.nextToken(); } int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(nextToken()); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
a638fa77b87ac486584b4984c5d830e9
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; import java.io.*; public class CFProblemB implements Runnable { public static void main(String args[]) { new Thread(new CFProblemB()).run(); } BufferedReader br; StringTokenizer in; PrintWriter out; public void solve() throws IOException { int n = nextInt(); int[] c = new int[100]; Arrays.fill(c, 0); int[] a = new int[2 * n]; for (int i = 0; i < 2 * n; i++) { a[i] = nextInt(); c[a[i]]++; } int c1 = 0; int c2 = 0; for (int i = 10; i < 100; i++) { if (c[i] == 1) c1++; else if (c[i] > 1) c2++; } int dx = 0; for (int i = 0; i < 2 * n; i++) { if (c[a[i]] == 1) a[i] = 1 + dx++ % 2; } dx = dx % 2; for (int i = 0; i < 2 * n; i++) { int x = a[i]; if (c[x] > 1) { if (c[x] % 2 == 0) { int d = 0; for (int j = 0; j < 2 * n; j++) { if (a[j] == x) a[j] = 1 + d++ % 2; } } else { for (int j = 0; j < 2 * n; j++) { if (a[j] == x) a[j] = 1 + dx++ % 2; } } c[x] = 0; } } out.println(c1 % 2 == 0 ? (c1 / 2 + c2) * (c1 / 2 + c2) : (c1 / 2 + c2) * (c1 / 2 + 1 + c2)); for (int i = 0; i < 2 * n; i++) out.print(a[i] + " "); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } String nextToken() throws IOException { while ((in == null) || (!in.hasMoreTokens())) { in = new StringTokenizer(br.readLine()); } return in.nextToken(); } public void run() { try { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); // br = new BufferedReader(new FileReader("input.txt")); // out = new PrintWriter("output.txt"); solve(); out.close(); } catch (IOException e) { } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
b9d4d373e97e98aaabc47025863cb3cd
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Integer.*; import static java.lang.Math.*; public class Problem353B3 { static BufferedReader in; static PrintWriter out; public static void main(String[] args) throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); new Problem353B3().go(); out.close(); } void go() throws IOException { int m = parseInt(in.readLine().trim()); int n = 2 * m; String[] inp = in.readLine().split("\\s+"); int[] a = new int[n]; Node[] nodes = new Node[101]; for (int i = 0; i < n; i++) { a[i] = parseInt(inp[i]); Node node = nodes[a[i]]; if (node == null) { node = new Node(); nodes[a[i]] = node; } node.ids[node.freq] = i; node.freq++; } int[] b = new int[n]; boolean leftHeap = false; int countDone = 0; int heapA = 0; int heapB = 0; for (int i = 0; i < nodes.length; i++) { if (nodes[i] == null) continue; int freq = nodes[i].freq; if (freq > 1) { heapA++; heapB++; int last = freq / 2 + ((freq % 2 == 0 || !leftHeap) ? 0 : 1); for (int j = 0; j < freq; j++) { int id = nodes[i].ids[j]; b[id] = (j < last) ? 1 : 2; countDone++; } if (freq % 2 != 0) leftHeap = !leftHeap; } } int rem = n - countDone; int last = rem / 2 + ((rem % 2 != 0) ? 1 : 0); int countLH = 0; heapA += last; heapB += n - countDone - last; for (int i = nodes.length - 1; i >= 0; i--) { if (nodes[i] == null) continue; int freq = nodes[i].freq; if (freq == 1) { countLH++; int id = nodes[i].ids[0]; b[id] = (countLH <= last) ? 1 : 2; } } int ans = heapA * heapB; out.println(ans); out.print(b[0]); for (int i = 1; i < n; i++) out.print(" " + b[i]); out.println(); } class Node { int freq; int[] ids = new int[201]; } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
15d22aea3330b3800053180bc267014a
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; public class B353 { static final int MAXCUBE = 99; public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int heap[] = new int[2*n]; int frq[] = new int[MAXCUBE + 1]; int cubes[][] = new int[2*n][2]; for (int i = 0; i < 2*n; i++) { cubes[i][0] = in.nextInt(); cubes[i][1] = i; frq[cubes[i][0]]++; } Arrays.sort(cubes, new Comparator<int[]>() { public int compare(int[] A, int[] B) { return A[0] - B[0]; } }); /* assign heaps */ for (int i = 0; i < n*2; i++) { if (i > 0) { if (cubes[i][0] == cubes[i-1][0]) continue; } if (frq[cubes[i][0]] >= 2) { heap[cubes[i][1]] = 1; heap[cubes[i+1][1]] = 2; } } int flag = 1; for (int i = 0; i < n*2; i++) { if (heap[cubes[i][1]] != 0 || frq[cubes[i][0]] > 1) continue; heap[cubes[i][1]] = flag; flag = 3 - flag; } for (int i = 0; i < n*2; i++) { if (heap[cubes[i][1]] != 0) continue; heap[cubes[i][1]] = flag; flag = 3 - flag; } Set<Integer> ones = new HashSet<Integer>(), twos = new HashSet<Integer>(), prod = new HashSet<Integer>(); for (int i = 0; i < 2*n; i++) { if (heap[cubes[i][1]] == 1) ones.add(cubes[i][0]); else twos.add(cubes[i][0]); } for (int i : ones) { for (int j : twos) { prod.add(100*i+j); } } System.out.println(prod.size()); Arrays.sort(cubes, new Comparator<int[]>() { public int compare(int[] A, int[] B) { return A[1] - B[1]; } }); for (int i = 0; i < 2*n; i++) System.out.print(heap[i] + " "); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
670444a4a30bd94b7ea78f80fb181e7b
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; public class b { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt()*2; int len = n/2; int[] data = new int[n]; for(int i = 0; i<n; i++) data[i] = input.nextInt(); int[] freq = new int[100]; for(int i =0; i<n; i++) freq[data[i]]++; HashSet<Integer> first = new HashSet<Integer>(); HashSet<Integer> second = new HashSet<Integer>(); int cf = 0, cs = 0; int[] res = new int[n]; int count = 0; for(int i = 0; i<100; i++) if(freq[i]>0) count++; for(int i =0; i<n; i++) { int cur = data[i]; if(!first.contains(cur) && freq[cur] > 1) { first.add(cur); cf++; res[i] = 1; freq[cur]--; } else if(first.contains(cur) && !second.contains(cur)) { res[i] = 2; freq[cur]--; cs++; second.add(cur); } } count -= cf; int used = count/2; for(int i = 0; i<n; i++) { int cur = data[i]; if(!first.contains(cur) && !second.contains(cur)) { if(used>0) { used--; first.add(cur); res[i] = 1; cf++; } else { second.add(cur); res[i] = 2; cs++; } } } for(int i = 0; i<n; i++) { int cur = data[i]; if(res[i] == 0) { if(cf < n/2) { first.add(cur); cf++; res[i] = 1; } else { second.add(cur); cs++; res[i] = 2; } } } System.out.println(first.size()*second.size()); for(int i =0; i<n; i++) System.out.print(res[i]+" "); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
080c5419067e08d43d489e72a59b25cd
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; public class code1{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>(); int ans = 0, ans1 = 0; int[] a = new int[2*n]; int[] b = new int[2*n]; for(int i=0; i<2*n; i++) { a[i] = sc.nextInt(); if(hm.get(a[i]) != null) { if(hm.get(a[i]) != -1) { int ind = hm.get(a[i]); b[ind] = 1; b[i] = 2; hm.put(a[i],-1); ans++; ans1++; } } else { hm.put(a[i], i); } } int put = 1; for(int i=0; i<2*n; i++) { if(b[i] == 0 && hm.get(a[i]) != -1) { b[i] = put; if(put == 1) { ans1++; put = 2; } else { put = 1; ans++; } } } for(int i=0; i<2*n; i++) { if(b[i]==0) { b[i] = put; if(put == 1) { put = 2; } else { put = 1; } } } int anss = ans*ans1; System.out.println(anss); for(int i=0; i<2*n; i++) { System.out.print(b[i]+" "); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
84314b1fe8e74693075819cf142e817b
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; import java.io.*; public class learn2 { Scanner in; PrintWriter out; public void solve() throws IOException { in = new Scanner(System.in); out = new PrintWriter(System.out); int n = in.nextInt() * 2; int[] a = new int[n]; int[] b = new int[100]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); b[a[i]]++; } int k1 = 0; int k2 = 0; int[] ans = new int[n]; for (int i = 0; i < n; i++) { if (b[a[i]] == 1 && k1 < k2) { ans[i] = 1; k1++; } else { if (b[a[i]] == 1) { ans[i] = 2; k2++; } } } for (int i = 10; i < 100; i++) { if (b[i] > 1) { for (int j = 0; j < n; j++) { if (a[j] == i) { if (k1 < k2) { ans[j] = 1; k1++; } else { ans[j] = 2; k2++; } } } } } int[] p = new int[100]; int c = 0; for (int i = 0; i < n; i++) { if (p[a[i]] == 0 && ans[i] == 1) { c++; } if (ans[i] == 1) { p[a[i]]++; } } int[] p1 = new int[100]; int c1 = 0; for (int i = 0; i < n; i++) { if (p1[a[i]] == 0 && ans[i] == 2) { c1++; } if (ans[i] == 2) { p1[a[i]]++; } } out.println(c*c1); for (int i = 0; i < n; i++) { out.print(ans[i] + " "); } out.close(); } public static void main(String[] arg) throws IOException { new learn2().solve(); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
ce77e3cef88b72147d2e0fa82a167bf7
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; public class Cubes { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n*2]; int[] fr = new int[101]; for(int i=0; i<2*n; i++){ int x = sc.nextInt(); fr[x]++; a[i] = x; } int[] index = new int[2*n]; Arrays.fill(index, -1); ArrayList<Integer> nums = new ArrayList<Integer>(); for(int i=10; i<=99; i++){ int freq = fr[i]; if(freq>0){ int b = 1; int cnt = 2*(freq/2); if(cnt>0){ for(int j=0; j<n*2; j++){ if(a[j]==i && index[j]==-1){ index[j] = b; b = 3 - b; cnt--; if(cnt==0) break; } } } if(freq%2==1 && freq==1) nums.add(i); } } for(int i=10; i<=99; i++){ int freq = fr[i]; if(freq>1 && freq%2==1){ nums.add(i); } } for(int i=0; i<nums.size(); i++){ int cur = nums.get(i); for(int j=2*n-1; j>=0; j--){ if(a[j]==cur){ if(index[j]==-1) index[j] = (i%2==0? 1: 2); break; } } } int[] As = new int[101], Bs = new int[101]; for(int i=0; i<2*n; i++){ if(index[i]==1){ As[a[i]] = 1; } else Bs[a[i]] = 1; } int X = 0, Y = 0; for(int i=10; i<=99; i++){ if(As[i]>0) X++; if(Bs[i]>0) Y++; } ArrayList<Integer> fir = new ArrayList<Integer>(), sec = new ArrayList<Integer>(); for(int i=0; i<2*n; i++){ if(index[i]==1) fir.add(a[i]); else sec.add(a[i]); } System.out.println(X*Y); for(int i=0; i<n*2-1; i++) System.out.print(index[i]+" "); System.out.println(index[2*n-1]); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
b5af5bdf51c520307b9308605f2bc03b
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.io.*; import java.util.*; public class second { static long fast_power(long a,long n,long m) { if(n==1) { return a%m; } if(n%2==1) { long power = fast_power(a,(n-1)/2,m)%m; return ((a%m) * ((power*power)%m))%m; } long power = fast_power(a,n/2,m)%m; return (power*power)%m; } public static void main(String arr[]) { Scanner sc= new Scanner(System.in); int n = sc.nextInt(); int a[] = new int[2*n]; int k[] = new int[2*n]; int count[] = new int[100]; int done[] = new int[100]; for(int i=0;i<2*n;i++){ a[i] = sc.nextInt(); count[a[i]]++; } int last=2; for(int i=0;i<2*n;i++) { if(k[i]!=0 || count[a[i]]==1)continue; int p = count[a[i]]%2; k[i]=(last)%2+1; done[a[i]]=1; last = (last)%2+1; count[a[i]]--; for(int j=i+1;j<2*n;j++) { if(count[a[i]]==p)break; if(a[j]==a[i]) { k[j] = (last)%2+1; last = (last)%2+1;count[a[i]]--; } } } last=2; for(int i=0;i<2*n;i++) { if(done[a[i]]==1)continue; k[i]=(last)%2+1; done[a[i]]=1; last = (last)%2+1; } for(int i=0;i<2*n;i++) { if(k[i]!=0)continue; k[i]=(last)%2+1; done[a[i]]=1; last = (last)%2+1; } int l[] = new int[100]; int r[] = new int[100]; int first=0; int second=0; for(int i=0;i<2*n;i++) { if(k[i]==1 && l[a[i]]==0) { first++; l[a[i]]++; } if(k[i]==2 && r[a[i]]==0) { second++; r[a[i]]++; } } System.out.println(first*second); for(int i=0;i<2*n;i++) System.out.print(k[i]+" "); } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
3302008a0b5eca60dc4e80fef92246fa
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.*; public class cf353B{ public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>(); int even = 0, odd = 0; int[] arr = new int[2*n]; int[] alloc = new int[2*n]; int dup =0; for(int i=0; i<2*n; i++) { arr[i] = sc.nextInt(); if(hm.get(arr[i]) != null) { if(hm.get(arr[i]) != -1) { int ind = hm.get(arr[i]); alloc[ind] = 1; alloc[i] = 2; hm.put(arr[i],-1); even++; odd++; } else dup++; } else { hm.put(arr[i], i); } } int to_put = 1; for(int i=0; i<2*n; i++) { if(alloc[i] == 0 && hm.get(arr[i]) != -1) { alloc[i] = to_put; if(to_put == 1) { odd++; to_put = 2; } else { to_put = 1; even++; } } } for(int i=0; i<2*n; i++) { if(alloc[i] == 0) { alloc[i] = to_put; if(to_put == 1) { to_put = 2; } else { to_put = 1; } } } int total = even*odd; System.out.println(total); for(int i=0; i<2*n; i++) { System.out.print(alloc[i]+" "); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
8303b457fbf66558052a371232372f1d
train_004.jsonl
1381419000
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class B { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] a = new int[100][2 * n + 1]; int[] b = new int[2 * n]; for (int i = 0; i < 2 * n; i++) { int p = sc.nextInt(); a[p][0]++; a[p][a[p][0]] = i + 1; } int counter = 0; int str1 = 0; int str2 = 0; int[] mas = new int[90]; int[] mas2 = new int[90]; int index = 0; int index2 = 0; for (int i = 10; i <= 99; i++) { if (a[i][0] == 1) { mas[index++] = i; counter++; } else if (a[i][0] > 1) { mas2[index2++] = i; counter += 2; } } System.out.println(counter / 2 * (counter - counter / 2)); int[] first = new int[n]; int[] second = new int[n]; for (int t = 0; t < index2; t++) { int k = a[mas2[t]][0]; int i = mas2[t]; if (k % 2 == 0) { for (int j = 1; j < k / 2 + 1; j++) { first[str1++] = a[i][j]; } for (int j = k / 2 + 1; j < k + 1; j++) { second[str2++] = a[i][j]; } } else { if (str2 > str1) { for (int j = 1; j < k / 2 + 2; j++) { first[str1++] = a[i][j]; } for (int j = k / 2 + 2; j < k + 1; j++) { second[str2++] = a[i][j]; } } else { for (int j = 1; j < k / 2 + 1; j++) { first[str1++] = a[i][j]; } for (int j = k / 2 + 1; j < k + 1; j++) { second[str2++] = a[i][j]; } } } } for (int i = 0; i < index; i++) { if (str1 > str2) { second[str2++] = a[mas[i]][1]; } else { first[str1++] = a[mas[i]][1]; } } Arrays.sort(first); Arrays.sort(second); int i = 0, j = 0, k = 0; for (; i < 2 * n - 1 && j < n && k < n; i++) { if (first[j] < second[k]) { System.out.print("1 "); j++; } else { System.out.print("2 "); k++; } } for (; i < 2 * n - 1 && j < n; i++, j++) { System.out.print("1 "); } for (; i < 2 * n - 1 && k < n; i++, k++) { System.out.print("2 "); } if (i == 2 * n - 1) { if (j != n) System.out.print(1); else System.out.print(2); } } }
Java
["1\n10 99", "2\n13 24 13 45"]
1 second
["1\n2 1", "4\n1 2 2 1"]
NoteIn the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number 1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
Java 6
standard input
[ "greedy", "constructive algorithms", "combinatorics", "math", "implementation", "sortings" ]
080287f34b0c1d52eb29eb81dada41dd
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
1,900
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them.
standard output
PASSED
fa3e278beed340b9bf4814117ea3501e
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class CodeForces{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); long arr[]=new long[3]; while(t>0){ arr[0]=sc.nextLong(); arr[1]=sc.nextLong(); arr[2]=sc.nextLong(); Arrays.sort(arr); if(arr[0]!=arr[1] && arr[0]!=arr[2] && arr[1]!=arr[2]) System.out.println("NO"); if(arr[0]==arr[1] && arr[1]==arr[2]){ System.out.println("YES"); System.out.println(arr[0]+" "+arr[0]+" "+arr[0]); } if(arr[1]==arr[2] && arr[0]!=arr[1]){ System.out.println("YES"); System.out.println(arr[1]+" "+arr[0]+" "+arr[0]); } if(arr[0]==arr[1] && arr[0]!=arr[2]){ System.out.println("NO"); } t--; } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
94aeeefa6e5d9c020f1adf2d5ee6cba0
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int tc = s.nextInt(); for(int i = 0;i < tc;i++) { long x = s.nextLong(); long y = s.nextLong(); long z = s.nextLong(); if(x != y && y != z && x != z) { System.out.println("No"); continue; } boolean x1 = true , y1 = false, z1 = false; long max = x; if(max <= y) { y1 = true; max = y; x1 = false; } if(max <= z) { z1 = true; max = z; x1 = false; } if(x == y && max != x) { System.out.println("No"); continue; } if(y == z && max != y) { System.out.println("No"); continue; } if(x == z && max != x) { System.out.println("No"); continue; } if(x == y) { System.out.println("Yes"); System.out.println(max + " " + z + " " + z); } else if(y == z) { System.out.println("Yes"); System.out.println(x + " " + x + " " + max); } else if(x == z) { System.out.println("Yes"); System.out.println(y + " " + max + " " + y); } } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
ee0d109b75dd879be0b0b2797ee99e9b
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class A { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solution sol = new Solution(); long t = in.nl(); for (int i = 0; i < t; ++i) sol.solve(in, out); out.close(); } private static class Solution { private void solve(InputReader in, PrintWriter out) { int x = in.ni(), y = in.ni(), z = in.ni(); int[] a = { x, y, z }; Arrays.parallelSort(a); if (a[1] != a[2]) { out.println("NO"); } else { out.println("YES"); if (x == y) out.println(x + " " + z + " " + z); else if (y == z) out.println(x + " " + x + " " + z); else out.println(y + " " + z + " " + y); } } } private static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; private InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } private String n() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } private int ni() { return Integer.parseInt(n()); } private long nl() { return Long.parseLong(n()); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
9409860aef51617d94794ea5b257b280
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; public class Test { public static void main(String[] args) throws Exception{ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { long x=sc.nextLong(); long y=sc.nextLong(); long z=sc.nextLong(); long a[]=new long[3]; a[0]=x; a[1]=y; a[2]=z; Arrays.sort(a); if(a[2]==a[1]) { System.out.println("YES"); System.out.println(a[0]+" "+a[0]+" "+a[2]); }else { System.out.println("NO"); } } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
3f40546199cb778573b60e14dbdc0a33
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Q1 { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub MScanner s = new MScanner(System.in); int t = s.nextInt(); while (t-- > 0) { int x = s.nextInt(); int y = s.nextInt(); int z = s.nextInt(); int a = Math.min(x, y); int b = Math.min(x, z); int c = Math.min(y, z); if (Math.max(a, b) == x && Math.max(a, c) == y && Math.max(b, c) == z) { System.out.println("YES"); System.out.println(a + " " + b + " " + c); } else { System.out.println("NO"); } } } 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; } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
428231d84a3d5eb247fb38cd512f3d9d
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.util.*; public class Main{ public static void main(String[] args) { FastScanner sc = new FastScanner(); int t=sc.nextInt(); while (t-->=1) { long a[]=sc.readArray(3); sort(a); if (a[0]==a[1]&&a[1]==a[2]){ System.out.println("YES"); System.out.println(a[0]+" "+a[1]+" "+a[2]); } if (a[2]!=a[1]) System.out.println("NO"); else if (a[2]==a[1]&&a[0]!=a[1]){ System.out.println("YES"); System.out.println(a[1]+" "+a[0]+" 1"); } } } static void sort(long[] a) { ArrayList<Integer> l=new ArrayList<>(); for (long i:a) l.add((int)i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long[] readArray(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
b8dbc87e5b5ca03e90278c443a6d2b6d
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) { FastScanner sc = new FastScanner(); int t=sc.nextInt(); outer:while (t-->=1) { int a[]= sc.readArray(3); sort(a); if (a[0]==a[1]&&a[1]==a[2]){ System.out.println("YES"); System.out.println(a[0]+" "+a[0]+" "+a[0]); continue outer; } if (a[2]==a[1]){ System.out.println("YES"); System.out.println(1+" "+(a[0])+" "+(a[2])); continue outer; } else { System.out.println("NO"); } } } static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sortLong(long[] a) { ArrayList<Integer> l = new ArrayList<>(); for (long i : a) l.add((int)i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sortReverse(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l, Collections.reverseOrder()); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
415d26715c7756bfd8ebb274033748a7
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int _t = s.nextInt(); for (int t = 0; t < _t; t++) { int[]xyz = new int[3]; for (int i = 0; i < 3; i++) xyz[i] = s.nextInt(); Arrays.sort(xyz); if (xyz[0] == xyz[1] && xyz[1] == xyz[2]){ System.out.println("YES"); System.out.println(xyz[0] + " " + xyz[0] + " " + xyz[0]); } else if (xyz[1] == xyz[2]){ System.out.println("YES"); System.out.println(xyz[0] + " " + xyz[0] + " " + xyz[1]); } else { System.out.println("NO"); } } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
d4be6fa73a7701597d63ede78dba1732
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.Scanner; public class A_ThreePairwisemax { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-->0){ int val1 = in.nextInt(); int val2 = in.nextInt(); int val3 = in.nextInt(); int arr[] = new int[]{val1,val2,val3}; int mx = Math.max(val1, val2); mx = Math.max(mx,val3); int mn = Math.min(val1, val2); mn = Math.min(mn,val3); int count = 0; for(int i=0;i<3;i++){ if(arr[i] == mx){ count++; } } if(count==2){ System.out.println("YES"); System.out.println(mx+ " "+ mn+" "+ 1); } else if(count==3){ System.out.println("YES"); System.out.println(mx+ " "+ mx+" "+ mx); } else System.out.println("NO"); } in.close(); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
16d820e4b9696564f5870dc75e07a24b
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class codeforces_div3_656_A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t=in.nextInt(); while(t-->0) { int x=in.nextInt(),s=0; int y=in.nextInt(); int z=in.nextInt(),c=0; s=x+y+z; // Set<Integer> set = new HashSet<>(); // set.add(x); // set.add(y); // set.add(z); int max=Math.max(x, y); max=Math.max(max, z); // if(set.size()==3) // { // System.out.println("NO"); // } // else if(x==y && x==z) // { // System.out.println("YES\n"+x+" "+x+" "+x); // } // else if(x>y && x>z) // { // System.out.println("NO"); // } // else // { // System.out.println("YES"); // System.out.print(max+" "); // if(x!=max) // System.out.print(x+" "+" "+x); // else if(y!=max) // System.out.print(y+" "+" "+y); // else if(z!=max) // System.out.print(z+" "+" "+z); // System.out.println(); // } if(max==x)c++; if(max==y)c++; if(max==z)c++; if(c>=2) { System.out.println("YES"); s=s-(2*max); System.out.println(max+" "+s+" "+s); } else System.out.println("NO"); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
89241a9b61cca5c6f6a919e2f1380611
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); while(n-->0){ int x = in.nextInt(); int y = in.nextInt(); int z = in.nextInt(); // 𝑥=max(𝑎,𝑏), 𝑦=max(𝑎,𝑐) and 𝑧=max(𝑏,𝑐) if(x==y && x>z) System.out.println("YES\n"+z+" "+x+" "+z); else if(x==z && x>y) System.out.println("YES\n"+x+" "+y+" "+y); else if(z==y && z>x) System.out.println("YES\n"+x+" "+x+" "+z); else if(x==y && z==x) System.out.println("YES\n"+x+" "+x+" "+x); else System.out.println("NO"); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
de3dbb391be4c16e95427157b378f5fa
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); while(n-->0){ int x = in.nextInt(); int y = in.nextInt(); int z = in.nextInt(); // Input: 𝑥=max(𝑎,𝑏), 𝑦=max(𝑎,𝑐) and 𝑧=max(𝑏,𝑐) if(x==y && x>z) System.out.println("YES\n"+z+" "+x+" "+z); else if(x==z && x>y) System.out.println("YES\n"+x+" "+y+" "+y); else if(z==y && z>x) System.out.println("YES\n"+x+" "+x+" "+z); else if(x==y && z==x) System.out.println("YES\n"+x+" "+x+" "+x); else System.out.println("NO"); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
1ad38ba078cd04b47dfcaaef95685447
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class solution{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int[] a = new int[3]; for(int i=0; i<3; i++){ a[i] = sc.nextInt(); } Arrays.sort(a); if(a[1]==a[2]){ System.out.println("YES"); System.out.println(a[2]+" "+a[0]+" "+a[0]); } else System.out.println("NO"); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
cdf0857a02ea1a4854310d81c65fd576
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; import java.io.*; public class Solution{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0){ int x = sc.nextInt(); int y = sc.nextInt(); int z = sc.nextInt(); int[] arr = new int[3]; int a,b,c; arr[0] = x; arr[1] = y; arr[2] = z; Arrays.sort(arr); if(arr[0]<arr[2] && arr[1]<arr[2]){ System.out.println("No"); } else{ System.out.println("Yes"); System.out.println(arr[0] + " " + arr[2] + " " + 1); } t--; } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
5b0f1c54fc2410575fe6b110a54d908f
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class weweewe { public static void main(String[] args) { Scanner sc=new Scanner (System.in); int t=sc.nextInt(); while(t-->0) { int ar[]=new int[3]; for(int i=0;i<3;i++) ar[i]=sc.nextInt(); Arrays.sort(ar); int x=0; if(ar[0]<ar[1]&&ar[1]==ar[2]) { x=1; System.out.println("YES"); System.out.println(ar[0]+" "+ar[0]+" "+ar[1]); } if(ar[0]==ar[1]&&ar[1]==ar[2]) { x=1; System.out.println("YES"); System.out.println(ar[0]+" "+ar[1]+" "+ar[2]); } if(x==0) { System.out.println("NO"); } } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
475e5326e4f1198fe474d7859e7dbdf7
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class Solution { public static void main(String []args){ Scanner scn= new Scanner(System.in); int t= scn.nextInt(); while(t-->0){ int []arr= new int[3]; for(int i=0;i<3;i++){ arr[i]=scn.nextInt(); } Arrays.sort(arr); if(arr[1]!=arr[2]) System.out.println("NO"); else System.out.println("YES \n"+arr[0]+" "+arr[0]+" "+arr[2]); } scn.close(); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
0aeed8f5ddf40e7783bba7bae2d45db2
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) { FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-- >0){ int a[] = new int[3]; a[0] = sc.nextInt(); a[1] = sc.nextInt(); a[2] = sc.nextInt(); Arrays.sort(a); if(a[1] != a[2]) System.out.println("NO"); else{ System.out.println("YES"); System.out.print(a[0]+" "+a[0]+" "+a[2]); System.out.println(); } } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
216bc0fb8b5514b45a7c94690af4e728
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
/*input 5 3 2 3 100 100 100 50 49 49 10 30 20 1 1000000000 1000000000 */ import java.math.*; import java.io.*; import java.util.*; public class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static Reader sc=new Reader(); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String args[])throws IOException { /* * For integer input: int n=inputInt(); * For long input: long n=inputLong(); * For double input: double n=inputDouble(); * For String input: String s=inputString(); * Logic goes here * For printing without space: print(a+""); where a is a variable of any datatype * For printing with space: printSp(a+""); where a is a variable of any datatype * For printing with new line: println(a+""); where a is a variable of any datatype Scanner in = new Scanner(System.in); //all four int[] dr = { 1, 0, -1, 0 }; int[] dc = { 0, 1, 0, -1 }; println("Case #"+k+": "+1+"");//Google */ int t=inputInt(); while(t-->0) { int x=inputInt(),y=inputInt(),z=inputInt(); if(x==z && z==y) { println("YES"); println(x+" "+y+" "+z); } else if((x==y && x!=1 && z<x) ) { println("YES"); println(x+" "+z+" "+1+""); } else if(z==x && z!=1 && y<z) { println("YES"); println(x+" "+y+" "+1+""); } else if(z==y && z!=1 && x<z) { println("YES"); println(z+" "+x+" "+1+""); } else println("NO"); } bw.flush(); bw.close(); } static void dfs(int src,int par,List<List<Integer>> ls,boolean visit[]) { if(visit[src]) return; visit[src]=true; Iterator<Integer> ite = ls.get(src).listIterator(); while(ite.hasNext()) { int x=ite.next(); if(!visit[x]) { dfs(x,par,ls,visit); } } } public static long pow(long a,long b) { long result=1; while(b>0) { if(b%2==1) result*=a; a*=a; b/=2; } return result; } public static long nCr(long n, long r) { long ans=1; if(r>n-r) { r=n-r; } for(long i=1;i<=r;i++) { ans*=(n-i+1); ans/=i; } return ans; } public static int modulo(int x,int N) { return (x % N + N) %N; } public static long lcm(long a,long b) { return a / gcd(a, b) * b; } public static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } public static int inputInt()throws IOException { return sc.nextInt(); } public static long inputLong()throws IOException { return sc.nextLong(); } public static double inputDouble()throws IOException { return sc.nextDouble(); } public static String inputString()throws IOException { return sc.readLine(); } public static void print(String a)throws IOException { bw.write(a); } public static void printSp(String a)throws IOException { bw.write(a+" "); } public static void println(String a)throws IOException { bw.write(a+"\n"); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
713f028296f2dab2d45d50503220647f
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java .util.Scanner ; import java.util.*; import java.io.*; import java.math.BigInteger; import java.nio.IntBuffer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; //import java.io.OutputStreamReader; import java.io.PrintWriter; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.lang.Math; import java.util.Arrays; import java.util.Collections; import java.io.InputStream; import java.io.InputStreamReader; import java.util.InputMismatchException; import java.awt.Point; public class cf2{ public static long LCM(int arr[], int n) { int max_num ; max_num= 0; for (int i = 0; i < n; i++) { if (max_num < arr[i]) { max_num = arr[i]; } } long res ; res= 1; int x ; x= 2; while (max_num>=x) { Vector<Integer> indexes = new Vector<>(); for (int j = 0; j < n; j++) { if (arr[j] % x == 0) { indexes.add(indexes.size(), j); } } if (indexes.size() >= 2) { for (int j = 0; j < indexes.size(); j++) { arr[indexes.get(j)] = arr[indexes.get(j)] / x; } res = res * x; } else { x++; } } for (int i = 0; i < n; i++) { res = res * arr[i]; } return res; } public static void main(final String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); long t =in.nextInt(); for(int i=0; i<t; i++){ int x =in.nextInt(); int y =in.nextInt(); int z=in.nextInt(); if(x!=y && y!=z && x!=z){ System.out.println("NO"); } else if ((x==y && x<z) || (x==z && x<y) || (y==z && y<x)){ System.out.println("NO"); } else { System.out.println("YES"); int min=Math.min(Math.min(x,y),z); int max=Math.max(Math.max(x,y),z); System.out.print(min+" "); System.out.print(min+" "); System.out.print(max+" "); } System.out.println(); } } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(final 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 (final IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (final 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(); final StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(final 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); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
32fa7abf5af4566051b706c46a47e034
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
//import java.util.PriorityQueue; import java.util.*; public class Code { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int x=sc.nextInt(); int y=sc.nextInt(); int z=sc.nextInt(); int max=Math.max(x,Math.max(y, z)); boolean ans=false; if(x==max&&y==max) { System.out.println("YES"); System.out.println(x+" "+z+" "+z); } else if(z==max&&y==max) { System.out.println("YES"); System.out.println(z+" "+x+" "+x); } else if(x==max&&z==max) { System.out.println("YES"); System.out.println(x+" "+y+" "+y); } else { System.out.println("NO"); } } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
3ac81e51518919da75cecc7f7297aefa
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class HelloWorld{ static int[] checkDuplicates(int x, int y, int z) { if(x==y && Math.max(x,z)==x) { return new int[]{x,z,1,1}; } else if(x==z && Math.max(x,y)==x) { return new int[]{x,y,1,1}; } else if(y==z && Math.max(y,x)==y) { return new int[]{y,x,1,1}; } else{ return new int[]{-1,-1,-1,0}; } } public static void main(String []args){ int t; int x,y,z; Scanner sc = new Scanner(System.in); t=sc.nextInt(); for(int i =0;i<t;i++) { x=sc.nextInt(); y=sc.nextInt(); z=sc.nextInt(); int arr[] = checkDuplicates(x,y,z); if(arr[3]==1) { System.out.println("YES"); System.out.println(arr[0]+" "+arr[1]+" "+"1"); } else{ System.out.println("NO"); } } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
b07aadfec0aed0de0f2dd7299eff0612
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); outer: for(int j=0;j<t;j++) { int x=sc.nextInt(); int y=sc.nextInt(); int z=sc.nextInt(); if(x>=y && x==z) { System.out.println("YES"); System.out.println(x+" "+ y +" "+y); continue outer; } if(x>z && x==y) { System.out.println("YES"); System.out.println(x+" "+ z +" "+z); continue outer; } if(y==z && y>x) { System.out.println("YES"); System.out.println(x+" "+ x +" "+y); continue outer; } System.out.println("NO"); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
993b9e6afd18af69754130f0dc549d18
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) throws Exception{ Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-->0){ int x = in.nextInt(); int y = in.nextInt(); int z = in.nextInt(); if(x == y && x > z){ System.out.println("Yes"); System.out.println(x+" "+(z)+" "+(z)); } else if(x == z && x > y){ System.out.println("Yes"); System.out.println((y)+" "+(x)+" "+(y)); } else if (y == z && y > x){ System.out.println("Yes"); System.out.println((x)+" "+(x)+" "+(z)); } else if(x == y && x == z){ System.out.println("Yes"); System.out.println((x)+" "+(x)+" "+(x)); } else{ System.out.println("No"); } } in.close(); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
0e59cd57b8c0bff1e7cb0ecf4366449c
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.Scanner; public class ThreePairwiseMax { public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while((t--)>0){ int x=sc.nextInt(); int y=sc.nextInt(); int z=sc.nextInt(); if(x==y && y==z && z==x){ System.out.println("YES"); System.out.println(x+" "+y+" "+z); } else if(x!=y && y!=z && z!=x) { System.out.println("NO"); } else{ if(x==z){ if(y>x) { System.out.println("NO"); } else{ int b=x; int a=y; int c=1; System.out.println("YES"); System.out.println(a+" "+b+" "+c);} } else if(x==y){ if(z>x){ System.out.println("NO"); } else{ int a=x; int b=z; int c=1; System.out.println("YES"); System.out.println(a+" "+b+" "+c);} } else{ if(x>y){ System.out.println("NO"); } else{ int c=y; int a=x; int b=1; System.out.println("YES"); System.out.println(a+" "+b+" "+c); } } } } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
36c3487ebcc15ad5bb49688bd53c2402
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.Scanner; public class Div3656A { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { int x = scanner.nextInt(); int y = scanner.nextInt(); int z = scanner.nextInt(); solve(x, y, z); } } private static void solve(int x, int y, int z) { if (Math.max(x, y) == z || Math.max(x, z) == y) { System.out.println("YES"); System.out.println(Math.max(Math.max(x, y), z) + " " + Math.min(Math.min(x, y), z) + " " + Math.min(Math.min(x, y), z) ); } else { System.out.println("NO"); } } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
1c85ea5e7bc7ead6ea3a1ec2519a56b1
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
// Codeforces 1385A import java.util.Scanner; import java.util.Arrays; import java.util.TreeMap; public class CF1385A { static final Scanner SC = new Scanner(System.in); public static void main(String[] args) { int tests = SC.nextInt(); for (int t = 0; t < tests; ++t) { int[] nums = new int[3]; for (int i = 0; i < 3; ++i) nums[i] = SC.nextInt(); checkPossibility(nums); } } // Checks and Prints whether pairwise maximum representation is possible static void checkPossibility(int[] nums) { TreeMap<Integer, Integer> numCount = new TreeMap<>(); // Counts occurrences of numbers for (int i = 0; i < nums.length; ++i) if (numCount.containsKey(nums[i])) numCount.put(nums[i], numCount.get(nums[i]) + 1); else numCount.put(nums[i], 1); if ((numCount.size() == 3) || (numCount.size() == 2 && numCount.get(numCount.firstKey()) == 2)) { out(false, nums); } else { if (numCount.size() == 1) out(true, nums); else { Arrays.sort(nums); nums[2] = 1; out(true, nums); } } } // Prints output based on condition static void out(boolean condition, int[] nums) { if (condition) { System.out.println("YES"); for (int i = 0; i < nums.length; ++i) System.out.print(nums[i] + " "); System.out.println(); } else System.out.println("NO"); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
6c2a74b2005471bfa170c682ec2427b6
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.*; public class ThreeMax { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x, y, z, a, b, c, a1, b1, c1; for (int i = 0; i < n; i++) { x = sc.nextInt(); y = sc.nextInt(); z = sc.nextInt(); if (x == y && y == z) { System.out.println("YES"); System.out.println(x + " " + y + " " + z); } else { a = x; a1 = y; b = x; b1 = z; c = y; c1 = z; if (a1 > x) a1 = 0; if (a > y) a = 0; if (b1 > x) b1 = 0; if (b > z) b = 0; if (c1 > y) c1 = 0; if (c > z) c = 0; if (a == 0 && a1 == 0 || b == 0 && b1 == 0 || c == 0 && c1 == 0) System.out.println("NO"); else { if (a1 != 0) a = a1; if (b1 != 0) b = b1; if (c1 != 0) c = c1; if (Math.max(a, b) == x && Math.max(a, c) == y && Math.max(b, c) == z) { System.out.println("Yes"); System.out.println(a + " " + b + " " + c); } else { System.out.println("NO"); } } } } sc.close(); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
688f5319dac059376caf643d46338c7b
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
// package com.company; import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int q = in.nextInt(); for (int j = 0; j < q; j++) { // int n = in.nextInt(); int a[] = new int[3]; for (int i = 0; i < 3; i++) { a[i] = in.nextInt(); } Arrays.sort(a); if (a[2] == a[1]) { // for (int i = 2; i >= 0 ; i--) { System.out.println("YES"); System.out.println(a[2] + " " + a[0] + " 1"); // } }else { System.out.println("NO"); } } } } //-1 5 -8,5 6,5 // 10 3 5,5 14,5 // 4 2 1 7 // 7 10 -8 22 // 8 1 6,5 9,5
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
808cbb9e0a6d6f1d21357c55a1ccbed6
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
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; Pair(int nod,int ucn){ this.nod=nod; this.ucn=ucn; } public static Comparator<Pair> wc = new Comparator<Pair>(){ public int compare(Pair e1,Pair e2){ //reverse order if(e1.ucn < e2.ucn) return 1; // 1 for swaping. else if (e1.ucn > e2.ucn) return -1; else{ // if(e1.siz>e2.siz) // return 1; // else // return -1; return 0; } } }; } public static long gcd(long a,long b){ if(b==0)return a; else return gcd(b,a%b); } ////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; } //// iterative BFS public static int bfs(int s,ArrayList<Integer>[] a,int[] dist,boolean[] b,PrintWriter w){ b[s]=true; int siz = 0; Queue<Integer> q = new LinkedList<>(); q.add(s); while(q.size()!=0){ int i=q.poll(); Iterator<Integer> it = a[i].listIterator(); int z=0; while(it.hasNext()){ z=it.next(); if(!b[z]){ b[z]=true; dist[z] = dist[i] + 1; siz++; q.add(z); } } } return siz; } ////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int defaultValue=0; int t = sc.nextInt(); while(t-->0){ int x = sc.nextInt(); int y = sc.nextInt(); int z = sc.nextInt(); if(x!=y && x!=z && y!=z){ w.println("NO"); } else if(x==y && y==z){ w.println("YES"); w.println(x+" "+y+" "+z); } else{ int a = 0; int b = 0; if(x==y){ a = x; b = z; } if(y==z){ a = y; b = x; } if(x==z){ a = x; b = y; } if(a<b){ w.println("NO"); } else{ w.println("YES"); w.println(a+" "+b+" "+b); } } } w.flush(); w.close(); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
dfc3cc95b611ad04685989e528951109
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.StringJoiner; import java.util.StringTokenizer; public class MainA { public static void main(String[] args) { var sc = new FastScanner(System.in); var pw = new PrintWriter(System.out); var T = sc.nextInt(); for (int t = 0; t < T; t++) { var X = sc.nextInt(); var Y = sc.nextInt(); var Z = sc.nextInt(); solve(X, Y, Z, pw); } pw.flush(); } private static void solve(int X, int Y, int Z, PrintWriter pw) { int[] S = new int[]{X, Y, Z}; Arrays.sort(S); if( S[1] != S[2] ) { pw.println("NO"); return; }; int fst = S[2]; int snd = S[0]; { int a = fst; int b = snd, c = snd; if( Math.max(a, b) == X && Math.max(a, c) == Y && Math.max(b, c) == Z ) { pw.println("YES"); pw.println(a + " " + b + " " + c); return; } } { int b = fst; int a = snd, c = snd; if( Math.max(a, b) == X && Math.max(a, c) == Y && Math.max(b, c) == Z ) { pw.println("YES"); pw.println(a + " " + b + " " + c); return; } } { int c = fst; int a = snd, b = snd; if( Math.max(a, b) == X && Math.max(a, c) == Y && Math.max(b, c) == Z ) { pw.println("YES"); pw.println(a + " " + b + " " + c); return; } } pw.println("NO"); } @SuppressWarnings("unused") static class FastScanner { private final BufferedReader reader; private StringTokenizer tokenizer; FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } long nextLong() { return Long.parseLong(next()); } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArray(int n, int delta) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt() + delta; return a; } long[] nextLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } static void writeLines(int[] as) { var pw = new PrintWriter(System.out); for (var a : as) pw.println(a); pw.flush(); } static void writeLines(long[] as) { var pw = new PrintWriter(System.out); for (var a : as) pw.println(a); pw.flush(); } static void writeSingleLine(int[] as) { var pw = new PrintWriter(System.out); for (var i = 0; i < as.length; i++) { if (i != 0) pw.print(" "); pw.print(as[i]); } pw.println(); pw.flush(); } static void debug(Object... args) { var j = new StringJoiner(" "); for (var arg : args) { if (arg == null) j.add("null"); else if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg)); else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg)); else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg)); else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg)); else j.add(arg.toString()); } System.err.println(j.toString()); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
9667c8982cf35162593549c36b55f29a
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.StringJoiner; import java.util.StringTokenizer; public class MainA { public static void main(String[] args) { var sc = new FastScanner(System.in); var pw = new PrintWriter(System.out); var T = sc.nextInt(); for (int t = 0; t < T; t++) { var X = sc.nextInt(); var Y = sc.nextInt(); var Z = sc.nextInt(); solve(X, Y, Z, pw); } pw.flush(); } private static void solve(int X, int Y, int Z, PrintWriter pw) { int[] S = new int[]{X, Y, Z}; Arrays.sort(S); if( S[1] != S[2] ) { pw.println("NO"); return; }; int fst = S[2]; int snd = S[0]; pw.println("YES"); pw.println(fst + " " + snd + " " + snd); } @SuppressWarnings("unused") static class FastScanner { private final BufferedReader reader; private StringTokenizer tokenizer; FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } long nextLong() { return Long.parseLong(next()); } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } int[] nextIntArray(int n, int delta) { var a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt() + delta; return a; } long[] nextLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } static void writeLines(int[] as) { var pw = new PrintWriter(System.out); for (var a : as) pw.println(a); pw.flush(); } static void writeLines(long[] as) { var pw = new PrintWriter(System.out); for (var a : as) pw.println(a); pw.flush(); } static void writeSingleLine(int[] as) { var pw = new PrintWriter(System.out); for (var i = 0; i < as.length; i++) { if (i != 0) pw.print(" "); pw.print(as[i]); } pw.println(); pw.flush(); } static void debug(Object... args) { var j = new StringJoiner(" "); for (var arg : args) { if (arg == null) j.add("null"); else if (arg instanceof int[]) j.add(Arrays.toString((int[]) arg)); else if (arg instanceof long[]) j.add(Arrays.toString((long[]) arg)); else if (arg instanceof double[]) j.add(Arrays.toString((double[]) arg)); else if (arg instanceof Object[]) j.add(Arrays.toString((Object[]) arg)); else j.add(arg.toString()); } System.err.println(j.toString()); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output
PASSED
ab6cc701098ea509a052a8d0d4e6564c
train_004.jsonl
1594996500
You are given three positive (i.e. strictly greater than zero) integers $$$x$$$, $$$y$$$ and $$$z$$$.Your task is to find positive integers $$$a$$$, $$$b$$$ and $$$c$$$ such that $$$x = \max(a, b)$$$, $$$y = \max(a, c)$$$ and $$$z = \max(b, c)$$$, or determine that it is impossible to find such $$$a$$$, $$$b$$$ and $$$c$$$.You have to answer $$$t$$$ independent test cases. Print required $$$a$$$, $$$b$$$ and $$$c$$$ in any (arbitrary) order.
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { // TODO Auto-generated method stub Scanner obj = new Scanner(System.in); int test = obj.nextInt(); while(test-- >0) { int x = obj.nextInt(); int y = obj.nextInt(); int z = obj.nextInt(); int a=1,b=1,c=1; boolean flag = false; if((x==y && z<=x)|| (y==z && x<=y) || (z==x && y<=z)){ flag=true; System.out.println("YES"); if(x==y && y==z) { a=x; b=x; c=x; } else if(x==y && z<x) { a=x; b=z; c=z-1; } else if(y==z && x<y) { a=x; b=x-1; c=y; } else if(z==x && y<z) { a=y; b=z; c=y-1; } if(a==0) { a=1; } if(b==0) { b=1; } if(c==0) { c=1; } System.out.println(a+" "+b+" "+c); } else { System.out.println("NO"); } } obj.close(); } }
Java
["5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000"]
1 second
["YES\n3 2 1\nYES\n100 100 100\nNO\nNO\nYES\n1 1 1000000000"]
null
Java 11
standard input
[ "math" ]
f4804780d9c63167746132c35b2bdd02
The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$, and $$$z$$$ ($$$1 \le x, y, z \le 10^9$$$).
800
For each test case, print the answer: "NO" in the only line of the output if a solution doesn't exist; or "YES" in the first line and any valid triple of positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) in the second line. You can print $$$a$$$, $$$b$$$ and $$$c$$$ in any order.
standard output