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
fbad7a88109f29452ee68514a055b184
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
//some updates in import stuff import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; import java.math.*; //key points learned //max space ever that could be alloted in a program to pass in cf //int[][] prefixSum = new int[...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
1bc20618d792d59cbfb5466505f5f040
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class q2 { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // public static long mod = 1000000007; public static void solve() throws Exception { String[] parts = br.readLine().split(" "); int n = I...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
9940517611ba2a41b3fdd1b9a3e590ea
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws IOException { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int k = sc.nextInt(); char[] arr = sc.next().toCharArray(); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
adac90e0168c5d571c7597b7a2e8f342
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; public class practice { static FastInput scn; static PrintWriter out; final static int MOD = (int) (1e9 + 7); final static int MAX = Integer.MAX_VALUE; final static int MIN = Integer.MIN_VALUE; // MAIN public static void...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
abd7e975d778d25db6491efe83b23110
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class B { public static void printArr(int arr[], int n) { StringBuilder s = new StringBuilder(); for (long no : arr) { ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
0a378c8a91acb79fd1dadb1671c217b0
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class Main { static long mod = 1000000007; static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); int t = sc.nextInt(); wh...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
7b3ad7157005fdf4cfa5b6a957126402
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.Scanner; public class B { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { // TODO Auto-generated method stub int testCases = Integer.parseInt(sc.nextLine()); for (int i = 1; i <= testCases; ++i) { solve(i); } } private static v...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
c76465b265c89c2694c11c6f5d444b84
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class gotoJapan { public static void main(String[] args) throws java.lang.Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream)...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
e79fac3a28b23b4e9f88c7016d88ba3a
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.Scanner; public class Main { Object solve(int n, int k, String bs) { int[] b = new int[n]; int[] c = new int[n]; int k_ = k; for (int i = 0; i < n; i++) { b[i] = bs.charAt(i) == '0' ? 0 : 1; b[i] ^= (k & 1); if (i < n-1) { if (b[i] == 0 && k_ > 0) { b[i] = 1; ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
9673b144e7e61d6b033a4126bab8c13e
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; // Created by @thesupremeone on 4/17/22 public class B { void solve() { int ts = getInt(); for (int t = 0; t < ts; t++) { int n = getInt(); int k = getInt(); int kb = k; String s = getLine(); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
394c2d8de3297a1dfd9d2001accec1ef
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; //need to be careful about negative sum resulting negative mod. public class Solution { static long mod = 1000000007; static long inv(long a, long b) {return 1 < a ? b - inv(b % a, a) * b / a : 1;} static long mi(long a) {return inv(a, mod);} static InputR...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
94e3c758e042aad12dd1742b49213404
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.StringTokenizer; public class B { String filename = null; InputReader sc; void solve() { int n = sc.nextInt(); int k = sc.nextInt(); String s = sc.next(); int[] flips = new int[n]; int remaining = k; for (i...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
9fa93ed1ec943f2987aadea14ab5767c
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class Main { public static Scanner obj=new Scanner(System.in); public static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) { int len=obj.nextInt(); while(len--!=0) { int n=obj.nextInt(); int k=obj...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
6ce3af3854670b54a376894b266760b5
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class Main { private static int MOD = 1000000007; private static long Inf = (long) 1E15; public static void main(String[] args) throws Exception { InputStream inputStream = System.in; //InputStream inputStream = new FileInputStr...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
5fb0eeed898773952b72393405aafcb3
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class Bit_Flipping { static FastScanner fs; static FastWriter fw; static boolean checkOnlineJudge = System.getProperty("ONLINE_JUDGE") == null; private static final int[][] kdir = new int[][]{{-1, 2}, {-2, 1}, {-2, -1}, {-1, -2}, {1, -2}, {2, -1},...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
7d42a7102c753b6114dfb02fcfed28e0
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
//<———My cp———— //https://takeuforward.org/interview-experience/strivers-cp-sheet/?utm_source=youtube&utm_medium=striver&utm_campaign=yt_video import java.util.*; import java.io.*; public class Solution{ static PrintWriter pw = new PrintWriter(System.out); static FastReader fr = new FastReader(System.in);...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
bb82ce465b4f4ff2190ee69d51b70e87
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class New { public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int testCases = Integer.parseIn...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
9f5d289d1e54f0ebc705ccc94c41bf1d
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Random; import java.util.Set; import java.util.StringTokenizer;...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
3fb33abf347bedc34127c4e1ef535002
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class BitFlipping { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWrit...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
d1bf45046892fd4ec1a2ec59a5a7b745
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import com.sun.security.jgss.GSSUtil; import java.io.*; import java.util.*; public class Main { private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private FastWriter wr; private Reader rd; public final int MOD = 1000000007; /***********************************************...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
29d5010fdf523a33cde412bb37a11682
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
8149c77aba271207d5e45529bb63a09c
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
//Utilities import java.io.*; import java.util.*; public class a { static int t; static int n, k; static char[] ch, f; static int[] res; public static void main(String[] args) throws IOException { t = in.iscan(); while (t-- > 0) { n = in.iscan(); k = in.iscan(); ch = in.sscan().toCharArr...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
71d19ca439b0c4c9533a249d3ad85c00
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
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.ArrayList; import java.util.StringTokenizer; import java.io.Writer; ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
fa0def6c90caab7998887ddb3ab42e1d
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class BitFlipping { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int t = Integer.parseInt(br.readLine()); for (int caseNum = 0; ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
9b3a35273b5aab76a0c597a1df519e20
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.lang.Math; import java.lang.reflect.Array; import java.util.*; import javax.swing.text.DefaultStyledDocument.ElementSpec; public final class Solution { static BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); static BufferedWriter bw = new B...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
fb249a558ddd05a6d53fbac08f07e520
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class Codeforces { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int t=Integer.parseInt(bu.readLine()); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
90d3cd918f6d7297b0c25769e73562f0
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class B { static class Scan { private byte[] buf=new byte[1024]; private int index; private InputStream in; private int total; public Scan() { in=System.in; } public int scan()throws ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
cf1e806a4a10d8cbd83191d65f99a597
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.pars...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
f3dab53e5d0024d8642d51a7f94155a5
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
/* Rating: 1461 Date: 17-04-2022 Time: 20-27-57 Author: Kartik Papney Linkedin: https://www.linkedin.com/in/kartik-papney-4951161a6/ Leetcode: https://leetcode.com/kartikpapney/ Codechef: https://www.codechef.com/users/kartikpapney */ import java.util.*; import java.io.BufferedRe...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
40e977d7605343413a7f3f6bfc30e708
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.math.*; import java.util.*; // @author : Dinosparton public class test { static class Pair{ long x; long y; Pair(long x,long y){ this.x = x; this.y = y; } } static class Sort implements Comparator...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
b371bf6ea363c83e24dedf8c12359ace
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
//Number of pairs import java.io.BufferedReader; import java.io.*; import java.io.InputStreamReader; import java.util.Scanner; import java.util.*; public class Yoo { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
8c000fb67497811885fa9c3e18646abd
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import javax.print.DocFlavor.INPUT_STREAM; import java.io.*; import java.math.*; import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLIntegrityConstraintViolationException; public class Main { private static class MyScanne...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
ede92bb92c8f070993f1878c2a2a56c6
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.util.NoSuchElementException; import java.util.*; import static java.util.Arrays.*; public class CodeforcesTemp { public static void main(String[] args) throws IOException { ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
080eec96a1038a882c1d46b2eac8b158
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class BitFlipping { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int T = Integer.parseInt(br.readLine())...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
c3dd8bda027284e3ef616f1eeab812f4
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; public class MyClass { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k=sc.nextInt(); String str=sc.next(); char[] arr=str.toCharArray(); int[] fr...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
29c357c168a670473570819c0176debd
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class Codeforces { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int t=Integer.parseInt(bu.readLine()); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
1a970840a67a3554cb47f0b86ee3c34a
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class Practice { static boolean multipleTC = true; final static int mod2 = 1000000007; final static int mod = 998244353; final double E = 2.7182818284590452354; final double PI = 3.14159265358979323846; int MAX = 200001; void pre() throws Exception { } // All t...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
df5f72409818baddb66bec25074504b6
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Random; import java.util.StringTokenizer; /* 1 6 3 100001 */ public class B { ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
f63ac22841a3b0dfd80ba4e38145a76a
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; import java.lang.*; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.math.*; import java.util.function.Consumer; import java.util.stream.Collectors; public class AAtempOneForCo...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
92b016a1833ac40b2d464d3b812b1f54
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
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 Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new Buf...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
3fe5eb608f4b715d26fa783b8634b4bb
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
/*----------- ---------------* Author : Ryan Ranaut __Hope is a big word, never lose it__ ------------- --------------*/ import java.io.*; import java.util.*; public class Codeforces2 { static PrintWriter out ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
3a23b14fa1220d4ed7b2285becd21e26
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
/*LoudSilence*/ import java.io.*; import java.util.*; import static java.lang.Math.*; public class Solution { /*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ static FastScanne...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
9433ca75282db3abd41906953982b93e
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.text.DecimalFormat; import java.util.Arrays; import java.util.*; import java.util.Scanner; import java.util.StringTokenizer; public class copy { static int log=18; static int[][] ancestor; static int[] depth; static voi...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
0b785096b9e5ad4f6f3f3cf83a04b426
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner scn = new Scanner(Syste...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
ada0274103b453dbb06327123347eb74
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class BitFlipping { public static void main(String[] args) throws Exception { FastIO in = new FastIO(); int t = in.nextInt(); for (int tc=0; tc<t; tc++) { int n = in.nextInt(); int k = in.nextInt(); char[] bits = in.next().toCharArray(); // in.pr....
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
9a6c9f24727c2e2669797d34db2de635
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class Main { static int[][] size; static int[][][] parent; static char[][] a; public static void main(String[] args) { MyScanner in = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int t = in.nextInt(...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
b47136f247305ad565dd4d157f8660a7
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Random; import java.util.StringTokenizer; /* 1 6 3 100001 */ public class B { ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
fa33b0022c56f256c89c985ca3c8e6df
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; //import javafx.util.Pair; public class CodeForces { public static void main(String[] args) throws FileNotFoundException { FastScanner fs = new FastScanner(); int tt = fs.nextInt(); while(tt-->0) { int n = fs.nextInt(), k = fs.nextInt(); char[] a = fs.n...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
815f7bc907aea9459200a80e4d1dccb7
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner cin=new Scanner(System...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
a475db81bb70bf9fb645a28da5a69e9f
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class CodeForces { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int tt = Integer.parseInt(in.readLine()); while (tt-- > 0) { String[] tok...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
517a4b983d21bc335ee8857e9d5dcb9f
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; import java.io.*; public class Main { // Graph // prefix sums //inputs public static void main(String args[])throws Exception{ Input sc=new Input(); precalcul...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
3b2d3a60497a2cebda13addeff41cc8a
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
// JAI SHREE RAM, HAR HAR MAHADEV, HARE KRISHNA import java.util.*; import java.util.Map.Entry; import java.util.stream.*; import java.lang.*; import java.math.BigInteger; import java.text.DecimalFormat; import java.io.*; public class CodeForces { static private final String INPUT = "input.txt"; s...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
3f7fb73f569699beb5e877c031a26394
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class practiceb { static FastScanner sc; static int ans; static long[] arr, arr1; static char[][] board; static long mul, mul1; static int[] spf; static char[] ch; s...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
a331b2f32cf12b5565db8f6dd0fc4d6a
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = Integer.parseInt(sc.next()); while(T-->0){ int n = Integer.parseInt(sc.next()); int k = Integer.parseInt(sc.next()); int K = k; String bits = sc.nex...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
a61080810d78b2f053aeda9a12449f6b
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; public class Main2 { static void solve() { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for (int i = 0; i < t; i++) { int n = scan.nextInt(); int m = scan.nextInt(); solveCase(n, m); } }...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
c0907cfbd1ae449e2e26857cef932ab2
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class Main { public static int[] arr = new int[300000]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); while(t>0){ int ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
46d8971a8213ec0576bb586bd4a35ca6
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.lang.*; import java.util.*; public class B16559 { public static void main(String[] args) throws IOException{ StringBuffer ans = new StringBuffer(); StringTokenizer st; BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); s...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
8853dc9ecf29cf442cc61a538ca65106
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; public class class1 { public static void main(String[] args) { Scanner input =new Scanner(System.in); int t=input.nextInt(); while(t-->0) { int n=input.nextInt(); int k=input.nextInt(); int m=k,x=0; String s=input.next(); char c[]=s.toCharArray(); StringBuilder p=new Str...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
d09089990191e1130b8e054407e223a7
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.Scanner; public class Codeforces782_2 { public static void main(String[] args) { Scanner input =new Scanner(System.in); int t= input.nextInt(); // System.out.println(t); for(int i=0;i<t;i++){ long k; int n; n= input.nextInt...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
ae6276384972d76df7c94d8c6e82735b
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
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 n = sc.nextInt(); int k = sc.nextInt(); String s = sc.next(); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
e664fe8452adcb34d11a3502827a7599
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
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 n = sc.nextInt(); int k = sc.nextInt(); String s = sc.next(); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
dc0a6aedf071e6454940f08159883a4f
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.Scanner; public class ProblemC1 { static int[] moveCount; static int k; public static char[] reverseStr(char[] chars) { char[] reverseChars = new char[chars.length]; for (int i = 0; i < chars.length; i++) { reverseChars[i] = chars[i] == '0' ? '1' : '0'; ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
151ee7a932d598d42ba222c6c5df5229
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { private static void solve(String s, int n, int k){ int[] count = new int[n]; int remain = k; for(int i = 0; i < n; i++){ if(remain == 0){ break; ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
8a9d890a09829bfa617bf273b9e47fdb
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class B1659 { public static void main(String[] args) { InputStream inputStre...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
900d3afe5da91b1b5f92cce5c1f8b73b
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class c { static BufferedReader bf; static PrintWriter out; public static void main (String[] args)throws IOException { bf = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int t= nextInt(); wh...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
c973ed07aa93324a8abd4ac5a9a1a355
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class problemB { public static void main(String[] args)throws IOException { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
c474c9c9d3167d97f30bcd53885c1665
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; import java.math.*; /* Goal: Become better in CP! Key: Consistency and Discipline Desire: SDE @ Google USA Motto: Do what i Love <=> Love what i do If you don't use your brain 100%, it deteriorates gradually */ public class Coder { static StringBuffer s...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
0088f8ad37199250b532d6fd91f764ce
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; import java.math.*; /* Challenge 1: Newbie to CM in 1year (Dec 2021 - Nov 2022) 5* Codechef Challenge 2: CM to IM in 1 year (Dec 2022 - Nov 2023) 6* Codechef Challenge 3: IM to GM in 1 year (Dec 2023 - Nov 2024) 7* Codechef Goal: Become better in CP!...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
7c1494b7aed79b33bd27b9c64a993227
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.Scanner; public class Main { public static void solve(int n, int k, String s) { int[] count = new int[n]; StringBuilder sb = new StringBuilder(s); int lastIdx = -1, idx = 0, cnt = 0; while (k > 0 && idx < n) { //制造更多的高位0 if(k%2 == 0)...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
74731261fcb0ad54e5fa3c073ee226c0
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Contest782B{ public static PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new Pri...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
1e61f4c38705fd56ce500de7d6a2498b
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
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.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
9c6d3c06fb37a96f696cfd44344279a9
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; //import javafx.util.*; public class Main { static PrintWriter out = new PrintWriter(System.out); static FastReader in = new FastReader(); static int INF = Integer.MAX_VALUE; static int NINF = Integer.MIN_VALUE; public static void main (String[] args) t...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
ce344f2a5152adfa2989f7983dc0cde0
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class B { public static PrintWriter out; public static void main(String[] args)throws IOException{ Scanner sc=new Scanner(); out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
5084e066a83b96f41d95dc88f9a248db
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.TreeSet; public class B { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamR...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
6d778be09b9511e4f9acd887d2ada1cf
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Main { static int t; static int n; static int[] a; static String s; static FastReader fr = new FastReader(); static PrintWriter...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
e85bcc0da69bd64c4098fa69bb3a60b3
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.util.concurrent.LinkedBlockingDeque; import javax.sql.rowset.spi.SyncResolver; import java.io.*; import java.nio.channels.NonReadableChannelException; import java.text.DateFormatSymbols; public class CpTemp { static int a[]; static long count=0l; static long row...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
3035a8c234461638167c8846ec4f09a7
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; /** * * @author eslam */ public class IceCave { static class FastReader { BufferedReader br; ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
8419be8c231dde3ba9db753dae4a8121
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class Main { static TreeSet<String> tSet; static PrintWriter pw; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t=sc.nextInt(); while(t...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
39fef41caa364cbee475d57daa34dacf
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; public class Main { public static void main(String arggs[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); while(t-- > 0) { int n = sc.nextInt(), k = sc.nextInt(), cnt = 0, arr[] = new int[n]; String s = sc.next(); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
d636900aff0aab05a96b28cb41c709eb
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class _1659b { FastScanner scn; PrintWriter w; PrintStream fs; int MOD = 1000000007; int MAX = 200005; long mul(long x, long y) {long res = x * y; return (res >= MOD ? res % MOD : res);} long power(long x, long y) {if (y < 0) return ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
fc920d85a0686882bb2ba442e8f47bc3
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; /* 1 6 1 111001 */ public class B { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); in.nextLine(); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
d211f027c82f2a89aeaa7c8ad7ee2252
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); int t = sc.nextInt(); System.out.println(); while (t-- != 0){ int n = sc.nextInt(); int k ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
7a85d1420934b7af63b97d0bf8204e66
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
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) throws IOException{ /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. *...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
994866432eb7adbf0b1a6bbf6a4a0e35
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class Main { static long mod=(long)1e9+7; static long[]fac=new long[1002]; static int n, x=0,me,op; static int[]pe,a,aa, prime=new int[(int)1e7+1]; static int[][]perm; static long[][]memo; static Integer[]ps; static TreeSet<Long>p=new TreeSet<Long>(); p...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
2e408ae000676b46ec4c3cc27e976431
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class a { public static void main(String[] args){ FastScanner sc = new FastScanner(); int t = sc.nextInt(); while(t-- > 0){ int n = sc.nextInt(); int k = sc.nextInt(); String s = sc.next(); Stri...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
284dd35ef8ba3e1b70a77b708fa6b99a
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author real */ public class Main ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
6c4844b48373c5830e0d85b9c73c66ef
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; //import java.math.BigInteger; public class code{ public static class Pair{ int a; int b; Pair(int i,int j){ a=i; b=j; } } public static int GCD(int a, int b) { if (b == 0) return a; return GCD(b, a % b); }...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
a81a1b3d509a2dbc14dfc6b2527069e4
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.Scanner; public class BitFlipping { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t= sc.nextInt(); for(int i=0;i<t;i++){ int n= sc.nextInt(); int k=sc.nextInt(); int rest=k; String s=...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
b24dd08c11f91f7c79d9a5792d03e601
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; im...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
244bd78bf93586908f0201c8429d8be4
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.StreamTokenizer; import java.math.BigInteger; import static java.lang.System.out; import static java.lang.Math.*; import java.util.*; public class Main { public static ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
d5ee4f60393ad874c5c1885a40c23b1d
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class B { static class Pair { int f;int s; // Pair(){} Pair(int f,int s){ this.f=f;this.s=s;} } static class Fast { BufferedReader br; StringTokenizer st; public Fast() { br = new Bu...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
6cb80a100d3ce68258b991b381132a3e
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import org.omg.PortableInterceptor.INACTIVE; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; import java.util.StringTokenizer; public class B { static StringTokenizer st; static PrintWriter pw; s...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
71a599fea9a0c2678aabb53b937dbb72
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
/* * Author: rickytsung(En Chi Tsung) * Date: 2022/7/30 * Problem: CF Round 782 */ import java.util.*; import java.time.*; import java.io.*; import java.math.*; public class Main { public static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public static BufferedWriter bw=ne...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
81865ef55d7515044150abf63dfa0cdd
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; public class Balabizo { public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-->0){ int n = sc.nextInt...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
213a720f805dabbf4e3ef432cdb30260
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
//---#ON_MY_WAY--- //---#THE_SILENT_ONE--- import static java.lang.Math.*; import java.io.*; import java.math.*; import java.util.*; public class apples { static FastReader x = new FastReader(); static OutputStream outputStream = System.out; static PrintWriter out = new PrintWriter(outputStream); ...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
ee6286ed157dccb23eb4213b0382ff8f
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public class practice { public static void main(String[] args) throws Exception { Scanner s= new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int k=s.nextInt(); String str=s.next(); int arr[]= new int[n]; StringB...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
378b7b030900ee389e90927ba1bd463f
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.io.*; import java.util.*; public final class Main { //int 2e9 - long 9e18 static PrintWriter out = new PrintWriter(System.out); static FastReader in = new FastReader(); static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)}; static...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
237977e63bfa024d62d8c07182d8c952
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.Scanner; public class B1659 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int N = in.nextInt(); int K = in.nextInt(); char[] S = in.next().toChar...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
570f25620568055b262adfd54f32151f
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; public class class1 { public static void main(String[] args) { Scanner input =new Scanner(System.in); int t=input.nextInt(); while(t-->0) { int n=input.nextInt(); int k=input.nextInt(); int m=k,x=0; String s=input.next(); char c[]=s.toCharArray(); StringBuilder p=new St...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output
PASSED
dd1c73e00e7dec117756d86b00fc91a0
train_110.jsonl
1650206100
You are given a binary string of length $$$n$$$. You have exactly $$$k$$$ moves. In one move, you must select a single bit. The state of all bits except that bit will get flipped ($$$0$$$ becomes $$$1$$$, $$$1$$$ becomes $$$0$$$). You need to output the lexicographically largest string that you can get after using all ...
256 megabytes
import java.util.*; import java.io.*; import java.math.*; /* Challenge 1: Newbie to CM in 1year (Dec 2021 - Nov 2022) 5* Codechef Challenge 2: CM to IM in 1 year (Dec 2022 - Nov 2023) 6* Codechef Challenge 3: IM to GM in 1 year (Dec 2023 - Nov 2024) 7* Codechef Goal: Become better in CP...
Java
["6\n\n6 3\n\n100001\n\n6 4\n\n100011\n\n6 0\n\n000000\n\n6 1\n\n111001\n\n6 11\n\n101100\n\n6 12\n\n001110"]
1 second
["111110\n1 0 0 2 0 0 \n111110\n0 1 1 1 0 1 \n000000\n0 0 0 0 0 0 \n100110\n1 0 0 0 0 0 \n111111\n1 2 1 3 0 4 \n111110\n1 1 4 2 0 4"]
NoteHere is the explanation for the first testcase. Each step shows how the binary string changes in a move. Choose bit $$$1$$$: $$$\color{red}{\underline{1}00001} \rightarrow \color{red}{\underline{1}}\color{blue}{11110}$$$. Choose bit $$$4$$$: $$$\color{red}{111\underline{1}10} \rightarrow \color{blue}{000}\color{r...
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "strings" ]
38375efafa4861f3443126f20cacf3ae
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Each test case has two lines. The first line has two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$; $$$0 \leq k \leq 10^9$$$). The second line has a binary string of length $$$n$$$, each character is ...
1,300
For each test case, output two lines. The first line should contain the lexicographically largest string you can obtain. The second line should contain $$$n$$$ integers $$$f_1, f_2, \ldots, f_n$$$, where $$$f_i$$$ is the number of times the $$$i$$$-th bit is selected. The sum of all the integers must be equal to $$$k$$...
standard output