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
9c734831b4955415f795afd09b18ebaa
train_109.jsonl
1614071100
You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you pick some integer $$$k > 0$$$, take the top $$$k$$$ cards from the original deck and place them, in the order they are now, on top of the new deck. You perform this operation until the original deck is empty. (Refer to the notes section for the better understanding.)Let's define an order of a deck as $$$\sum\limits_{i = 1}^{n}{n^{n - i} \cdot p_i}$$$.Given the original deck, output the deck with maximum possible order you can make using the operation above.
512 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String args[]) throws Exception { BufferedReader Rb = new BufferedReader(new InputStreamReader(System.in)); int count = Integer.valueOf(Rb.readLine()); int counter = 0; while(counter++<count) { int n = Integer.valueOf(Rb.readLine()); String temp[] = Rb.readLine().split(" "); int array[] = new int[n]; ArrayList<Integer> sorter = new ArrayList<Integer>(); HashMap<Integer, Integer> hmap = new HashMap<Integer, Integer>(); for(int i = 0; i < n; i++) {array[i] = Integer.valueOf(temp[i]); sorter.add(array[i]); hmap.put(array[i], i);} Collections.sort(sorter); int end = n - 1; for(int i = n - 1; i > -1; i--) { if(hmap.get(sorter.get(i)) > end) {continue;} for(int j = hmap.get(sorter.get(i)); j <= end; j++) {System.out.print(array[j] + " ");} end = hmap.get(sorter.get(i)) - 1; } System.out.println(""); } } }
Java
["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"]
1 second
["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"]
NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[4, 3, 2]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[4, 3, 2, 1]$$$. In result, $$$p'$$$ has order equal to $$$4^3 \cdot 4 + 4^2 \cdot 3 + 4^1 \cdot 2 + 4^0 \cdot 1$$$ $$$=$$$ $$$256 + 48 + 8 + 1 = 313$$$.In the second test case, one of the optimal strategies is: take $$$4$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[5, 2, 4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[5, 2, 4, 3, 1]$$$; In result, $$$p'$$$ has order equal to $$$5^4 \cdot 5 + 5^3 \cdot 2 + 5^2 \cdot 4 + 5^1 \cdot 3 + 5^0 \cdot 1$$$ $$$=$$$ $$$3125 + 250 + 100 + 15 + 1 = 3491$$$.In the third test case, one of the optimal strategies is: take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2, 5, 3]$$$, $$$p'$$$ becomes $$$[6, 1]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2]$$$, $$$p'$$$ becomes $$$[6, 1, 5, 3]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[6, 1, 5, 3, 4, 2]$$$. In result, $$$p'$$$ has order equal to $$$6^5 \cdot 6 + 6^4 \cdot 1 + 6^3 \cdot 5 + 6^2 \cdot 3 + 6^1 \cdot 4 + 6^0 \cdot 2$$$ $$$=$$$ $$$46656 + 1296 + 1080 + 108 + 24 + 2 = 49166$$$.
Java 11
standard input
[ "data structures", "greedy", "math" ]
1637670255f8bd82a01e2ab20cdcc9aa
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — values of card in the deck from bottom to top. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,100
For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them.
standard output
PASSED
77e0427eff5477046d29a879f1dd6c8e
train_109.jsonl
1614071100
You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you pick some integer $$$k &gt; 0$$$, take the top $$$k$$$ cards from the original deck and place them, in the order they are now, on top of the new deck. You perform this operation until the original deck is empty. (Refer to the notes section for the better understanding.)Let's define an order of a deck as $$$\sum\limits_{i = 1}^{n}{n^{n - i} \cdot p_i}$$$.Given the original deck, output the deck with maximum possible order you can make using the operation above.
512 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.PriorityQueue; import java.util.StringTokenizer; import java.io.*; public class CardDeck { private static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void solution(int[] arr, int n) { boolean[] bool = new boolean[n]; int s = n-1; int[] deck = new int[n]; int i = n-1; int j = 0; while(j<n) { if(bool[s]) { while(bool[s]) s--; } int k = s+1; while(arr[i]!=k) i--; int t = i; int z = (n-t)-j; while(z-->0) { bool[arr[t]-1] = true; deck[j++] = arr[t++]; } s--; } for(int m = 0; m<n; m++) { out.print(deck[m]+" "); } } private static PrintWriter out = new PrintWriter(System.out); public static void main (String[] args) { MyScanner s = new MyScanner(); int t = s.nextInt(); for(int j = 0; j<t ; j++) { int n = s.nextInt(); int[] arr = new int[n]; for(int i =0; i<n; i++) arr[i] = s.nextInt(); solution(arr,n); out.println(); } out.flush(); out.close(); } }
Java
["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"]
1 second
["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"]
NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[4, 3, 2]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[4, 3, 2, 1]$$$. In result, $$$p'$$$ has order equal to $$$4^3 \cdot 4 + 4^2 \cdot 3 + 4^1 \cdot 2 + 4^0 \cdot 1$$$ $$$=$$$ $$$256 + 48 + 8 + 1 = 313$$$.In the second test case, one of the optimal strategies is: take $$$4$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[5, 2, 4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[5, 2, 4, 3, 1]$$$; In result, $$$p'$$$ has order equal to $$$5^4 \cdot 5 + 5^3 \cdot 2 + 5^2 \cdot 4 + 5^1 \cdot 3 + 5^0 \cdot 1$$$ $$$=$$$ $$$3125 + 250 + 100 + 15 + 1 = 3491$$$.In the third test case, one of the optimal strategies is: take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2, 5, 3]$$$, $$$p'$$$ becomes $$$[6, 1]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2]$$$, $$$p'$$$ becomes $$$[6, 1, 5, 3]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[6, 1, 5, 3, 4, 2]$$$. In result, $$$p'$$$ has order equal to $$$6^5 \cdot 6 + 6^4 \cdot 1 + 6^3 \cdot 5 + 6^2 \cdot 3 + 6^1 \cdot 4 + 6^0 \cdot 2$$$ $$$=$$$ $$$46656 + 1296 + 1080 + 108 + 24 + 2 = 49166$$$.
Java 11
standard input
[ "data structures", "greedy", "math" ]
1637670255f8bd82a01e2ab20cdcc9aa
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — values of card in the deck from bottom to top. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,100
For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them.
standard output
PASSED
e1af5ad4dbb10d393992d12f19498a2a
train_109.jsonl
1614071100
You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you pick some integer $$$k &gt; 0$$$, take the top $$$k$$$ cards from the original deck and place them, in the order they are now, on top of the new deck. You perform this operation until the original deck is empty. (Refer to the notes section for the better understanding.)Let's define an order of a deck as $$$\sum\limits_{i = 1}^{n}{n^{n - i} \cdot p_i}$$$.Given the original deck, output the deck with maximum possible order you can make using the operation above.
512 megabytes
//package clipse; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; import java.io.*; import java.math.*; public class A { static StringBuilder sb; static dsu dsu; static void solve() { int n=i(); int A[]=new int[n]; int index[]=new int[n+1]; for(int i=0;i<n;i++) { A[i]=i(); index[A[i]]=i; } ArrayList<Integer>l=new ArrayList<>(); boolean visited[]=new boolean[n+1]; int last=n; for(int i=n;i>=1;i--) { int ind=index[i]; if(ind<last) { for(int j=ind;j<last;j++) { l.add(A[j]); } last=ind; } } for(int a:l) System.out.print(a+" "); System.out.println(); } public static void main(String[] args) { sb=new StringBuilder(); int test=i(); while(test-->0) { solve(); } System.out.println(sb); } //*********************************Disjoint set union*************************// static class dsu { int parent[]; dsu(int n) { parent=new int[n]; for(int i=0;i<n;i++) parent[i]=-1; } int find(int a) { if(parent[a]<0) return a; else { int x=find(parent[a]); parent[a]=x; return x; } } void merge(int a,int b) { a=find(a); b=find(b); if(a==b) return; parent[b]=a; } } //*******************************************PRIME FACTORIZE *****************************************************************************************************// static TreeMap<Integer,Integer> prime(long n) { TreeMap<Integer,Integer>h=new TreeMap<>(); long num=n; for(int i=2;i<=Math.sqrt(num);i++) { if(n%i==0) { int nt=0; while(n%i==0) { n=n/i; nt++; } h.put(i, nt); } } if(n!=1) h.put((int)n, 1); return h; } //*************CLASS PAIR *********************************************************************************************************************************************** static class pair implements Comparable<pair> { int x; int y; pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(pair o) { return x-o.x==0?y-o.y:x-o.x; } } //*************CLASS PAIR ***************************************************************************************************************************************************** static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int Int() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String String() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return String(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } static InputReader in = new InputReader(System.in); static OutputWriter out = new OutputWriter(System.out); static int modulus = (int) 1e7; public static int[] sort(int[] a) { int n = a.length; ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < l.size(); i++) a[i] = l.get(i); return a; } public static long pow(long x, long y) { long res = 1; while (y > 0) { if (y % 2 != 0) { res = (res * x) % modulus; y--; } x = (x * x) % modulus; y = y / 2; } return res; } //GCD___+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public static long gcd(long x, long y) { if (x == 0) return y; else return gcd(y % x, x); } //****************LOWEST COMMON MULTIPLE ************************************************************************************************************************************* public static long lcm(long x, long y) { return (x * (y / gcd(x, y))); } //INPUT PATTERN****************************************************************************************************************************************************************** public static int i() { return in.Int(); } public static long l() { String s = in.String(); return Long.parseLong(s); } public static String s() { return in.String(); } public static int[] readArray(int n) { int A[] = new int[n]; for (int i = 0; i < n; i++) { A[i] = i(); } return A; } public static long[] readArray(long n) { long A[] = new long[(int) n]; for (int i = 0; i < n; i++) { A[i] = l(); } return A; } }
Java
["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"]
1 second
["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"]
NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[4, 3, 2]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[4, 3, 2, 1]$$$. In result, $$$p'$$$ has order equal to $$$4^3 \cdot 4 + 4^2 \cdot 3 + 4^1 \cdot 2 + 4^0 \cdot 1$$$ $$$=$$$ $$$256 + 48 + 8 + 1 = 313$$$.In the second test case, one of the optimal strategies is: take $$$4$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[5, 2, 4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[5, 2, 4, 3, 1]$$$; In result, $$$p'$$$ has order equal to $$$5^4 \cdot 5 + 5^3 \cdot 2 + 5^2 \cdot 4 + 5^1 \cdot 3 + 5^0 \cdot 1$$$ $$$=$$$ $$$3125 + 250 + 100 + 15 + 1 = 3491$$$.In the third test case, one of the optimal strategies is: take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2, 5, 3]$$$, $$$p'$$$ becomes $$$[6, 1]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2]$$$, $$$p'$$$ becomes $$$[6, 1, 5, 3]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[6, 1, 5, 3, 4, 2]$$$. In result, $$$p'$$$ has order equal to $$$6^5 \cdot 6 + 6^4 \cdot 1 + 6^3 \cdot 5 + 6^2 \cdot 3 + 6^1 \cdot 4 + 6^0 \cdot 2$$$ $$$=$$$ $$$46656 + 1296 + 1080 + 108 + 24 + 2 = 49166$$$.
Java 11
standard input
[ "data structures", "greedy", "math" ]
1637670255f8bd82a01e2ab20cdcc9aa
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — values of card in the deck from bottom to top. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,100
For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them.
standard output
PASSED
c1109e27beab1a5249867448b06a5d39
train_109.jsonl
1614071100
You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you pick some integer $$$k &gt; 0$$$, take the top $$$k$$$ cards from the original deck and place them, in the order they are now, on top of the new deck. You perform this operation until the original deck is empty. (Refer to the notes section for the better understanding.)Let's define an order of a deck as $$$\sum\limits_{i = 1}^{n}{n^{n - i} \cdot p_i}$$$.Given the original deck, output the deck with maximum possible order you can make using the operation above.
512 megabytes
// Working program using Reader Class import java.io.*; import java.util.*; public class Hello { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if (st.hasMoreTokens()) { str = st.nextToken("\n"); } else { str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } static BufferedWriter output = new BufferedWriter( new OutputStreamWriter(System.out)); public static void main(String[] args) throws IOException { FastReader input = new FastReader(); int t = input.nextInt(); for(int i = 0; i<t; i++){ int n = input.nextInt(); int[]arr = new int[n]; Stack st = new Stack<Pair>(); for(int j = 0; j<arr.length; j++){ arr[j] = input.nextInt(); }int current = arr[0]; st.push(new Pair(arr[0],0)); for(int j= 0; j<arr.length; j++){ if(current<arr[j]){ st.push(new Pair(arr[j],j)); current = arr[j]; } }int old = n; while(!st.isEmpty()){ Pair curr = (Pair) st.pop(); for(int j= curr.y; j< old; j++){ output.write(arr[j]+" "); }old = curr.y; }output.write("\n"); } output.close(); } static class Pair implements Comparable<Pair> { int x; int y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { if (this.x == o.x) return 0; else return this.x - o.x; } } }
Java
["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"]
1 second
["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"]
NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[4, 3, 2]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[4, 3, 2, 1]$$$. In result, $$$p'$$$ has order equal to $$$4^3 \cdot 4 + 4^2 \cdot 3 + 4^1 \cdot 2 + 4^0 \cdot 1$$$ $$$=$$$ $$$256 + 48 + 8 + 1 = 313$$$.In the second test case, one of the optimal strategies is: take $$$4$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[5, 2, 4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[5, 2, 4, 3, 1]$$$; In result, $$$p'$$$ has order equal to $$$5^4 \cdot 5 + 5^3 \cdot 2 + 5^2 \cdot 4 + 5^1 \cdot 3 + 5^0 \cdot 1$$$ $$$=$$$ $$$3125 + 250 + 100 + 15 + 1 = 3491$$$.In the third test case, one of the optimal strategies is: take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2, 5, 3]$$$, $$$p'$$$ becomes $$$[6, 1]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2]$$$, $$$p'$$$ becomes $$$[6, 1, 5, 3]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[6, 1, 5, 3, 4, 2]$$$. In result, $$$p'$$$ has order equal to $$$6^5 \cdot 6 + 6^4 \cdot 1 + 6^3 \cdot 5 + 6^2 \cdot 3 + 6^1 \cdot 4 + 6^0 \cdot 2$$$ $$$=$$$ $$$46656 + 1296 + 1080 + 108 + 24 + 2 = 49166$$$.
Java 17
standard input
[ "data structures", "greedy", "math" ]
1637670255f8bd82a01e2ab20cdcc9aa
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — values of card in the deck from bottom to top. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,100
For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them.
standard output
PASSED
b431f3aedda4af74368e582f3f2796cd
train_109.jsonl
1614071100
You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you pick some integer $$$k &gt; 0$$$, take the top $$$k$$$ cards from the original deck and place them, in the order they are now, on top of the new deck. You perform this operation until the original deck is empty. (Refer to the notes section for the better understanding.)Let's define an order of a deck as $$$\sum\limits_{i = 1}^{n}{n^{n - i} \cdot p_i}$$$.Given the original deck, output the deck with maximum possible order you can make using the operation above.
512 megabytes
import java.util.*; import java.math.*; import java.io.*; public class A1{ static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); static StringTokenizer st; static final long mod=1000000007; public static void Solve() throws IOException{ st=new StringTokenizer(br.readLine()); int n=Integer.parseInt(st.nextToken()); int[] ar=getArrIn(n); boolean[] bool=new boolean[n+1]; Map<Integer,Integer> at=new TreeMap<>(Collections.reverseOrder()); for(int i=0;i<n;i++) at.put(ar[i],i); int c=0; for(int i:at.keySet()){ int j=at.get(i); if(c==n) break; for(int k=j;k<n;k++){ if(bool[ar[k]]) break; c++; bw.write(ar[k]+" "); bool[ar[k]]=true; } } bw.newLine(); } /** Main Method**/ public static void main(String[] YDSV) throws IOException{ //int t=1; int t=Integer.parseInt(br.readLine()); while(t-->0) Solve(); bw.flush(); } /** Helpers**/ private static char[] getStr()throws IOException{ return br.readLine().toCharArray(); } private static int Gcd(int a,int b){ if(b==0) return a; return Gcd(b,a%b); } private static long Gcd(long a,long b){ if(b==0) return a; return Gcd(b,a%b); } private static int[] getArrIn(int n) throws IOException{ st=new StringTokenizer(br.readLine()); int[] ar=new int[n]; for(int i=0;i<n;i++) ar[i]=Integer.parseInt(st.nextToken()); return ar; } private static Integer[] getArrInP(int n) throws IOException{ st=new StringTokenizer(br.readLine()); Integer[] ar=new Integer[n]; for(int i=0;i<n;i++) ar[i]=Integer.parseInt(st.nextToken()); return ar; } private static long[] getArrLo(int n) throws IOException{ st=new StringTokenizer(br.readLine()); long[] ar=new long[n]; for(int i=0;i<n;i++) ar[i]=Long.parseLong(st.nextToken()); return ar; } private static List<Integer> getListIn(int n) throws IOException{ st=new StringTokenizer(br.readLine()); List<Integer> al=new ArrayList<>(); for(int i=0;i<n;i++) al.add(Integer.parseInt(st.nextToken())); return al; } private static List<Long> getListLo(int n) throws IOException{ st=new StringTokenizer(br.readLine()); List<Long> al=new ArrayList<>(); for(int i=0;i<n;i++) al.add(Long.parseLong(st.nextToken())); return al; } private static long pow_mod(long a,long b) { long result=1; while(b!=0){ if((b&1)!=0) result=(result*a)%mod; a=(a*a)%mod; b>>=1; } return result; } private static int pow_mod(int a,int b) { int result=1; int mod1=(int)mod; while(b!=0){ if((b&1)!=0) result=(result*a)%mod1; a=(a*a)%mod1; b>>=1; } return result; } private static int lower_bound(int a[],int x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r+1; } private static long lower_bound(long a[],long x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r+1; } private static int upper_bound(int a[],int x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } private static long upper_bound(long a[],long x){ int l=-1,r=a.length; while(l+1<r){ int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } private static boolean Sqrt(int x){ int a=(int)Math.sqrt(x); return a*a==x; } private static boolean Sqrt(long x){ long a=(long)Math.sqrt(x); return a*a==x; } }
Java
["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"]
1 second
["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"]
NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[4, 3, 2]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[4, 3, 2, 1]$$$. In result, $$$p'$$$ has order equal to $$$4^3 \cdot 4 + 4^2 \cdot 3 + 4^1 \cdot 2 + 4^0 \cdot 1$$$ $$$=$$$ $$$256 + 48 + 8 + 1 = 313$$$.In the second test case, one of the optimal strategies is: take $$$4$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[5, 2, 4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[5, 2, 4, 3, 1]$$$; In result, $$$p'$$$ has order equal to $$$5^4 \cdot 5 + 5^3 \cdot 2 + 5^2 \cdot 4 + 5^1 \cdot 3 + 5^0 \cdot 1$$$ $$$=$$$ $$$3125 + 250 + 100 + 15 + 1 = 3491$$$.In the third test case, one of the optimal strategies is: take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2, 5, 3]$$$, $$$p'$$$ becomes $$$[6, 1]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2]$$$, $$$p'$$$ becomes $$$[6, 1, 5, 3]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[6, 1, 5, 3, 4, 2]$$$. In result, $$$p'$$$ has order equal to $$$6^5 \cdot 6 + 6^4 \cdot 1 + 6^3 \cdot 5 + 6^2 \cdot 3 + 6^1 \cdot 4 + 6^0 \cdot 2$$$ $$$=$$$ $$$46656 + 1296 + 1080 + 108 + 24 + 2 = 49166$$$.
Java 17
standard input
[ "data structures", "greedy", "math" ]
1637670255f8bd82a01e2ab20cdcc9aa
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — values of card in the deck from bottom to top. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,100
For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them.
standard output
PASSED
ae986cf7ce79dcbee893d39c6fa2e456
train_109.jsonl
1614071100
You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you pick some integer $$$k &gt; 0$$$, take the top $$$k$$$ cards from the original deck and place them, in the order they are now, on top of the new deck. You perform this operation until the original deck is empty. (Refer to the notes section for the better understanding.)Let's define an order of a deck as $$$\sum\limits_{i = 1}^{n}{n^{n - i} \cdot p_i}$$$.Given the original deck, output the deck with maximum possible order you can make using the operation above.
512 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; /** * * @author eslam */ public class Solution { // Beginning of the solution static Kattio input = new Kattio(); static BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); static ArrayList<ArrayList<Integer>> powerSet = new ArrayList<>(); static ArrayList<LinkedList<Integer>> allprem = new ArrayList<>(); static ArrayList<LinkedList<String>> allprems = new ArrayList<>(); static ArrayList<Long> luc = new ArrayList<>(); static long mod = (long) (Math.pow(10, 9) + 7); static int grid[][] = {{0, 0, 1, -1, 1, 1, -1, -1}, {1, -1, 0, 0, 1, -1, 1, -1}}; static int dp[][]; static double cmp = 0.000000001; public static void main(String[] args) throws IOException { // Kattio input = new Kattio("input"); // BufferedWriter log = new BufferedWriter(new FileWriter("output.txt")); int test = input.nextInt(); loop: for (int o = 1; o <= test; o++) { int n = input.nextInt(); int a[] = new int[n]; TreeSet<Integer> s = new TreeSet<>(); LinkedList<Integer> ans = new LinkedList<>(); for (int i = 0; i < n; i++) { a[i] = input.nextInt(); s.add(i + 1); } int cur = n - 1; while (!s.isEmpty()) { Stack<Integer> st = new Stack<>(); while (cur > -1) { st.add(a[cur]); if (a[cur] == s.last()) { s.pollLast(); cur--; break; } s.remove(a[cur--]); } while (!st.isEmpty()) { ans.add(st.pop()); } } for (Integer an : ans) { log.write(an + " "); } log.write("\n"); } log.flush(); } static Comparator<tri> cmpTri() { Comparator<tri> c = new Comparator<tri>() { @Override public int compare(tri o1, tri o2) { if (o1.x > o2.x) { return 1; } else if (o1.x < o2.x) { return -1; } else { if (o1.y > o2.y) { return 1; } else if (o1.y < o2.y) { return -1; } else { if (o1.z > o2.z) { return 1; } else if (o1.z < o2.z) { return -1; } else { return 0; } } } } }; return c; } static Comparator<pair> cmpPair() { Comparator<pair> c = new Comparator<pair>() { @Override public int compare(pair o1, pair o2) { if (o1.x > o2.x) { return 1; } else if (o1.x < o2.x) { return -1; } else { if (o1.y > o2.y) { return 1; } else if (o1.y < o2.y) { return -1; } else { return 0; } } } }; return c; } static class rec { long x1; long x2; long y1; long y2; public rec(long x1, long y1, long x2, long y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; } public long getArea() { return (x2 - x1) * (y2 - y1); } } static int sumOfRange(int x1, int y1, int x2, int y2, int e, int a[][][]) { return (a[e][x2][y2] - a[e][x1 - 1][y2] - a[e][x2][y1 - 1]) + a[e][x1 - 1][y1 - 1]; } public static int[][] bfs(int i, int j, String w[]) { Queue<pair> q = new ArrayDeque<>(); q.add(new pair(i, j)); int dis[][] = new int[w.length][w[0].length()]; for (int k = 0; k < w.length; k++) { Arrays.fill(dis[k], -1); } dis[i][j] = 0; while (!q.isEmpty()) { pair p = q.poll(); int cost = dis[p.x][p.y]; for (int k = 0; k < 4; k++) { int nx = p.x + grid[0][k]; int ny = p.y + grid[1][k]; if (isValid(nx, ny, w.length, w[0].length())) { if (dis[nx][ny] == -1 && w[nx].charAt(ny) == '.') { q.add(new pair(nx, ny)); dis[nx][ny] = cost + 1; } } } } return dis; } public static void dfs(int node, ArrayList<Integer> a[], boolean vi[]) { vi[node] = true; for (Integer ch : a[node]) { if (!vi[ch]) { dfs(ch, a, vi); } } } public static void graphRepresintion(ArrayList<Integer>[] a, int q) throws IOException { for (int i = 0; i < a.length; i++) { a[i] = new ArrayList<>(); } while (q-- > 0) { int x = input.nextInt(); int y = input.nextInt(); a[x].add(y); a[y].add(x); } } public static boolean isValid(int i, int j, int n, int m) { return (i > -1 && i < n) && (j > -1 && j < m); } // present in the left and right indices public static int[] swap(int data[], int left, int right) { // Swap the data int temp = data[left]; data[left] = data[right]; data[right] = temp; // Return the updated array return data; } // Function to reverse the sub-array // starting from left to the right // both inclusive public static int[] reverse(int data[], int left, int right) { // Reverse the sub-array while (left < right) { int temp = data[left]; data[left++] = data[right]; data[right--] = temp; } // Return the updated array return data; } // Function to find the next permutation // of the given integer array public static boolean findNextPermutation(int data[]) { // If the given dataset is empty // or contains only one element // next_permutation is not possible if (data.length <= 1) { return false; } int last = data.length - 2; // find the longest non-increasing suffix // and find the pivot while (last >= 0) { if (data[last] < data[last + 1]) { break; } last--; } // If there is no increasing pair // there is no higher order permutation if (last < 0) { return false; } int nextGreater = data.length - 1; // Find the rightmost successor to the pivot for (int i = data.length - 1; i > last; i--) { if (data[i] > data[last]) { nextGreater = i; break; } } // Swap the successor and the pivot data = swap(data, nextGreater, last); // Reverse the suffix data = reverse(data, last + 1, data.length - 1); // Return true as the next_permutation is done return true; } public static pair[] dijkstra(int node, ArrayList<pair> a[]) { PriorityQueue<tri> q = new PriorityQueue<>(new Comparator<tri>() { @Override public int compare(tri o1, tri o2) { if (o1.y > o2.y) { return 1; } else if (o1.y < o2.y) { return -1; } else { return 0; } } }); q.add(new tri(node, 0, -1)); pair distance[] = new pair[a.length]; while (!q.isEmpty()) { tri p = q.poll(); int cost = p.y; if (distance[p.x] != null) { continue; } distance[p.x] = new pair(p.z, cost); ArrayList<pair> nodes = a[p.x]; for (pair node1 : nodes) { if (distance[node1.x] == null) { tri pa = new tri(node1.x, cost + node1.y, p.x); q.add(pa); } } } return distance; } public static String revs(String w) { String ans = ""; for (int i = w.length() - 1; i > -1; i--) { ans += w.charAt(i); } return ans; } public static boolean isPalindrome(String w) { for (int i = 0; i < w.length() / 2; i++) { if (w.charAt(i) != w.charAt(w.length() - i - 1)) { return false; } } return true; } public static void getPowerSet(Queue<Integer> a) { int n = a.poll(); if (!a.isEmpty()) { getPowerSet(a); } int s = powerSet.size(); for (int i = 0; i < s; i++) { ArrayList<Integer> ne = new ArrayList<>(); ne.add(n); for (int j = 0; j < powerSet.get(i).size(); j++) { ne.add(powerSet.get(i).get(j)); } powerSet.add(ne); } ArrayList<Integer> p = new ArrayList<>(); p.add(n); powerSet.add(p); } public static int getlo(int va) { int v = 1; while (v <= va) { if ((va&v) != 0) { return v; } v <<= 1; } return 0; } static long fast_pow(long a, long p, long mod) { long res = 1; while (p > 0) { if (p % 2 == 0) { a = (a * a) % mod; p /= 2; } else { res = (res * a) % mod; p--; } } return res; } public static int countPrimeInRange(int n, boolean isPrime[]) { int cnt = 0; Arrays.fill(isPrime, true); for (int i = 2; i * i <= n; i++) { if (isPrime[i]) { for (int j = i * 2; j <= n; j += i) { isPrime[j] = false; } } } for (int i = 2; i <= n; i++) { if (isPrime[i]) { cnt++; } } return cnt; } public static void create(long num) { luc.add(num); if (num > power(10, 9)) { return; } create(num * 10 + 4); create(num * 10 + 7); } public static long ceil(long a, long b) { return (a + b - 1) / b; } public static long round(long a, long b) { if (a < 0) { return (a - b / 2) / b; } return (a + b / 2) / b; } public static void allPremutationsst(LinkedList<String> l, boolean visited[], ArrayList<String> st) { if (l.size() == st.size()) { allprems.add(l); } for (int i = 0; i < st.size(); i++) { if (!visited[i]) { visited[i] = true; LinkedList<String> nl = new LinkedList<>(); for (String x : l) { nl.add(x); } nl.add(st.get(i)); allPremutationsst(nl, visited, st); visited[i] = false; } } } public static void allPremutations(LinkedList<Integer> l, boolean visited[], int a[]) { if (l.size() == a.length) { allprem.add(l); } for (int i = 0; i < a.length; i++) { if (!visited[i]) { visited[i] = true; LinkedList<Integer> nl = new LinkedList<>(); for (Integer x : l) { nl.add(x); } nl.add(a[i]); allPremutations(nl, visited, a); visited[i] = false; } } } public static int binarySearch(long[] a, long value) { int l = 0; int r = a.length - 1; while (l <= r) { int m = (l + r) / 2; if (a[m] == value) { return m; } else if (a[m] > value) { r = m - 1; } else { l = m + 1; } } return -1; } public static void reverse(int l, int r, char ch[]) { for (int i = 0; i < r / 2; i++) { char c = ch[i]; ch[i] = ch[r - i - 1]; ch[r - i - 1] = c; } } public static int logK(long v, long k) { int ans = 0; while (v > 1) { ans++; v /= k; } return ans; } public static long power(long a, long n) { if (n == 1) { return a; } long pow = power(a, n / 2); pow *= pow; if (n % 2 != 0) { pow *= a; } return pow; } public static long get(long max, long x) { if (x == 1) { return max; } int cnt = 0; while (max > 0) { cnt++; max /= x; } return cnt; } public static int numOF0(long v) { long x = 1; int cnt = 0; while (x <= v) { if ((x & v) == 0) { cnt++; } x <<= 1; } return cnt; } public static int log2(double n) { int cnt = 0; while (n > 1) { n /= 2; cnt++; } return cnt; } public static int[] bfs(int node, ArrayList<Integer> a[]) { Queue<Integer> q = new LinkedList<>(); q.add(node); int distances[] = new int[a.length]; Arrays.fill(distances, -1); distances[node] = 0; while (!q.isEmpty()) { int parent = q.poll(); ArrayList<Integer> nodes = a[parent]; int cost = distances[parent]; for (Integer node1 : nodes) { if (distances[node1] == -1) { q.add(node1); distances[node1] = cost + 1; } } } return distances; } public static ArrayList<Integer> primeFactors(int n) { ArrayList<Integer> a = new ArrayList<>(); while (n % 2 == 0) { a.add(2); n /= 2; } for (int i = 3; i <= Math.sqrt(n); i += 2) { while (n % i == 0) { a.add(i); n /= i; } if (n < i) { break; } } if (n > 2) { a.add(n); } return a; } public static ArrayList<Integer> printPrimeFactoriztion(int n) { ArrayList<Integer> a = new ArrayList<>(); for (int i = 1; i < Math.sqrt(n) + 1; i++) { if (n % i == 0) { if (isPrime(i)) { a.add(i); n /= i; i = 0; } else if (isPrime(n / i)) { a.add(n / i); n = i; i = 0; } } } return a; } // end of solution public static BigInteger f(long n) { if (n <= 1) { return BigInteger.ONE; } long t = n - 1; BigInteger b = new BigInteger(t + ""); BigInteger ans = new BigInteger(n + ""); while (t > 1) { ans = ans.multiply(b); b = b.subtract(BigInteger.ONE); t--; } return ans; } public static long factorial(long n) { if (n <= 1) { return 1; } long t = n - 1; while (t > 1) { n = mod((mod(n, mod) * mod(t, mod)), mod); t--; } return n; } public static long rev(long n) { long t = n; long ans = 0; while (t > 0) { ans = ans * 10 + t % 10; t /= 10; } return ans; } public static boolean isPalindrome(int n) { int t = n; int ans = 0; while (t > 0) { ans = ans * 10 + t % 10; t /= 10; } return ans == n; } static class tri { int x, y, z; public tri(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } @Override public String toString() { return x + " " + y + " " + z; } } static boolean isPrime(long num) { if (num == 1) { return false; } if (num == 2) { return true; } if (num % 2 == 0) { return false; } if (num == 3) { return true; } for (int i = 3; i <= Math.sqrt(num) + 1; i += 2) { if (num % i == 0) { return false; } } return true; } public static void prefixSum(int[] a) { for (int i = 1; i < a.length; i++) { a[i] = a[i] + a[i - 1]; } } public static void suffixSum(long[] a) { for (int i = a.length - 2; i > -1; i--) { a[i] = a[i] + a[i + 1]; } } static long mod(long a, long b) { long r = a % b; return r < 0 ? r + b : r; } public static long binaryToDecimal(String w) { long r = 0; long l = 0; for (int i = w.length() - 1; i > -1; i--) { long x = (w.charAt(i) - '0') * (long) Math.pow(2, l); r = r + x; l++; } return r; } public static String decimalToBinary(long n) { String w = ""; while (n > 0) { w = n % 2 + w; n /= 2; } return w; } public static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] >= a[i + 1]) { return false; } } return true; } public static void print(int[] a) throws IOException { for (int i = 0; i < a.length; i++) { log.write(a[i] + " "); } log.write("\n"); } public static void read(int[] a) { for (int i = 0; i < a.length; i++) { a[i] = input.nextInt(); } } static class gepair { long x; long y; public gepair(long x, long y) { this.x = x; this.y = y; } @Override public String toString() { return x + " " + y; } } static class pair { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } @Override public String toString() { return x + " " + y; } } static class pai { long x; int y; public pai(long x, int y) { this.x = x; this.y = y; } @Override public String toString() { return x + " " + y; } } public static long LCM(long x, long y) { return x / GCD(x, y) * y; } public static long GCD(long x, long y) { if (y == 0) { return x; } return GCD(y, x % y); } public static void simplifyTheFraction(int a, int b) { long GCD = GCD(a, b); System.out.println(a / GCD + " " + b / GCD); } static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in, System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(problemName + ".out"); r = new BufferedReader(new FileReader(problemName + ".in")); } // returns null if no more input String nextLine() { String str = ""; try { str = r.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(r.readLine()); } return st.nextToken(); } catch (Exception e) { } return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"]
1 second
["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"]
NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[4, 3, 2]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[4, 3, 2, 1]$$$. In result, $$$p'$$$ has order equal to $$$4^3 \cdot 4 + 4^2 \cdot 3 + 4^1 \cdot 2 + 4^0 \cdot 1$$$ $$$=$$$ $$$256 + 48 + 8 + 1 = 313$$$.In the second test case, one of the optimal strategies is: take $$$4$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[5, 2, 4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[5, 2, 4, 3, 1]$$$; In result, $$$p'$$$ has order equal to $$$5^4 \cdot 5 + 5^3 \cdot 2 + 5^2 \cdot 4 + 5^1 \cdot 3 + 5^0 \cdot 1$$$ $$$=$$$ $$$3125 + 250 + 100 + 15 + 1 = 3491$$$.In the third test case, one of the optimal strategies is: take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2, 5, 3]$$$, $$$p'$$$ becomes $$$[6, 1]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2]$$$, $$$p'$$$ becomes $$$[6, 1, 5, 3]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[6, 1, 5, 3, 4, 2]$$$. In result, $$$p'$$$ has order equal to $$$6^5 \cdot 6 + 6^4 \cdot 1 + 6^3 \cdot 5 + 6^2 \cdot 3 + 6^1 \cdot 4 + 6^0 \cdot 2$$$ $$$=$$$ $$$46656 + 1296 + 1080 + 108 + 24 + 2 = 49166$$$.
Java 17
standard input
[ "data structures", "greedy", "math" ]
1637670255f8bd82a01e2ab20cdcc9aa
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — values of card in the deck from bottom to top. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,100
For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them.
standard output
PASSED
f78300f27db6d57bd6f8433a9d529713
train_109.jsonl
1614071100
You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you pick some integer $$$k &gt; 0$$$, take the top $$$k$$$ cards from the original deck and place them, in the order they are now, on top of the new deck. You perform this operation until the original deck is empty. (Refer to the notes section for the better understanding.)Let's define an order of a deck as $$$\sum\limits_{i = 1}^{n}{n^{n - i} \cdot p_i}$$$.Given the original deck, output the deck with maximum possible order you can make using the operation above.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { static final PrintWriter out =new PrintWriter(System.out); static final FastReader sc = new FastReader(); //I invented a new word!Plagiarism! //Did you hear about the mathematician who’s afraid of negative numbers?He’ll stop at nothing to avoid them //What do Alexander the Great and Winnie the Pooh have in common? Same middle name. //I finally decided to sell my vacuum cleaner. All it was doing was gathering dust! //ArrayList<Integer> a=new ArrayList <Integer>(); //PriorityQueue<Integer> pq=new PriorityQueue<>(); //char[] a = s.toCharArray(); public static void main (String[] args) throws java.lang.Exception { int tes=sc.nextInt(); while(tes-->0) { TreeSet<Integer> ts=new TreeSet<Integer>(); int n=sc.nextInt(); int a[]=new int[n]; int pos[]=new int[n+1]; int i,j=n-1,end=n; for(i=0;i<n;i++) { a[i]=sc.nextInt(); pos[a[i]]=i; ts.add(a[i]); } while(!ts.isEmpty()) { int max=ts.last(); int start=pos[max]; for(i=start;i<end;i++) { System.out.print(a[i]+" "); ts.remove(a[i]); } end=start; } System.out.println(); } } public static int lis(int[] arr) { int n = arr.length; ArrayList<Integer> al = new ArrayList<Integer>(); al.add(arr[0]); for(int i = 1 ; i<n;i++) { int x = al.get(al.size()-1); if(arr[i]>=x) { al.add(arr[i]); }else { int v = upper_bound(al, 0, al.size(), arr[i]); al.set(v, arr[i]); } } return al.size(); } public static long lower_bound(ArrayList<Long> ar,long lo , long hi , long k) { long s=lo; long e=hi; while (s !=e) { long mid = s+e>>1; if (ar.get((int)mid) <k) { s=mid+1; } else { e=mid; } } if(s==ar.size()) { return -1; } return s; } public static int upper_bound(ArrayList<Integer> ar,int lo , int hi, int k) { int s=lo; int e=hi; while (s !=e) { int mid = s+e>>1; if (ar.get(mid) <=k) { s=mid+1; } else { e=mid; } } if(s==ar.size()) { return -1; } return s; } static boolean isPrime(long N) { if (N<=1) return false; if (N<=3) return true; if (N%2 == 0 || N%3 == 0) return false; for (int i=5; i*i<=N; i=i+6) if (N%i == 0 || N%(i+2) == 0) return false; return true; } static int countBits(long a) { return (int)(Math.log(a)/Math.log(2)+1); } static long fact(long N) { long mod=1000000007; long n=2; if(N<=1)return 1; else { for(int i=3; i<=N; i++)n=(n*i)%mod; } return n; } private static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) if (str.charAt(i++) != str.charAt(j--)) return false; return true; } private static String reverseString(String str) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"]
1 second
["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"]
NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[4, 3, 2]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[4, 3, 2, 1]$$$. In result, $$$p'$$$ has order equal to $$$4^3 \cdot 4 + 4^2 \cdot 3 + 4^1 \cdot 2 + 4^0 \cdot 1$$$ $$$=$$$ $$$256 + 48 + 8 + 1 = 313$$$.In the second test case, one of the optimal strategies is: take $$$4$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[5, 2, 4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[5, 2, 4, 3, 1]$$$; In result, $$$p'$$$ has order equal to $$$5^4 \cdot 5 + 5^3 \cdot 2 + 5^2 \cdot 4 + 5^1 \cdot 3 + 5^0 \cdot 1$$$ $$$=$$$ $$$3125 + 250 + 100 + 15 + 1 = 3491$$$.In the third test case, one of the optimal strategies is: take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2, 5, 3]$$$, $$$p'$$$ becomes $$$[6, 1]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2]$$$, $$$p'$$$ becomes $$$[6, 1, 5, 3]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[6, 1, 5, 3, 4, 2]$$$. In result, $$$p'$$$ has order equal to $$$6^5 \cdot 6 + 6^4 \cdot 1 + 6^3 \cdot 5 + 6^2 \cdot 3 + 6^1 \cdot 4 + 6^0 \cdot 2$$$ $$$=$$$ $$$46656 + 1296 + 1080 + 108 + 24 + 2 = 49166$$$.
Java 17
standard input
[ "data structures", "greedy", "math" ]
1637670255f8bd82a01e2ab20cdcc9aa
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — values of card in the deck from bottom to top. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,100
For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them.
standard output
PASSED
b87a24ad6a1ff04fc0c5545d9734dbde
train_109.jsonl
1614071100
You have a deck of $$$n$$$ cards, and you'd like to reorder it to a new one.Each card has a value between $$$1$$$ and $$$n$$$ equal to $$$p_i$$$. All $$$p_i$$$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $$$p_1$$$ stands for the bottom card, $$$p_n$$$ is the top card. In each step you pick some integer $$$k &gt; 0$$$, take the top $$$k$$$ cards from the original deck and place them, in the order they are now, on top of the new deck. You perform this operation until the original deck is empty. (Refer to the notes section for the better understanding.)Let's define an order of a deck as $$$\sum\limits_{i = 1}^{n}{n^{n - i} \cdot p_i}$$$.Given the original deck, output the deck with maximum possible order you can make using the operation above.
512 megabytes
import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tc = 0; tc < t; ++tc) { int n = sc.nextInt(); int[] p = new int[n]; for (int i = 0; i < p.length; ++i) { p[i] = sc.nextInt(); } System.out.println(solve(p)); } sc.close(); } static String solve(int[] p) { int[] leftMaxs = new int[p.length]; int leftMax = -1; for (int i = 0; i < leftMaxs.length; ++i) { leftMax = Math.max(leftMax, p[i]); leftMaxs[i] = leftMax; } List<Integer> result = new ArrayList<>(); int endIndex = p.length - 1; for (int beginIndex = p.length - 1; beginIndex >= 0; --beginIndex) { if (p[beginIndex] == leftMaxs[beginIndex]) { for (int i = beginIndex; i <= endIndex; ++i) { result.add(p[i]); } endIndex = beginIndex - 1; } } return result.stream().map(String::valueOf).collect(Collectors.joining(" ")); } }
Java
["4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1"]
1 second
["4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1"]
NoteIn the first test case, one of the optimal strategies is the next one: take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1, 2, 3]$$$, $$$p'$$$ becomes $$$[4]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1, 2]$$$, $$$p'$$$ becomes $$$[4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[4, 3, 2]$$$; take $$$1$$$ card from the top of $$$p$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[4, 3, 2, 1]$$$. In result, $$$p'$$$ has order equal to $$$4^3 \cdot 4 + 4^2 \cdot 3 + 4^1 \cdot 2 + 4^0 \cdot 1$$$ $$$=$$$ $$$256 + 48 + 8 + 1 = 313$$$.In the second test case, one of the optimal strategies is: take $$$4$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[1]$$$, $$$p'$$$ becomes $$$[5, 2, 4, 3]$$$; take $$$1$$$ card from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[5, 2, 4, 3, 1]$$$; In result, $$$p'$$$ has order equal to $$$5^4 \cdot 5 + 5^3 \cdot 2 + 5^2 \cdot 4 + 5^1 \cdot 3 + 5^0 \cdot 1$$$ $$$=$$$ $$$3125 + 250 + 100 + 15 + 1 = 3491$$$.In the third test case, one of the optimal strategies is: take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2, 5, 3]$$$, $$$p'$$$ becomes $$$[6, 1]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes $$$[4, 2]$$$, $$$p'$$$ becomes $$$[6, 1, 5, 3]$$$; take $$$2$$$ cards from the top of $$$p$$$ and move it to $$$p'$$$: $$$p$$$ becomes empty, $$$p'$$$ becomes $$$[6, 1, 5, 3, 4, 2]$$$. In result, $$$p'$$$ has order equal to $$$6^5 \cdot 6 + 6^4 \cdot 1 + 6^3 \cdot 5 + 6^2 \cdot 3 + 6^1 \cdot 4 + 6^0 \cdot 2$$$ $$$=$$$ $$$46656 + 1296 + 1080 + 108 + 24 + 2 = 49166$$$.
Java 17
standard input
[ "data structures", "greedy", "math" ]
1637670255f8bd82a01e2ab20cdcc9aa
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of deck you have. The second line contains $$$n$$$ integers $$$p_1, p_2,\dots, p_n$$$ ($$$1 \le p_i \le n$$$; $$$p_i \neq p_j$$$ if $$$i \neq j$$$) — values of card in the deck from bottom to top. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.
1,100
For each test case print the deck with maximum possible order. Print values of cards in the deck from bottom to top. If there are multiple answers, print any of them.
standard output
PASSED
cfa213434b4efafbec30ec358baf58d1
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; public class MaxContigiousSubarray { public static void main (String [] args) throws IOException { InputStreamReader in= new InputStreamReader(System.in); BufferedReader br= new BufferedReader(in); String input=br.readLine(); String[] inps=input.split(" "); int a=Integer.parseInt(inps[0]); int b=Integer.parseInt(inps[1]); int k=Integer.parseInt(inps[2]); b--; String X="",Y=""; if(k==0){ System.out.println("YES"); System.out.println("1"+trail('1',b)+trail('0',a)); System.out.println("1"+trail('1',b)+trail('0',a)); return; } if(b>=k&&a>0){ StringBuilder x =new StringBuilder("1"); StringBuilder y =new StringBuilder("10"); int preserve=k; StringBuilder preserveStr =new StringBuilder(""); for(int i=0;i<k;i++)preserveStr.append('1'); x.append(preserveStr.toString()+"0"); y.append(preserveStr.toString()); a--; String one=trail('1',b-k); String zero=trail('0',a); X=x.toString()+zero+one; Y=y.toString()+zero+one; }else if(a>=k&&b>0){ String x="11"; String y="1"; //swap String swap=trail('0',k); x=x+swap; y=y+swap+"1"; b--; String one=trail('1',b); String zero=trail('0',a-k); x=x+zero+one; y=y+zero+one; X=x; Y=y; } else if((a>0&&b>0)){ a--; if(a+(b-1)>=k){ b--; String x="1"; String y="10"; String preserve=trail('1',b); x=x+preserve+"0"; y=y+preserve; k=k-b; x=x+"1"; String swap=trail('0',k); x=x+swap; y=y+swap+"1"; a=a-k; String zero=trail('0',a); x=x+zero; y=y+zero; X=x; Y=y; }else if(a+b>=k){ String x="1"; String y="10"; String preserve=trail('1',b-1); x=x+preserve+"1"; y=y+preserve; k=k-b; String swap=trail('0',k); x=x+swap+"0"; y=y+swap+"1"; a=a-k; String zero=trail('0',a); x=x+zero; y=y+zero; X=x; Y=y; } else{ System.out.println("No"); return; } }else{ System.out.println("No"); return; } System.out.println("YES"); System.out.println(X+"\n"+Y); //System.out.println("1s "+number(X,'1')+" 0s "+number(X,'0')); //System.out.println("1s "+number(Y,'1')+" 0s "+number(Y,'0')); } static String trail(char tr,int a){ StringBuilder result=new StringBuilder(); for(int i=0;i<a;i++) result.append(tr); return result.toString(); } static int number(String str,Character ch){ int num=0; for(int i=0;i<str.length();i++){ if(str.charAt(i)==ch) num++; } return num; } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
5b7c107dfaf9febcea6dad2605791a90
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.StringTokenizer; public class GeniusGambit { static int mod = 1000000007; public static void main(String[] args) throws IOException { FastReader reader = new FastReader(); FastWriter writer = new FastWriter(); int[] ABK = reader.readIntArray(3); int A = ABK[0], B = ABK[1], K = ABK[2]; if((A+B-2 < K && K > 0) || (B == 1 && K > 0) || (A == 0 && K > 0) || (B == 0 && K > 0)){ writer.writeString("No"); } else { writer.writeString("Yes"); int[] x = new int[A+B]; int[] y = new int[A+B]; if(K > B-1){ x[0] = 1; y[0] = 1; y[A+B-1] = 1; int zeroPadding = K-(B-1) + 1; int ones = B; int i = A+B-1-zeroPadding; while(ones > 1) { x[i] = 1; i--; ones--; } ones = B-1; i = A+B-1-zeroPadding; while(ones > 1) { y[i] = 1; i--; ones--; } } else { int prefix = B-K; for(int i = 0; i<prefix; i++){ x[i] = 1; y[i] = 1; } for(int i = A+B-1; i>A+B-1-K; i--){ x[i-1] = 1; y[i] = 1; } } writer.writeIntArrayWithoutSpaces(x); writer.writeIntArrayWithoutSpaces(y); } } public static void mergeSort(int[] a, int n) { if (n < 2) { return; } int mid = n / 2; int[] l = new int[mid]; int[] r = new int[n - mid]; for (int i = 0; i < mid; i++) { l[i] = a[i]; } for (int i = mid; i < n; i++) { r[i - mid] = a[i]; } mergeSort(l, mid); mergeSort(r, n - mid); merge(a, l, r, mid, n - mid); } public static void merge(int[] a, int[] l, int[] r, int left, int right) { int i = 0, j = 0, k = 0; while (i < left && j < right) { if (l[i] <= r[j]) { a[k++] = l[i++]; } else { a[k++] = r[j++]; } } while (i < left) { a[k++] = l[i++]; } while (j < right) { a[k++] = r[j++]; } } public static class FastReader { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenizer; public int readSingleInt() throws IOException { return Integer.parseInt(reader.readLine()); } public int[] readIntArray(int numInts) throws IOException { int[] nums = new int[numInts]; tokenizer = new StringTokenizer(reader.readLine()); for(int i = 0; i<numInts; i++){ nums[i] = Integer.parseInt(tokenizer.nextToken()); } return nums; } public String readString() throws IOException { return reader.readLine(); } } public static class FastWriter { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); public void writeSingleInteger(int i) throws IOException { writer.write(Integer.toString(i)); writer.newLine(); writer.flush(); } public void writeSingleLong(long i) throws IOException { writer.write(Long.toString(i)); writer.newLine(); writer.flush(); } public void writeIntArrayWithSpaces(int[] nums) throws IOException { for(int i = 0; i<nums.length; i++){ writer.write(nums[i] + " "); } writer.newLine(); writer.flush(); } public void writeIntArrayWithoutSpaces(int[] nums) throws IOException { for(int i = 0; i<nums.length; i++){ writer.write(Integer.toString(nums[i])); } writer.newLine(); writer.flush(); } public void writeString(String s) throws IOException { writer.write(s); writer.newLine(); writer.flush(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
25b67155e682ce3a6eb75644b58bf3f4
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class D { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String[] s = in.readLine().split(" "); int a = Integer.parseInt(s[0]); int b = Integer.parseInt(s[1]); int k = Integer.parseInt(s[2]); if(a == 0 && b == 1){ if(k == 0){ System.out.println("Yes\n1\n1"); } else { System.out.println("No"); } } else if(k > a + b - 2){ System.out.println("No"); } else { int[] x = new int[a + b]; int[] y = new int[a + b]; for(int i = 0; i < b; i++){ x[i] = 1; y[i] = 1; } int l = b - 1, r = a + b - 1; if(k <= a){ y[l] = 0; y[l + k] = 1; } else { k -= a; y[a + b - 1] = 1; y[l - k] = 0; } int cnt = 0; for(int i = 0; i < a + b; i++){ if(y[i] != 0) cnt++; } if(y[0] != 0 && cnt == b){ System.out.println("Yes"); for(int i = 0; i < a + b; i++){ System.out.print(x[i]); } System.out.println(); for(int i = 0; i < a + b; i++){ System.out.print(y[i]); } System.out.println(); } else { System.out.println("No"); } } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
a3e4822e4d1f57df0822ff7b84f5216d
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static class Pair implements Comparable<Pair> { int f,s; Pair(int f,int s) { this.f=f; this.s=s; } public int compareTo(Pair p) { return this.s-p.s; } } public static void main(String args[]) { FastReader fs=new FastReader(); PrintWriter pw=new PrintWriter(System.out); //int tc=fs.nextInt(); int tc=1; while(tc-->0) { int a=fs.nextInt(); int b=fs.nextInt(); int k=fs.nextInt(); if(b==1) { if(k!=0) pw.println("No"); else { pw.println("Yes"); pw.print(1); for(int i=1;i<=a;i++) pw.print(0); pw.println(); pw.print(1); for(int i=1;i<=a;i++) pw.print(0); } } else if(a==0) { if(k!=0) pw.println("No"); else { pw.println("Yes"); for(int i=0;i<b;i++) pw.print(1); pw.println(); for(int i=0;i<b;i++) pw.print(1); } } else if(k==0) { pw.println("Yes"); for(int i=0;i<b;i++) pw.print(1); for(int i=0;i<a;i++) pw.print(0); pw.println(); for(int i=0;i<b;i++) pw.print(1); for(int i=0;i<a;i++) pw.print(0); } else if(k>a+b-2) pw.println("No"); else { pw.println("Yes"); char c1[]=new char[a+b]; char c2[]=new char[a+b]; int n=a+b; b--; c1[0]=c2[0]='1'; c1[1]='1'; c2[1]='0'; c1[k+1]='0'; c2[k+1]='1'; --a; b--; for(int i=2;i<=k;i++) { if(a>0) { c1[i]=c2[i]='0'; a--; } else { c1[i]=c2[i]='1'; b--; } } int ind=k+2; while(a-->0) { c1[ind]=c2[ind]='0'; ind++; } while(b-->0) { c1[ind]=c2[ind]='1'; ind++; } pw.println(new String(c1)); pw.println(new String(c2)); } } pw.flush(); pw.close(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
a669528684ddf10b1d7d8fc7d383020b
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.lang.*; import java.util.*; import java.io.*; import java.util.*; public class Main{ static Scanner scanner=new Scanner(System.in); public static void main(String[] args) { int a=scanner.nextInt(); int b=scanner.nextInt(); int k=scanner.nextInt(); int max=a; if((b==1&&k!=0)||(k>=a+b-1&&k!=0)||(a==0&&k!=0)) { System.out.println("No"); return; } System.out.println("Yes"); StringBuilder sb1=new StringBuilder(); StringBuilder sb2=new StringBuilder(); if(a==0||b==0||k==0) { while(b-->0) { sb1.append(1); sb2.append(1); } while(a-->0) { sb1.append(0); sb2.append(0); } System.out.println(sb1); System.out.println(sb2); return; } b--; a--; sb1.append("0"); sb2.append("1"); b--; k--; for(;b>0&&k>0;b--,k--) { sb1.append("1"); sb2.append("1"); } for(;k>0;k--,a--) { sb1.append(0); sb2.append(0); } sb1.append(1); sb2.append(0); while(a-->0) { sb1.append(0); sb2.append(0); } while(b-->0) { sb2.append(1); sb1.append(1); } sb1.append(1); sb2.append(1); System.out.println(sb1.reverse()); System.out.println(sb2.reverse()); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
46194e2c3ba3c165de5892ee83bf6172
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; public class D { public void solve() { int a = in.nextInt(); int b = in.nextInt(); int k = in.nextInt(); int x[] = new int[a+b]; int y[] = new int[a+b]; if (b == 1 || a == 0) { if (k != 0) { out.println("No"); return; } else { out.println("Yes"); for (int i = 0; i < b; i++) { x[i] = y[i] = 1; } } } else if (k > (a + b - 2)) { out.println("No"); return; } else { out.println("Yes"); if (k == 0) { for (int i = 0; i < b; i++) { x[i] = y[i] = 1; } for (int i = b; i < a + b; i++) { x[i] = y[i] = 0; } } else { for (int i = 0; i < b; i++) x[i] = y[i] = 1; if (k <= a) { y[b-1] = 0; y[b+k-1] = 1; } else { y[a+b-1]=1; y[a+b-k-1]=0; } // for (int i = 1; i <= b - 1; i++) // out.print('1'); // for (int i = 1; i <= a - k; i++) // out.print('0'); // out.print('1'); // for (int i = 1; i <= k; i++) // out.print('0'); // out.println(); // // for (int i = 1; i <= b - 1; i++) // out.print('1'); // for (int i = 1; i <= a - k; i++) // out.print('0'); // for (int i = 1; i <= k; i++) // out.print('0'); // out.print('1'); // out.println(); } } for (int i = 0; i < a + b; i++) { out.print(x[i]); } out.println(); for (int i = 0; i < a + b; i++) { out.print(y[i]); } out.println(); } String input = ""; String output = ""; FastScanner in; PrintWriter out; void run() throws Exception { if (input.length() == 0) { in = new FastScanner(System.in); } else { in = new FastScanner(new File(input)); } if (output.length() == 0) { out = new PrintWriter(System.out); } else { out = new PrintWriter(new File(output)); } solve(); out.close(); } public static void main(String[] args) throws Exception { new D().run(); } class FastScanner { BufferedReader bf; StringTokenizer st; public FastScanner(InputStream is) { bf = new BufferedReader(new InputStreamReader(is)); } public FastScanner(File fr) throws FileNotFoundException { bf = new BufferedReader(new FileReader(fr)); } public String next() { try { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(bf.readLine()); } } catch (IOException ex) { ex.printStackTrace(); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] readIntArray(int length) { int arr[] = new int[length]; for (int i = 0; i<length; i++) arr[i] = nextInt(); return arr; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
40f858ffb56ddac61922bdce88cd3c85
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 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 Pranay2516 */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); DGeniussGambit solver = new DGeniussGambit(); solver.solve(1, in, out); out.close(); } static class DGeniussGambit { public void solve(int testNumber, FastReader in, PrintWriter out) { int zeroes = in.nextInt(), ones = in.nextInt(), k = in.nextInt(); if (k == 0) { out.println("Yes"); for (int i = 0; i < ones; ++i) { out.print(1); } for (int i = 0; i < zeroes; ++i) { out.print(0); } out.println(); for (int i = 0; i < ones; ++i) { out.print(1); } for (int i = 0; i < zeroes; ++i) { out.print(0); } return; } if (k > zeroes + ones - 2 || ones <= 1 || zeroes == 0) { out.println("No"); return; } out.println("Yes"); StringBuilder a = new StringBuilder("1"); StringBuilder b = new StringBuilder("1"); ones--; while (k < ones + zeroes - 1 && ones > 1) { a.append('1'); b.append('1'); ones--; } int extraZeroes = ones + zeroes - 1 - k; zeroes = k + 1 - ones; a.append('1'); b.append('0'); for (int i = 0; i < zeroes - 1; ++i) { a.append('0'); b.append('0'); } for (int i = 0; i < ones - 1; ++i) { a.append('1'); b.append('1'); } a.append('0'); b.append('1'); for (int i = 0; i < extraZeroes; ++i) { a.append('0'); b.append('0'); } out.println(a.toString()); out.println(b.toString()); } } static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
6a40555ab190b131e5282d75f20d551d
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
//package cf1; import java.io.*; import java.util.*; public class utkarsh { public static void main(String[] args) { new utkarsh().run(); } BufferedReader br; PrintWriter out; long mod = (long) (1e9 + 7), inf = (long) (3e18); void solve() { int b = ni(), a = ni(), k = ni(); if(k == 0) { out.println("Yes"); for(int i = 0; i < a; i++) out.print('1'); for(int i = 0; i < b; i++) out.print('0'); out.println(); for(int i = 0; i < a; i++) out.print('1'); for(int i = 0; i < b; i++) out.print('0'); out.println(); } else if(k >= a+b-1 || b == 0 || a == 1) out.println("No"); else if(k > b) { out.println("Yes"); for(int i = 0; i < a; i++) out.print('1'); for(int i = 0; i < b; i++) out.print('0'); out.println(); for(int i = 0; i < a+b-k-1; i++) out.print('1'); out.print('0'); for(int i = 0; i < a-1 - (a+b-k-1); i++) out.print('1'); for(int i = 0; i < b-1; i++) out.print('0'); out.println('1'); } else { out.println("Yes"); for(int i = 0; i < a-1; i++) out.print('1'); for(int i = 0; i < b-k; i++) out.print('0'); out.print('1'); for(int i = 0; i < k; i++) out.print('0'); out.println(); for(int i = 0; i < a-1; i++) out.print('1'); for(int i = 0; i < b; i++) out.print('0'); out.println('1'); } } // -------- I/O Template ------------- char nc() { return ns().charAt(0); } String nLine() { try { return br.readLine(); } catch(IOException e) { return "-1"; } } double nd() { return Double.parseDouble(ns()); } long nl() { return Long.parseLong(ns()); } int ni() { return Integer.parseInt(ns()); } int[] na(int n) { int a[] = new int[n]; for(int i = 0; i < n; i++) a[i] = ni(); return a; } StringTokenizer ip; String ns() { if(ip == null || !ip.hasMoreTokens()) { try { ip = new StringTokenizer(br.readLine()); if(ip == null || !ip.hasMoreTokens()) ip = new StringTokenizer(br.readLine()); } catch(IOException e) { throw new InputMismatchException(); } } return ip.nextToken(); } void run() { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.flush(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
e4b903907ddced05d133a6d6c6ef8e80
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
//package Codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Round704_Div2 { public static void main(String[] args) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st= new StringTokenizer(br.readLine()); int a= Integer.parseInt(st.nextToken()); int b= Integer.parseInt(st.nextToken()); int k= Integer.parseInt(st.nextToken()); if (k>=(a+b)) {System.out.println("NO");} else if (k==0){ char x[]=new char[a+b]; char y[]= new char[a+b]; for (int i=0;i<x.length;i++){ if (b>0){ x[i]='1'; y[i]='1'; b--; }else { x[i]='0'; y[i]='0'; } } StringBuilder sb= new StringBuilder(); sb.append("YES"); sb.append("\n"); sb.append(x); sb.append("\n"); sb.append(y); sb.append("\n"); PrintWriter pw= new PrintWriter(System.out); pw.println(sb.toString().trim()); pw.flush(); }else if (b==1 || a==0|| k>=(a+b-1)) { System.out.println("NO"); }else { char x[]=new char[a+b]; char y[]= new char[a+b]; x[0]='1'; y[0]='1'; x[a+b-k-1]='1'; x[a+b-1]='0'; y[a+b-k-1]='0'; y[a+b-1]='1'; b-=2; for (int i=0;i<x.length;i++){ if (x[i]=='1'|| y[i]=='1'){ continue; }else if (b>0){ x[i]='1'; y[i]='1'; b--; }else { x[i]='0'; y[i]='0'; } } StringBuilder sb= new StringBuilder(); sb.append("YES"); sb.append("\n"); sb.append(x); sb.append("\n"); sb.append(y); sb.append("\n"); PrintWriter pw= new PrintWriter(System.out); pw.println(sb.toString().trim()); pw.flush(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
fd23cc1f26f1c7b62ee7cbaa1461cde9
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
//package Codeforces; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Round704_Div2 { public static void main(String[] args) throws IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st= new StringTokenizer(br.readLine()); int a= Integer.parseInt(st.nextToken()); int b= Integer.parseInt(st.nextToken()); int k= Integer.parseInt(st.nextToken()); if (k>=(a+b)) {System.out.println("NO");} else if (k==0){ char x[]=new char[a+b]; char y[]= new char[a+b]; for (int i=0;i<x.length;i++){ if (b>0){ x[i]='1'; y[i]='1'; b--; }else { x[i]='0'; y[i]='0'; } } System.out.println("YES"); for (int i=0;i<x.length;i++){ System.out.print(x[i]); } System.out.println(); for (int i=0;i<y.length;i++){ System.out.print(y[i]); } System.out.println(); }else if (b==1 || a==0|| k>=(a+b-1)) { System.out.println("NO"); }else { char x[]=new char[a+b]; char y[]= new char[a+b]; x[0]='1'; y[0]='1'; x[a+b-k-1]='1'; x[a+b-1]='0'; y[a+b-k-1]='0'; y[a+b-1]='1'; b-=2; for (int i=0;i<x.length;i++){ if (x[i]=='1'|| y[i]=='1'){ continue; }else if (b>0){ x[i]='1'; y[i]='1'; b--; }else { x[i]='0'; y[i]='0'; } } System.out.println("YES"); for (int i=0;i<x.length;i++){ System.out.print(x[i]); } System.out.println(); for (int i=0;i<y.length;i++){ System.out.print(y[i]); } System.out.println(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
ea5f955776a4d3522967fb5f7a2c45a6
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class TaskD { public static void main(String[] arg) { final FastScanner in = new FastScanner(System.in); final PrintWriter out = new PrintWriter(System.out); final int a = in.nextInt(); final int b = in.nextInt(); final int k = in.nextInt(); String [] result = solution(a, b, k); for(String res:result) { out.println(res); } out.close(); in.close(); } private static String [] solution(final int a, final int b, final int k) { final String [] No = new String[]{"No"}; char []s1 = new char[a+b]; char []s2 = new char[a+b]; if(a==0&&k!=0){ return No; } if(b==1&&k!=0){ return No; } if(a+b-2<k&&k!=0){ return No; } for(int i=0;i<b;i++){ s1[i]='1'; s2[i]='1'; } s2[b-1]='0'; for(int i=b;i<a+b;i++){ s1[i]='0'; s2[i]='0'; } int c = 0; int i = b-1; while(c<k&&i<a+b){ c++; i++; } if(c==k&&i<a+b){ s2[i]='1'; }else { s2[a+b-1]='1'; s2[b-1]='1'; i=b-2; while(c!=k){ i--; c++; } s2[i]='0'; } return new String[]{"Yes", String.valueOf(s1), String.valueOf(s2)}; } private static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream stream) { try { br = new BufferedReader(new InputStreamReader(stream)); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readIntArr(int n) { int[] result = new int[n]; for (int i = 0; i < n; i++) { result[i] = Integer.parseInt(next()); } return result; } long[] readLongArr(int n) { long[] result = new long[n]; for (int i = 0; i < n; i++) { result[i] = Long.parseLong(next()); } return result; } void close() { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } long nextLong() { return Long.parseLong(next()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
cff126313b61430eafaff5d9bcdb17a7
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import java.util.TreeMap; public class Main implements Runnable { int n, m; static boolean use_n_tests = false; void solve(FastScanner in, PrintWriter out, int testNumber) { int a = in.nextInt(); int b = in.nextInt(); int k = in.nextInt(); if (a == 0) { if (k == 0) { out.println("Yes"); for (int i = 0; i < b; i++) { out.print(1); } out.println(); for (int i = 0; i < b; i++) { out.print(1); } out.println(); } else { out.println("No"); } return; } if (b == 1) { if (k == 0) { out.println("Yes"); out.print(1); for (int i = 0; i < a; i++) { out.print(0); } out.println(); out.print(1); for (int i = 0; i < a; i++) { out.print(0); } } else { out.println("No"); } return; } if (k <= a) { out.println("Yes"); for (int i = 0; i < b - 1; i++) { out.print(1); } for (int i = 0; i < a - k; i++) { out.print(0); } out.print(1); for (int i = 0; i < k; i++) { out.print(0); } out.println(); for (int i = 0; i < b - 1; i++) { out.print(1); } for (int i = 0; i < a; i++) { out.print(0); } out.println(1); } else if (k <= (a + b - 2)) { out.println("Yes"); for (int i = 0; i < b; i++) { out.print(1); } for (int i = 0; i < a; i++) { out.print(0); } out.println(); int d = k - a; for (int i = 0; i < b - 1 - d; i++) { out.print(1); } out.print(0); for (int i = 0; i < d; i++) { out.print(1); } for (int i = 0; i < a - 1; i++) { out.print(0); } out.println(1); } else { out.println("No"); } } void solve1(FastScanner in, PrintWriter out, int testNumber) { n = in.nextInt(); int k = in.nextInt(); int[] a = in.nextArray(n); int l = 1; int r = n; int ans = -1; while (l <= r) { int m = (l + r) / 2; if (can(m, a, k)) { ans = m; l = m + 1; } else { r = m - 1; } } out.println(ans); } boolean can(int m, int[] a, int limit) { int[] sum = new int[a.length]; for (int i = 0; i < a.length; i++) { if (a[i] <= m) { sum[i] = -1; } else { sum[i] = 1; } if (i > 0) { sum[i] += sum[i - 1]; } } for (int i = 0; i <= n - limit; i++) { int psum = 0; if (i > 0) { psum -= sum[i - 1]; } psum += sum[i + limit - 1]; if (limit % 2 == 0 && psum >= 0) { return true; } if (limit % 2 == 1 && psum >= -1) { return true; } } return false; } // ****************************** template code *********** int ask(int l, int r) { if (l >= r) { return -1; } System.out.printf("? %d %d\n", l + 1, r + 1); System.out.flush(); return in.nextInt() - 1; } static int stack_size = 1 << 27; class Mod { long mod; Mod(long mod) { this.mod = mod; } long add(long a, long b) { a = mod(a); b = mod(b); return (a + b) % mod; } long sub(long a, long b) { a = mod(a); b = mod(b); return (a - b + mod) % mod; } long mul(long a, long b) { a = mod(a); b = mod(b); return a * b % mod; } long div(long a, long b) { a = mod(a); b = mod(b); return (a * inv(b)) % mod; } public long inv(long r) { if (r == 1) return 1; return ((mod - mod / r) * inv(mod % r)) % mod; } private long mod(long a) { return a % mod; } } class Coeff { long mod; long[][] C; long[] fact; boolean cycleWay = false; Coeff(int n, long mod) { this.mod = mod; fact = new long[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) { fact[i] = i; fact[i] %= mod; fact[i] *= fact[i - 1]; fact[i] %= mod; } } Coeff(int n, int m, long mod) { // n > m cycleWay = true; this.mod = mod; C = new long[n + 1][m + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= Math.min(i, m); j++) { if (j == 0 || j == i) { C[i][j] = 1; } else { C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; C[i][j] %= mod; } } } } public long C(int n, int m) { if (cycleWay) { return C[n][m]; } return fC(n, m); } private long fC(int n, int m) { return (fact[n] * inv(fact[n - m] * fact[m] % mod)) % mod; } private long inv(long r) { if (r == 1) return 1; return ((mod - mod / r) * inv(mod % r)) % mod; } } class Pair { int first; int second; public int getFirst() { return first; } public int getSecond() { return second; } } class MultisetTree<T> { int size = 0; TreeMap<T, Integer> mp = new TreeMap<>(); void add(T x) { mp.merge(x, 1, Integer::sum); size++; } void remove(T x) { if (mp.containsKey(x)) { mp.merge(x, -1, Integer::sum); if (mp.get(x) == 0) { mp.remove(x); } size--; } } boolean contains(T x) { return mp.containsKey(x); } T greatest() { return mp.lastKey(); } T smallest() { return mp.firstKey(); } int size() { return size; } int diffSize() { return mp.size(); } } class Multiset<T> { int size = 0; Map<T, Integer> mp = new HashMap<>(); void add(T x) { mp.merge(x, 1, Integer::sum); size++; } boolean contains(T x) { return mp.containsKey(x); } void remove(T x) { if (mp.containsKey(x)) { mp.merge(x, -1, Integer::sum); if (mp.get(x) == 0) { mp.remove(x); } size--; } } int size() { return size; } int diffSize() { return mp.size(); } } static class Range { int l, r; int id; public int getL() { return l; } public int getR() { return r; } public Range(int l, int r, int id) { this.l = l; this.r = r; this.id = id; } } static class Array { static Range[] readRanges(int n, FastScanner in) { Range[] result = new Range[n]; for (int i = 0; i < n; i++) { result[i] = new Range(in.nextInt(), in.nextInt(), i); } return result; } static List<List<Integer>> intInit2D(int n) { List<List<Integer>> res = new ArrayList<>(); for (int i = 0; i < n; i++) { res.add(new ArrayList<>()); } return res; } static boolean isSorted(Integer[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { return false; } } return true; } static public long sum(int[] a) { long sum = 0; for (int x : a) { sum += x; } return sum; } static public long sum(long[] a) { long sum = 0; for (long x : a) { sum += x; } return sum; } static public long sum(Integer[] a) { long sum = 0; for (int x : a) { sum += x; } return sum; } static public int min(Integer[] a) { int mn = Integer.MAX_VALUE; for (int x : a) { mn = Math.min(mn, x); } return mn; } static public int min(int[] a) { int mn = Integer.MAX_VALUE; for (int x : a) { mn = Math.min(mn, x); } return mn; } static public int max(Integer[] a) { int mx = Integer.MIN_VALUE; for (int x : a) { mx = Math.max(mx, x); } return mx; } static public int max(int[] a) { int mx = Integer.MIN_VALUE; for (int x : a) { mx = Math.max(mx, x); } return mx; } static public int[] readint(int n, FastScanner in) { int[] out = new int[n]; for (int i = 0; i < out.length; i++) { out[i] = in.nextInt(); } return out; } } class Graph { List<List<Integer>> graph; Graph(int n) { create(n); } void create(int n) { List<List<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } this.graph = graph; } void readBi(int m, FastScanner in) { for (int i = 0; i < m; i++) { int v = in.nextInt() - 1; int u = in.nextInt() - 1; graph.get(v).add(u); graph.get(u).add(v); } } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream io) { br = new BufferedReader(new InputStreamReader(io)); } public String line() { String result = ""; try { result = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return result; } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] nextArray(int n) { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = in.nextInt(); } return res; } public long[] nextArrayL(int n) { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = in.nextLong(); } return res; } public Long[] nextArrayL2(int n) { Long[] res = new Long[n]; for (int i = 0; i < n; i++) { res[i] = in.nextLong(); } return res; } public Integer[] nextArray2(int n) { Integer[] res = new Integer[n]; for (int i = 0; i < n; i++) { res[i] = in.nextInt(); } return res; } public long nextLong() { return Long.parseLong(next()); } } void run_t_tests() { int t = in.nextInt(); int i = 0; while (t-- > 0) { solve(in, out, i++); } } void run_one() { solve(in, out, -1); } @Override public void run() { in = new FastScanner(System.in); out = new PrintWriter(System.out); if (use_n_tests) { run_t_tests(); } else { run_one(); } out.close(); } static FastScanner in; static PrintWriter out; public static void main(String[] args) throws InterruptedException { Thread thread = new Thread(null, new Main(), "", stack_size); thread.start(); thread.join(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
31cca3db686734ac9df658866ee38b4a
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; public class Main{ static void main() throws Exception{ int a=sc.nextInt(),b=sc.nextInt()-1,k=sc.nextInt(); if(a==0) { if(k!=0) { pw.println("No"); return; } b++; pw.println("Yes"); for(int i=0;i<b;i++) { pw.print(1); } pw.println(); for(int i=0;i<b;i++) { pw.print(1); } pw.println(); return; } if(k==0) { pw.println("Yes"); b++; for(int i=0;i<b;i++) { pw.print(1); } for(int i=0;i<a;i++) { pw.print(0); } pw.println(); for(int i=0;i<b;i++) { pw.print(1); } for(int i=0;i<a;i++) { pw.print(0); } pw.println(); return; } if(b==0) { pw.println("No"); return; } if(k<=a) { b++; pw.println("Yes"); int[]ans1=new int[a+b],ans2=new int[a+b]; int idx=a+b-1; ans1[idx]=0;ans2[idx]=1; idx--; for(int i=0;i<k-1;i++) { ans1[idx]=0; ans2[idx]=0; a--; idx--; } ans1[idx]=1;ans2[idx]=0; a--;b--; idx--; while(a>0) { ans1[idx]=0; ans2[idx]=0; a--; idx--; } while(b>0) { ans1[idx]=1; ans2[idx]=1; b--; idx--; } for(int i=0;i<ans1.length;i++) { pw.print(ans1[i]); } pw.println(); for(int i=0;i<ans2.length;i++) { pw.print(ans2[i]); } pw.println(); return; } if(k<=a+b-1) { pw.println("Yes"); k-=a; int[]ans1=new int[a+b+1],ans2=new int[a+b+1]; ans1[0]=ans2[0]=1; int idx=a+b; ans1[idx]=0;ans2[idx]=1; idx--; for(int i=0;i<a-1;i++) { ans1[idx]=0; ans2[idx]=0; idx--; } a=0; while(k>0) { ans1[idx]=1; ans2[idx]=1; b--; idx--; k--; } ans1[idx]=1;ans2[idx]=0; b--; idx--; while(b>0) { ans1[idx]=1; ans2[idx]=1; b--; idx--; } for(int i=0;i<ans1.length;i++) { pw.print(ans1[i]); } pw.println(); for(int i=0;i<ans2.length;i++) { pw.print(ans2[i]); } pw.println(); return; } pw.println("No"); } public static void main(String[] args) throws Exception{ sc=new MScanner(System.in); pw = new PrintWriter(System.out); int tc=1; // tc=sc.nextInt(); for(int i=1;i<=tc;i++) { // pw.printf("Case %d:\n", i); main(); } pw.flush(); } static PrintWriter pw; static MScanner sc; static class MScanner { StringTokenizer st; BufferedReader br; public MScanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public MScanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int[] intArr(int n) throws IOException { int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public long[] longArr(int n) throws IOException { long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public int[] intSortedArr(int n) throws IOException { int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt(); shuffle(in); Arrays.sort(in); return in; } public long[] longSortedArr(int n) throws IOException { long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong(); shuffle(in); Arrays.sort(in); return in; } public Integer[] IntegerArr(int n) throws IOException { Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt(); return in; } public Long[] LongArr(int n) throws IOException { Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong(); return in; } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } static void shuffle(int[]in) { for(int i=0;i<in.length;i++) { int idx=(int)(Math.random()*in.length); int tmp=in[i]; in[i]=in[idx]; in[idx]=tmp; } } static void shuffle(long[]in) { for(int i=0;i<in.length;i++) { int idx=(int)(Math.random()*in.length); long tmp=in[i]; in[i]=in[idx]; in[idx]=tmp; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
22679067d027a004c943a15d5368e236
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 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.HashMap; import java.util.HashSet; import java.util.Random; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; // CFPS -> CodeForcesProblemSet public final class CFPS { static FastReader fr = new FastReader(); static PrintWriter out = new PrintWriter(System.out); static final int gigamod = 1000000007; static final int mod = 998244353; static int t = 1; static double epsilon = 0.00000001; static boolean[] isPrime; static int[] smallestFactorOf; @SuppressWarnings("unused") public static void main(String[] args) { OUTER: for (int tc = 0; tc < t; tc++) { int a = fr.nextInt(), b = fr.nextInt(), k = fr.nextInt(); if (k == 0) { char[] x = new char[a + b]; Arrays.fill(x, '0'); for (int i = 0; i < b; i++) x[i] = '1'; out.println("Yes"); out.println(toString(x)); out.println(toString(x)); continue OUTER; } // Observations: // 1. The task is to determine such binary numbers 'x' and 'y' such // that binary of res = (x - y) contains exactly 'k' ones. // 2. Ones in 'res' start from a 1 location in 'x' and end at a 1 location // in y, both inclusive. // 3. In such a desired chain, if we place intermediate 1s in both 'x' and 'y', // it doesn't disrupt the desired flow. char[] x = new char[a + b]; char[] y = new char[a + b]; Arrays.fill(x, '0'); Arrays.fill(y, '0'); x[0] = '1'; y[0] = '1'; x[1] = '1'; if (1 + k < a + b) y[1 + k] = '1'; else { out.println("No"); continue OUTER; } int remOnes = b - 2; for (int i = 2; i < a + b && remOnes > 0; i++) { if (i == 1 + k) continue; x[i] = y[i] = '1'; remOnes--; } int numXOnes = 0, numYOnes = 0; for (int i = 0; i < a + b; i++) { if (x[i] == '1') numXOnes++; if (y[i] == '1') numYOnes++; } if (numXOnes != b || numYOnes != b) { out.println("No"); continue OUTER; } if (y[0] == '0' || x[0] == '0') { out.println("No"); continue OUTER; } out.println("Yes"); out.println(toString(x)); out.println(toString(y)); } out.close(); } static class State { int node, dist, from; State(int ll, int rr, int zz) { node = ll; dist = rr; from = zz; } } static int treeDiameter(UGraph ug) { int n = ug.V(); int farthest = -1; int[] distTo = new int[n]; diamDFS(0, -1, 0, ug, distTo); int maxDist = -1; for (int i = 0; i < n; i++) if (maxDist < distTo[i]) { maxDist = distTo[i]; farthest = i; } distTo = new int[n]; diamDFS(farthest, -1, 0, ug, distTo); return Arrays.stream(distTo).max().getAsInt(); } static void diamDFS(int current, int from, int dist, UGraph ug, int[] distTo) { distTo[current] = dist; for (int adj : ug.adj(current)) if (adj != from) diamDFS(adj, current, dist + 1, ug, distTo); } static class LCA { int[] height, first, segtree; ArrayList<Integer> euler; boolean[] visited; int n; LCA(UGraph ug, int root) { n = ug.V(); height = new int[n]; first = new int[n]; euler = new ArrayList<>(); visited = new boolean[n]; dfs(ug, root, 0); int m = euler.size(); segtree = new int[m * 4]; build(1, 0, m - 1); } void dfs(UGraph ug, int node, int h) { visited[node] = true; height[node] = h; first[node] = euler.size(); euler.add(node); for (int adj : ug.adj(node)) { if (!visited[adj]) { dfs(ug, adj, h + 1); euler.add(node); } } } void build(int node, int b, int e) { if (b == e) { segtree[node] = euler.get(b); } else { int mid = (b + e) / 2; build(node << 1, b, mid); build(node << 1 | 1, mid + 1, e); int l = segtree[node << 1], r = segtree[node << 1 | 1]; segtree[node] = (height[l] < height[r]) ? l : r; } } int query(int node, int b, int e, int L, int R) { if (b > R || e < L) return -1; if (b >= L && e <= R) return segtree[node]; int mid = (b + e) >> 1; int left = query(node << 1, b, mid, L, R); int right = query(node << 1 | 1, mid + 1, e, L, R); if (left == -1) return right; if (right == -1) return left; return height[left] < height[right] ? left : right; } int lca(int u, int v) { int left = first[u], right = first[v]; if (left > right) { int temp = left; left = right; right = temp; } return query(1, 0, euler.size() - 1, left, right); } } static class FenwickTree { long[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates public FenwickTree(int size) { array = new long[size + 1]; } public long rsq(int ind) { assert ind > 0; long sum = 0; while (ind > 0) { sum += array[ind]; //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number ind -= ind & (-ind); } return sum; } public long rsq(int a, int b) { assert b >= a && a > 0 && b > 0; return rsq(b) - rsq(a - 1); } public void update(int ind, long value) { assert ind > 0; while (ind < array.length) { array[ind] += value; //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number ind += ind & (-ind); } } public int size() { return array.length - 1; } } static boolean[] prefMatchesSuff(char[] s) { int n = s.length; boolean[] res = new boolean[n + 1]; int[] pi = prefixFunction(s); res[0] = true; for (int p = n; p != 0; p = pi[p]) res[p] = true; return res; } static int[] prefixFunction(char[] s) { int k = s.length; int[] pfunc = new int[k + 1]; pfunc[0] = pfunc[1] = 0; for (int i = 2; i <= k; i++) { pfunc[i] = 0; for (int p = pfunc[i - 1]; p != 0; p = pfunc[p]) if (s[p] == s[i - 1]) { pfunc[i] = p + 1; break; } if (pfunc[i] == 0 && s[i - 1] == s[0]) pfunc[i] = 1; } return pfunc; } static class Edge implements Comparable<Edge> { int from, to; long weight; int id; // int hash; Edge(int fro, int t, long weigh, int i) { from = fro; to = t; weight = weigh; id = i; // hash = Objects.hash(from, to, weight); } /*public int hashCode() { return hash; }*/ public int compareTo(Edge that) { return Long.compare(this.id, that.id); } } public static long[][] sparseTable(long[] a) { int n = a.length; int b = 32-Integer.numberOfLeadingZeros(n); long[][] ret = new long[b][]; for(int i = 0, l = 1;i < b;i++, l*=2) { if(i == 0) { ret[i] = a; }else { ret[i] = new long[n-l+1]; for(int j = 0;j < n-l+1;j++) { ret[i][j] = Math.min(ret[i-1][j], ret[i-1][j+l/2]); } } } return ret; } public static long sparseRMQ(long[][] table, int l, int r) { // [a,b) assert l <= r; if(l >= r)return Integer.MAX_VALUE; // 1:0, 2:1, 3:1, 4:2, 5:2, 6:2, 7:2, 8:3 int t = 31-Integer.numberOfLeadingZeros(r-l); return Math.min(table[t][l], table[t][r-(1<<t)]); } static class Point implements Comparable<Point> { long x; long y; long z; long id; // private int hashCode; Point() { x = z = y = 0; // this.hashCode = Objects.hash(x, y, cost); } Point(Point p) { this.x = p.x; this.y = p.y; this.z = p.z; this.id = p.id; // this.hashCode = Objects.hash(x, y, cost); } Point(long x, long y, long z, long id) { this.x = x; this.y = y; this.z = z; this.id = id; // this.hashCode = Objects.hash(x, y, id); } Point(long a, long b) { this.x = a; this.y = b; this.z = 0; // this.hashCode = Objects.hash(a, b); } Point(long x, long y, long id) { this.x = x; this.y = y; this.id = id; } @Override public int compareTo(Point o) { if (this.x < o.x) return -1; if (this.x > o.x) return 1; if (this.y < o.y) return -1; if (this.y > o.y) return 1; if (this.z < o.z) return -1; if (this.z > o.z) return 1; return 0; } @Override public boolean equals(Object that) { return this.compareTo((Point) that) == 0; } /*@Override public int hashCode() { return this.hashCode; }*/ } static class BinaryLift { // FUNCTIONS: k-th ancestor and LCA in log(n) int[] parentOf; int maxJmpPow; int[][] binAncestorOf; int n; int[] lvlOf; // How this works? // a. For every node, we store the b-ancestor for b in {1, 2, 4, 8, .. log(n)}. // b. When we need k-ancestor, we represent 'k' in binary and for each set bit, we // lift level in the tree. public BinaryLift(UGraph tree) { n = tree.V(); maxJmpPow = logk(n, 2) + 1; parentOf = new int[n]; binAncestorOf = new int[n][maxJmpPow]; lvlOf = new int[n]; for (int i = 0; i < n; i++) Arrays.fill(binAncestorOf[i], -1); parentConstruct(0, -1, tree, 0); binConstruct(); } // TODO: Implement lvlOf[] initialization public BinaryLift(int[] parentOf) { this.parentOf = parentOf; n = parentOf.length; maxJmpPow = logk(n, 2) + 1; binAncestorOf = new int[n][maxJmpPow]; lvlOf = new int[n]; for (int i = 0; i < n; i++) Arrays.fill(binAncestorOf[i], -1); UGraph tree = new UGraph(n); for (int i = 1; i < n; i++) tree.addEdge(i, parentOf[i]); binConstruct(); parentConstruct(0, -1, tree, 0); } private void parentConstruct(int current, int from, UGraph tree, int depth) { parentOf[current] = from; lvlOf[current] = depth; for (int adj : tree.adj(current)) if (adj != from) parentConstruct(adj, current, tree, depth + 1); } private void binConstruct() { for (int node = 0; node < n; node++) for (int lvl = 0; lvl < maxJmpPow; lvl++) binConstruct(node, lvl); } private int binConstruct(int node, int lvl) { if (node < 0) return -1; if (lvl == 0) return binAncestorOf[node][lvl] = parentOf[node]; if (node == 0) return binAncestorOf[node][lvl] = -1; if (binAncestorOf[node][lvl] != -1) return binAncestorOf[node][lvl]; return binAncestorOf[node][lvl] = binConstruct(binConstruct(node, lvl - 1), lvl - 1); } // return ancestor which is 'k' levels above this one public int ancestor(int node, int k) { if (node < 0) return -1; if (node == 0) if (k == 0) return node; else return -1; if (k > (1 << maxJmpPow) - 1) return -1; if (k == 0) return node; int ancestor = node; int highestBit = Integer.highestOneBit(k); while (k > 0 && ancestor != -1) { ancestor = binAncestorOf[ancestor][logk(highestBit, 2)]; k -= highestBit; highestBit = Integer.highestOneBit(k); } return ancestor; } public int lca(int u, int v) { if (u == v) return u; // The invariant will be that 'u' is below 'v' initially. if (lvlOf[u] < lvlOf[v]) { int temp = u; u = v; v = temp; } // Equalizing the levels. u = ancestor(u, lvlOf[u] - lvlOf[v]); if (u == v) return u; // We will now raise level by largest fitting power of two until possible. for (int power = maxJmpPow - 1; power > -1; power--) if (binAncestorOf[u][power] != binAncestorOf[v][power]) { u = binAncestorOf[u][power]; v = binAncestorOf[v][power]; } return ancestor(u, 1); } } static class DFSTree { // NOTE: The thing is made keeping in mind that the whole // input graph is connected. UGraph tree; UGraph backUG; int hasBridge; int n; DFSTree(UGraph ug) { this.n = ug.V(); tree = new UGraph(n); hasBridge = -1; backUG = new UGraph(n); treeCalc(0, -1, new boolean[n], ug); } private void treeCalc(int current, int from, boolean[] marked, UGraph ug) { if (marked[current]) { // This is a backEdge. backUG.addEdge(from, current); return; } if (from != -1) tree.addEdge(from, current); marked[current] = true; for (int adj : ug.adj(current)) if (adj != from) treeCalc(adj, current, marked, ug); } public boolean hasBridge() { if (hasBridge != -1) return (hasBridge == 1); // We have to determine the bridge. bridgeFinder(); return (hasBridge == 1); } int[] levelOf; int[] dp; private void bridgeFinder() { // Finding the level of each node. levelOf = new int[n]; // Applying DP solution. // dp[i] -> Highest level reachable from subtree of 'i' using // some backEdge. dp = new int[n]; Arrays.fill(dp, Integer.MAX_VALUE / 100); dpDFS(0, -1, 0); // Now, we will check each edge and determine whether its a // bridge. for (int i = 0; i < n; i++) for (int adj : tree.adj(i)) { // (i -> adj) is the edge. if (dp[adj] > levelOf[i]) hasBridge = 1; } if (hasBridge != 1) hasBridge = 0; } private int dpDFS(int current, int from, int lvl) { levelOf[current] = lvl; dp[current] = levelOf[current]; for (int back : backUG.adj(current)) dp[current] = Math.min(dp[current], levelOf[back]); for (int adj : tree.adj(current)) if (adj != from) dp[current] = Math.min(dp[current], dpDFS(adj, current, lvl + 1)); return dp[current]; } } static class UnionFind { // Uses weighted quick-union with path compression. private int[] parent; // parent[i] = parent of i private int[] size; // size[i] = number of sites in tree rooted at i // Note: not necessarily correct if i is not a root node private int count; // number of components public UnionFind(int n) { count = n; parent = new int[n]; size = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; size[i] = 1; } } // Number of connected components. public int count() { return count; } // Find the root of p. public int find(int p) { while (p != parent[p]) p = parent[p]; return p; } public boolean connected(int p, int q) { return find(p) == find(q); } public int numConnectedTo(int node) { return size[find(node)]; } // Weighted union. public void union(int p, int q) { int rootP = find(p); int rootQ = find(q); if (rootP == rootQ) return; // make smaller root point to larger one if (size[rootP] < size[rootQ]) { parent[rootP] = rootQ; size[rootQ] += size[rootP]; } else { parent[rootQ] = rootP; size[rootP] += size[rootQ]; } count--; } public static int[] connectedComponents(UnionFind uf) { // We can do this in nlogn. int n = uf.size.length; int[] compoColors = new int[n]; for (int i = 0; i < n; i++) compoColors[i] = uf.find(i); HashMap<Integer, Integer> oldToNew = new HashMap<>(); int newCtr = 0; for (int i = 0; i < n; i++) { int thisOldColor = compoColors[i]; Integer thisNewColor = oldToNew.get(thisOldColor); if (thisNewColor == null) thisNewColor = newCtr++; oldToNew.put(thisOldColor, thisNewColor); compoColors[i] = thisNewColor; } return compoColors; } } static class UGraph { // Adjacency list. private HashSet<Integer>[] adj; private static final String NEWLINE = "\n"; private int E; @SuppressWarnings("unchecked") public UGraph(int V) { adj = (HashSet<Integer>[]) new HashSet[V]; E = 0; for (int i = 0; i < V; i++) adj[i] = new HashSet<Integer>(); } public void addEdge(int from, int to) { if (adj[from].contains(to)) return; E++; adj[from].add(to); adj[to].add(from); } public HashSet<Integer> adj(int from) { return adj[from]; } public int degree(int v) { return adj[v].size(); } public int V() { return adj.length; } public int E() { return E; } public String toString() { StringBuilder s = new StringBuilder(); s.append(V() + " vertices, " + E() + " edges " + NEWLINE); for (int v = 0; v < V(); v++) { s.append(v + ": "); for (int w : adj[v]) { s.append(w + " "); } s.append(NEWLINE); } return s.toString(); } public static void dfsMark(int current, boolean[] marked, UGraph g) { if (marked[current]) return; marked[current] = true; Iterable<Integer> adj = g.adj(current); for (int adjc : adj) dfsMark(adjc, marked, g); } public static void dfsMark(int current, int from, long[] distTo, boolean[] marked, UGraph g, ArrayList<Integer> endPoints) { if (marked[current]) return; marked[current] = true; if (from != -1) distTo[current] = distTo[from] + 1; HashSet<Integer> adj = g.adj(current); int alreadyMarkedCtr = 0; for (int adjc : adj) { if (marked[adjc]) alreadyMarkedCtr++; dfsMark(adjc, current, distTo, marked, g, endPoints); } if (alreadyMarkedCtr == adj.size()) endPoints.add(current); } public static void bfsOrder(int current, UGraph g) { } public static void dfsMark(int current, int[] colorIds, int color, UGraph g) { if (colorIds[current] != -1) return; colorIds[current] = color; Iterable<Integer> adj = g.adj(current); for (int adjc : adj) dfsMark(adjc, colorIds, color, g); } public static int[] connectedComponents(UGraph g) { int n = g.V(); int[] componentId = new int[n]; Arrays.fill(componentId, -1); int colorCtr = 0; for (int i = 0; i < n; i++) { if (componentId[i] != -1) continue; dfsMark(i, componentId, colorCtr, g); colorCtr++; } return componentId; } public static boolean hasCycle(UGraph ug) { int n = ug.V(); boolean[] marked = new boolean[n]; boolean[] hasCycleFirst = new boolean[1]; for (int i = 0; i < n; i++) { if (marked[i]) continue; hcDfsMark(i, ug, marked, hasCycleFirst, -1); } return hasCycleFirst[0]; } // Helper for hasCycle. private static void hcDfsMark(int current, UGraph ug, boolean[] marked, boolean[] hasCycleFirst, int parent) { if (marked[current]) return; if (hasCycleFirst[0]) return; marked[current] = true; HashSet<Integer> adjc = ug.adj(current); for (int adj : adjc) { if (marked[adj] && adj != parent && parent != -1) { hasCycleFirst[0] = true; return; } hcDfsMark(adj, ug, marked, hasCycleFirst, current); } } } static class Digraph { // Adjacency list. private HashSet<Integer>[] adj; private static final String NEWLINE = "\n"; private int E; @SuppressWarnings("unchecked") public Digraph(int V) { adj = (HashSet<Integer>[]) new HashSet[V]; E = 0; for (int i = 0; i < V; i++) adj[i] = new HashSet<Integer>(); } public void addEdge(int from, int to) { if (adj[from].contains(to)) return; E++; adj[from].add(to); } public HashSet<Integer> adj(int from) { return adj[from]; } public int V() { return adj.length; } public int E() { return E; } public Digraph reversed() { Digraph dg = new Digraph(V()); for (int i = 0; i < V(); i++) for (int adjVert : adj(i)) dg.addEdge(adjVert, i); return dg; } public String toString() { StringBuilder s = new StringBuilder(); s.append(V() + " vertices, " + E() + " edges " + NEWLINE); for (int v = 0; v < V(); v++) { s.append(v + ": "); for (int w : adj[v]) { s.append(w + " "); } s.append(NEWLINE); } return s.toString(); } public static int[] KosarajuSharirSCC(Digraph dg) { int[] id = new int[dg.V()]; Digraph reversed = dg.reversed(); // Gotta perform topological sort on this one to get the stack. Stack<Integer> revStack = Digraph.topologicalSort(reversed); // Initializing id and idCtr. id = new int[dg.V()]; int idCtr = -1; // Creating a 'marked' array. boolean[] marked = new boolean[dg.V()]; while (!revStack.isEmpty()) { int vertex = revStack.pop(); if (!marked[vertex]) sccDFS(dg, vertex, marked, ++idCtr, id); } return id; } private static void sccDFS(Digraph dg, int source, boolean[] marked, int idCtr, int[] id) { marked[source] = true; id[source] = idCtr; for (Integer adjVertex : dg.adj(source)) if (!marked[adjVertex]) sccDFS(dg, adjVertex, marked, idCtr, id); } public static Stack<Integer> topologicalSort(Digraph dg) { // dg has to be a directed acyclic graph. // We'll have to run dfs on the digraph and push the deepest nodes on stack first. // We'll need a Stack<Integer> and a int[] marked. Stack<Integer> topologicalStack = new Stack<Integer>(); boolean[] marked = new boolean[dg.V()]; // Calling dfs for (int i = 0; i < dg.V(); i++) if (!marked[i]) runDfs(dg, topologicalStack, marked, i); return topologicalStack; } static void runDfs(Digraph dg, Stack<Integer> topologicalStack, boolean[] marked, int source) { marked[source] = true; for (Integer adjVertex : dg.adj(source)) if (!marked[adjVertex]) runDfs(dg, topologicalStack, marked, adjVertex); topologicalStack.add(source); } } static class FastReader { private BufferedReader bfr; private StringTokenizer st; public FastReader() { bfr = new BufferedReader(new InputStreamReader(System.in)); } String next() { if (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(bfr.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return next().toCharArray()[0]; } String nextString() { return next(); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } double[] nextDoubleArray(int n) { double[] arr = new double[n]; for (int i = 0; i < arr.length; i++) arr[i] = nextDouble(); return arr; } long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } int[][] nextIntGrid(int n, int m) { int[][] grid = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) grid[i][j] = fr.nextInt(); } return grid; } } static class SegmentTree { private Node[] heap; private long[] array; private int size; public SegmentTree(long[] array) { this.array = Arrays.copyOf(array, array.length); //The max size of this array is about 2 * 2 ^ log2(n) + 1 size = (int) (2 * Math.pow(2.0, Math.floor((Math.log((double) array.length) / Math.log(2.0)) + 1))); heap = new Node[size]; build(1, 0, array.length); } public int size() { return array.length; } //Initialize the Nodes of the Segment tree private void build(int v, int from, int size) { heap[v] = new Node(); heap[v].from = from; heap[v].to = from + size - 1; if (size == 1) { heap[v].sum = array[from]; heap[v].min = array[from]; heap[v].max = array[from]; } else { //Build childs build(2 * v, from, size / 2); build(2 * v + 1, from + size / 2, size - size / 2); heap[v].sum = heap[2 * v].sum + heap[2 * v + 1].sum; //min = min of the children heap[v].min = Math.min(heap[2 * v].min, heap[2 * v + 1].min); heap[v].max = Math.max(heap[2 * v].max, heap[2 * v + 1].max); } } public long rsq(int from, int to) { return rsq(1, from, to); } private long rsq(int v, int from, int to) { Node n = heap[v]; //If you did a range update that contained this node, you can infer the Sum without going down the tree if (n.pendingVal != null && contains(n.from, n.to, from, to)) { return (to - from + 1) * n.pendingVal; } if (contains(from, to, n.from, n.to)) { return heap[v].sum; } if (intersects(from, to, n.from, n.to)) { propagate(v); long leftSum = rsq(2 * v, from, to); long rightSum = rsq(2 * v + 1, from, to); return leftSum + rightSum; } return 0; } public long rMinQ(int from, int to) { return rMinQ(1, from, to); } private long rMinQ(int v, int from, int to) { Node n = heap[v]; //If you did a range update that contained this node, you can infer the Min value without going down the tree if (n.pendingVal != null && contains(n.from, n.to, from, to)) { return n.pendingVal; } if (contains(from, to, n.from, n.to)) { return heap[v].min; } if (intersects(from, to, n.from, n.to)) { propagate(v); long leftMin = rMinQ(2 * v, from, to); long rightMin = rMinQ(2 * v + 1, from, to); return Math.min(leftMin, rightMin); } return Integer.MAX_VALUE; } public long rMaxQ(int from, int to) { return rMaxQ(1, from, to); } private long rMaxQ(int v, int from, int to) { Node n = heap[v]; //If you did a range update that contained this node, you can infer the Min value without going down the tree if (n.pendingVal != null && contains(n.from, n.to, from, to)) { return n.pendingVal; } if (contains(from, to, n.from, n.to)) { return heap[v].max; } if (intersects(from, to, n.from, n.to)) { propagate(v); long leftMax = rMaxQ(2 * v, from, to); long rightMax = rMaxQ(2 * v + 1, from, to); return Math.max(leftMax, rightMax); } return Integer.MIN_VALUE; } public void update(int from, int to, long value) { update(1, from, to, value); } private void update(int v, int from, int to, long value) { //The Node of the heap tree represents a range of the array with bounds: [n.from, n.to] Node n = heap[v]; if (contains(from, to, n.from, n.to)) { change(n, value); } if (n.size() == 1) return; if (intersects(from, to, n.from, n.to)) { propagate(v); update(2 * v, from, to, value); update(2 * v + 1, from, to, value); n.sum = heap[2 * v].sum + heap[2 * v + 1].sum; n.min = Math.min(heap[2 * v].min, heap[2 * v + 1].min); n.max = Math.max(heap[2 * v].max, heap[2 * v + 1].max); } } //Propagate temporal values to children private void propagate(int v) { Node n = heap[v]; if (n.pendingVal != null) { change(heap[2 * v], n.pendingVal); change(heap[2 * v + 1], n.pendingVal); n.pendingVal = null; //unset the pending propagation value } } //Save the temporal values that will be propagated lazily private void change(Node n, long value) { n.pendingVal = value; n.sum = n.size() * value; n.min = value; n.max = value; array[n.from] = value; } //Test if the range1 contains range2 private boolean contains(int from1, int to1, int from2, int to2) { return from2 >= from1 && to2 <= to1; } //check inclusive intersection, test if range1[from1, to1] intersects range2[from2, to2] private boolean intersects(int from1, int to1, int from2, int to2) { return from1 <= from2 && to1 >= from2 // (.[..)..] or (.[...]..) || from1 >= from2 && from1 <= to2; // [.(..]..) or [..(..).. } //The Node class represents a partition range of the array. static class Node { long sum; long min; long max; //Here we store the value that will be propagated lazily Long pendingVal = null; int from; int to; int size() { return to - from + 1; } } } @SuppressWarnings("serial") static class CountMap<T> extends TreeMap<T, Integer>{ CountMap() { } CountMap(T[] arr) { this.putCM(arr); } public Integer putCM(T key) { return super.put(key, super.getOrDefault(key, 0) + 1); } public Integer removeCM(T key) { int count = super.getOrDefault(key, -1); if (count == -1) return -1; if (count == 1) return super.remove(key); else return super.put(key, count - 1); } public Integer getCM(T key) { return super.getOrDefault(key, 0); } public void putCM(T[] arr) { for (T l : arr) this.putCM(l); } } static long dioGCD(long a, long b, long[] x0, long[] y0) { if (b == 0) { x0[0] = 1; y0[0] = 0; return a; } long[] x1 = new long[1], y1 = new long[1]; long d = dioGCD(b, a % b, x1, y1); x0[0] = y1[0]; y0[0] = x1[0] - y1[0] * (a / b); return d; } static boolean diophantine(long a, long b, long c, long[] x0, long[] y0, long[] g) { g[0] = dioGCD(Math.abs(a), Math.abs(b), x0, y0); if (c % g[0] > 0) { return false; } x0[0] *= c / g[0]; y0[0] *= c / g[0]; if (a < 0) x0[0] = -x0[0]; if (b < 0) y0[0] = -y0[0]; return true; } static long[][] prod(long[][] mat1, long[][] mat2) { int n = mat1.length; long[][] prod = new long[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) // determining prod[i][j] // it will be the dot product of mat1[i][] and mat2[][i] for (int k = 0; k < n; k++) prod[i][j] += mat1[i][k] * mat2[k][j]; return prod; } static long[][] matExpo(long[][] mat, long power) { int n = mat.length; long[][] ans = new long[n][n]; if (power == 0) return null; if (power == 1) return mat; long[][] half = matExpo(mat, power / 2); ans = prod(half, half); if (power % 2 == 1) { ans = prod(ans, mat); } return ans; } static int KMPNumOcc(char[] text, char[] pat) { int n = text.length; int m = pat.length; char[] patPlusText = new char[n + m + 1]; for (int i = 0; i < m; i++) patPlusText[i] = pat[i]; patPlusText[m] = '^'; // Seperator for (int i = 0; i < n; i++) patPlusText[m + i] = text[i]; int[] fullPi = piCalcKMP(patPlusText); int answer = 0; for (int i = 0; i < n + m + 1; i++) if (fullPi[i] == m) answer++; return answer; } static int[] piCalcKMP(char[] s) { int n = s.length; int[] pi = new int[n]; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) j++; pi[i] = j; } return pi; } static long hash(long key) { long h = Long.hashCode(key); h ^= (h >>> 20) ^ (h >>> 12) ^ (h >>> 7) ^ (h >>> 4); return h & (gigamod-1); } static int mapTo1D(int row, int col, int n, int m) { // Maps elements in a 2D matrix serially to elements in // a 1D array. return row * m + col; } static int[] mapTo2D(int idx, int n, int m) { // Inverse of what the one above does. int[] rnc = new int[2]; rnc[0] = idx / m; rnc[1] = idx % m; return rnc; } static boolean[] primeGenerator(int upto) { // Sieve of Eratosthenes: isPrime = new boolean[upto + 1]; smallestFactorOf = new int[upto + 1]; Arrays.fill(smallestFactorOf, 1); Arrays.fill(isPrime, true); isPrime[1] = isPrime[0] = false; for (long i = 2; i < upto + 1; i++) if (isPrime[(int) i]) { smallestFactorOf[(int) i] = (int) i; // Mark all the multiples greater than or equal // to the square of i to be false. for (long j = i; j * i < upto + 1; j++) { if (isPrime[(int) j * (int) i]) { isPrime[(int) j * (int) i] = false; smallestFactorOf[(int) j * (int) i] = (int) i; } } } return isPrime; } static HashMap<Integer, Integer> smolNumPrimeFactorization(int num) { if (smallestFactorOf == null) primeGenerator(num + 1); HashMap<Integer, Integer> fnps = new HashMap<>(); while (num != 1) { fnps.put(smallestFactorOf[num], fnps.getOrDefault(smallestFactorOf[num], 0) + 1); num /= smallestFactorOf[num]; } return fnps; } static HashMap<Long, Integer> primeFactorization(long num) { // Returns map of factor and its power in the number. HashMap<Long, Integer> map = new HashMap<>(); while (num % 2 == 0) { num /= 2; Integer pwrCnt = map.get(2L); map.put(2L, pwrCnt != null ? pwrCnt + 1 : 1); } for (long i = 3; i * i <= num; i += 2) { while (num % i == 0) { num /= i; Integer pwrCnt = map.get(i); map.put(i, pwrCnt != null ? pwrCnt + 1 : 1); } } // If the number is prime, we have to add it to the // map. if (num != 1) map.put(num, 1); return map; } static HashSet<Long> divisors(long num) { HashSet<Long> divisors = new HashSet<Long>(); divisors.add(1L); divisors.add(num); for (long i = 2; i * i <= num; i++) { if (num % i == 0) { divisors.add(num/i); divisors.add(i); } } return divisors; } static void coprimeGenerator(int m, int n, ArrayList<Point> coprimes, int limit, int numCoprimes) { if (m > limit) return; if (m <= limit && n <= limit) coprimes.add(new Point(m, n)); if (coprimes.size() > numCoprimes) return; coprimeGenerator(2 * m - n, m, coprimes, limit, numCoprimes); coprimeGenerator(2 * m + n, m, coprimes, limit, numCoprimes); coprimeGenerator(m + 2 * n, n, coprimes, limit, numCoprimes); } static int bsearch(int[] arr, int val, int lo, int hi) { // Returns the index of the first element // larger than or equal to val. int idx = -1; while (lo <= hi) { int mid = lo + (hi - lo)/2; if (arr[mid] >= val) { idx = mid; hi = mid - 1; } else lo = mid + 1; } return idx; } static int bsearch(long[] arr, long val, int lo, int hi) { // Returns the index of the first element // larger than or equal to val. int idx = -1; while (lo <= hi) { int mid = lo + (hi - lo)/2; if (arr[mid] >= val) { idx = mid; hi = mid - 1; } else lo = mid + 1; } return idx; } static int bsearch(long[] arr, long val, int lo, int hi, boolean sMode) { // Returns the index of the last element // smaller than or equal to val. int idx = -1; while (lo <= hi) { int mid = lo + (hi - lo)/2; if (arr[mid] > val) { hi = mid - 1; } else { idx = mid; lo = mid + 1; } } return idx; } static int bsearch(int[] arr, long val, int lo, int hi, boolean sMode) { int idx = -1; while (lo <= hi) { int mid = lo + (hi - lo)/2; if (arr[mid] > val) { hi = mid - 1; } else { idx = mid; lo = mid + 1; } } return idx; } static long nCr(long n, long r, long[] fac) { long p = mod; if (r == 0) return 1; return (fac[(int)n] * modInverse(fac[(int)r], p) % p * modInverse(fac[(int)n - (int)r], p) % p) % p; } static long modInverse(long n, long p) { return power(n, p - 2, p); } static long modDiv(long a, long b){return mod(a * power(b, gigamod - 2, gigamod));} static long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if ((y & 1)==1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static int logk(long n, long k) { return (int)(Math.log(n) / Math.log(k)); } static long gcd(long a, long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } static int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } static long gcd(long[] arr) { int n = arr.length; long gcd = arr[0]; for (int i = 1; i < n; i++) { gcd = gcd(gcd, arr[i]); } return gcd; } static int gcd(int[] arr) { int n = arr.length; int gcd = arr[0]; for (int i = 1; i < n; i++) { gcd = gcd(gcd, arr[i]); } return gcd; } static long lcm(long[] arr) { long lcm = arr[0]; int n = arr.length; for (int i = 1; i < n; i++) { lcm = (lcm * arr[i]) / gcd(lcm, arr[i]); } return lcm; } static long lcm(long a, long b) { return (a * b)/gcd(a, b); } static boolean less(int a, int b) { return a < b ? true : false; } static boolean isSorted(int[] a) { for (int i = 1; i < a.length; i++) { if (less(a[i], a[i - 1])) return false; } return true; } static boolean isSorted(long[] a) { for (int i = 1; i < a.length; i++) { if (a[i] < a[i - 1]) return false; } return true; } static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } static void swap(long[] a, int i, int j) { long temp = a[i]; a[i] = a[j]; a[j] = temp; } static void swap(double[] a, int i, int j) { double temp = a[i]; a[i] = a[j]; a[j] = temp; } static void swap(char[] a, int i, int j) { char temp = a[i]; a[i] = a[j]; a[j] = temp; } static void sort(int[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); } static void sort(char[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); } static void sort(long[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); } static void sort(double[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); } static void reverseSort(int[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); int n = arr.length; for (int i = 0; i < n/2; i++) swap(arr, i, n - 1 - i); } static void reverseSort(char[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); int n = arr.length; for (int i = 0; i < n/2; i++) swap(arr, i, n - 1 - i); } static void reverse(char[] arr) { int n = arr.length; for (int i = 0; i < n / 2; i++) swap(arr, i, n - 1 - i); } static void reverseSort(long[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); int n = arr.length; for (int i = 0; i < n/2; i++) swap(arr, i, n - 1 - i); } static void reverseSort(double[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); int n = arr.length; for (int i = 0; i < n/2; i++) swap(arr, i, n - 1 - i); } static void shuffleArray(long[] arr, int startPos, int endPos) { Random rnd = new Random(); for (int i = startPos; i < endPos; ++i) { long tmp = arr[i]; int randomPos = i + rnd.nextInt(endPos - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } static void shuffleArray(int[] arr, int startPos, int endPos) { Random rnd = new Random(); for (int i = startPos; i < endPos; ++i) { int tmp = arr[i]; int randomPos = i + rnd.nextInt(endPos - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } static void shuffleArray(double[] arr, int startPos, int endPos) { Random rnd = new Random(); for (int i = startPos; i < endPos; ++i) { double tmp = arr[i]; int randomPos = i + rnd.nextInt(endPos - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } static void shuffleArray(char[] arr, int startPos, int endPos) { Random rnd = new Random(); for (int i = startPos; i < endPos; ++i) { char tmp = arr[i]; int randomPos = i + rnd.nextInt(endPos - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } static boolean isPrime(long n) {if (n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;} static String toString(int[] dp){StringBuilder sb=new StringBuilder();for(int i=0;i<dp.length;i++)sb.append(dp[i]+" ");return sb.toString();} static String toString(boolean[] dp){StringBuilder sb=new StringBuilder();for(int i=0;i<dp.length;i++)sb.append(dp[i]+" ");return sb.toString();} static String toString(long[] dp){StringBuilder sb=new StringBuilder();for(int i=0;i<dp.length;i++)sb.append(dp[i]+" ");return sb.toString();} static String toString(char[] dp){StringBuilder sb=new StringBuilder();for(int i=0;i<dp.length;i++)sb.append(dp[i]+"");return sb.toString();} static String toString(int[][] dp){StringBuilder sb=new StringBuilder();for(int i=0;i<dp.length;i++){for(int j=0;j<dp[i].length;j++){sb.append(dp[i][j]+" ");}sb.append('\n');}return sb.toString();} static String toString(long[][] dp){StringBuilder sb=new StringBuilder();for(int i=0;i<dp.length;i++){for(int j=0;j<dp[i].length;j++) {sb.append(dp[i][j]+" ");}sb.append('\n');}return sb.toString();} static String toString(double[][] dp){StringBuilder sb=new StringBuilder();for(int i = 0;i<dp.length;i++){for(int j = 0;j<dp[i].length;j++){sb.append(dp[i][j]+" ");}sb.append('\n');}return sb.toString();} static String toString(char[][] dp){StringBuilder sb = new StringBuilder();for(int i = 0;i<dp.length;i++){for(int j = 0;j<dp[i].length;j++){sb.append(dp[i][j]+"");}sb.append('\n');}return sb.toString();} static long mod(long a, long m){return(a%m+1000000L*m)%m;} static long mod(long num){return(num%gigamod+gigamod)%gigamod;} } // NOTES: // ASCII VALUE OF 'A': 65 // ASCII VALUE OF 'a': 97 // Range of long: 9 * 10^18 // ASCII VALUE OF '0': 48 // Primes upto 'n' can be given by (n / (logn)).
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
fdc87c77ac427dd649f5ae2e1d653665
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 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.HashMap; import java.util.HashSet; import java.util.Random; import java.util.Stack; import java.util.StringTokenizer; // CFPS -> CodeForcesProblemSet public final class CFPS { static FastReader fr = new FastReader(); static PrintWriter out = new PrintWriter(System.out); static final int gigamod = 1000000007; static int t = 1; static double epsilon = 0.0000001; static boolean[] isPrime; static int[] smallestFactorOf; @SuppressWarnings("unused") public static void main(String[] args) { OUTER: for (int tc = 0; tc < t; tc++) { int a = fr.nextInt(), b = fr.nextInt(), k = fr.nextInt(); int acpy = a, bcpy = b; int n = a + b; // Observations: // 1. The task is to determine two binary integers 'x' and 'y' such that // both contain 'a' zeroes and 'b' ones and (x - y) contains 'k' ones. char[] x = new char[n]; char[] y = new char[n]; if (k == 0) { for (int i = 0; i < b; i++) x[i] = '1'; for (int i = 0; i < a; i++) x[i + b] = '0'; out.println("Yes"); out.println(toString(x)); out.println(toString(x)); continue OUTER; } Arrays.fill(x, '0'); Arrays.fill(y, '0'); x[0] = '1'; y[0] = '1'; b--; if (k > 0 && b == 0) { out.println("No"); continue OUTER; } if (k + 1 > n - 1) { out.println("No"); continue OUTER; } x[1] = '1'; y[k + 1] = '1'; b--; for (int i = 2; i < n; i++) if (i != k + 1) if (b > 0) { x[i] = '1'; y[i] = '1'; b--; } // Now, we will verify our solution. int oneCount = 0, zeroCount = 0; for (int i = 0; i < n; i++) if (x[i] == '1') oneCount++; else zeroCount++; if (oneCount != bcpy || zeroCount != acpy) { out.println("No"); continue OUTER; } out.println("Yes"); out.println(toString(x)); out.println(toString(y)); } out.close(); } public static class FenwickTree { long[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates public FenwickTree(int size) { array = new long[size + 1]; } public long rsq(int ind) { assert ind > 0; long sum = 0; while (ind > 0) { sum += array[ind]; //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number ind -= ind & (-ind); } return sum; } public long rsq(int a, int b) { assert b >= a && a > 0 && b > 0; return rsq(b) - rsq(a - 1); } public void update(int ind, long value) { assert ind > 0; while (ind < array.length) { array[ind] += value; //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number ind += ind & (-ind); } } public int size() { return array.length - 1; } } static int longestPrefixPalindromeLen(char[] s) { int n = s.length; StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) sb.append(s[i]); StringBuilder sb2 = new StringBuilder(sb); sb.append('^'); sb.append(sb2.reverse()); // out.println(sb.toString()); char[] newS = sb.toString().toCharArray(); int m = newS.length; int[] pi = piCalcKMP(newS); return pi[m - 1]; } static int KMPNumOcc(char[] text, char[] pat) { int n = text.length; int m = pat.length; char[] patPlusText = new char[n + m + 1]; for (int i = 0; i < m; i++) patPlusText[i] = pat[i]; patPlusText[m] = '^'; // Seperator for (int i = 0; i < n; i++) patPlusText[m + i] = text[i]; int[] fullPi = piCalcKMP(patPlusText); int answer = 0; for (int i = 0; i < n + m + 1; i++) if (fullPi[i] == m) answer++; return answer; } static int[] piCalcKMP(char[] s) { int n = s.length; int[] pi = new int[n]; for (int i = 1; i < n; i++) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) j++; pi[i] = j; } return pi; } static String toBinaryString(long num, int bits) { StringBuilder sb = new StringBuilder(Long.toBinaryString(num)); sb.reverse(); for (int i = sb.length(); i < bits; i++) sb.append('0'); return sb.reverse().toString(); } // Manual implementation of RB-BST for C++ PBDS functionality. // Modification required according to requirements. public static final class RedBlackCountSet { // Colors for Nodes: private static final boolean RED = true; private static final boolean BLACK = false; // Pointer to the root: private Node root; // Public constructor: public RedBlackCountSet() { root = null; } // Node class for storing key value pairs: private class Node { long key; long value; Node left, right; boolean color; long size; // Size of the subtree rooted at that node. public Node(long key, long value, boolean color) { this.key = key; this.value = value; this.left = this.right = null; this.color = color; this.size = value; } } /***** Invariant Maintenance functions: *****/ // When a temporary 4 node is formed: private Node flipColors(Node node) { node.left.color = node.right.color = BLACK; node.color = RED; return node; } // When there's a right leaning red link and it is not a 3 node: private Node rotateLeft(Node node) { Node rn = node.right; node.right = rn.left; rn.left = node; rn.color = node.color; node.color = RED; return rn; } // When there are 2 red links in a row: private Node rotateRight(Node node) { Node ln = node.left; node.left = ln.right; ln.right = node; ln.color = node.color; node.color = RED; return ln; } /***** Invariant Maintenance functions end *****/ // Public functions: public void put(long key) { root = put(root, key); root.color = BLACK; // One of the invariants. } private Node put(Node node, long key) { // Standard insertion procedure: if (node == null) return new Node(key, 1, RED); // Recursing: int cmp = Long.compare(key, node.key); if (cmp < 0) node.left = put(node.left, key); else if (cmp > 0) node.right = put(node.right, key); else node.value++; // Invariant maintenance: if (node.left != null && node.right != null) { if (node.right.color = RED && node.left.color == BLACK) node = rotateLeft(node); if (node.left.color == RED && node.left.left.color == RED) node = rotateRight(node); if (node.left.color == RED && node.right.color == RED) node = flipColors(node); } // Property maintenance: node.size = node.value + size(node.left) + size(node.right); return node; } private long size(Node node) { if (node == null) return 0; else return node.size; } public long rank(long key) { return rank(root, key); } // Modify according to requirements. private long rank(Node node, long key) { if (node == null) return 0; int cmp = Long.compare(key, node.key); if (cmp < 0) return rank(node.left, key); else if (cmp > 0) return node.value + size(node.left) + rank(node.right, key); else return node.value + size(node.left); } } static long modDiv(long a, long b) { return mod(a * power(b, gigamod - 2, gigamod)); } static class SegTree { // Setting up the parameters. int n; // Size of the array long[] sumTree; long[] ogArr; long[] maxTree; long[] minTree; boolean[] prpgtMarked; // For segment assignment operation with // lazy updates public static final int sumMode = 0; public static final int maxMode = 1; public static final int minMode = 2; // Constructor public SegTree(long[] arr, int mode) { if (mode == sumMode) { Arrays.fill(sumTree = new long[4 * (n = ((ogArr = arr.clone()).length))], -1); buildSum(0, n - 1, 0); } else if (mode == maxMode) { Arrays.fill(maxTree = new long[4 * (n = ((ogArr = arr.clone()).length))], -1); buildMax(0, n - 1, 0); } else if (mode == minMode) { Arrays.fill(minTree = new long[4 * (n = ((ogArr = arr.clone()).length))], Long.MAX_VALUE - 1); buildMin(0, n - 1, 0); } prpgtMarked = new boolean[minTree.length]; } /**********Code for sum***********/ /*********************************/ // Build the segment tree node-by-node private long buildSum(int l, int r, int segIdx) { return sumTree[segIdx] = (l == r) ? ogArr[l] : (buildSum(l, l + (r - l) / 2, 2 * segIdx + 1) + buildSum((l + (r - l) / 2) + 1, r, 2 * segIdx + 2)); } // Change a single element public void changeForSum(int idx, long to) { changeForSum(idx, to, 0, n - 1, 0); } private long changeForSum(int idx, long to, int l, int r, int segIdx) { return sumTree[segIdx] = ((l == r) ? (ogArr[idx] = to) : ((0 * ((idx <= (l + (r - l) / 2)) ? changeForSum(idx, to, l, l + (r - l) / 2, 2 * segIdx + 1) : changeForSum(idx, to, (l + (r - l) / 2) + 1, r, 2 * segIdx + 2))) + sumTree[2 * segIdx + 1] + sumTree[2 * segIdx + 2])); } // Return the sum arr[l, r] public long segSum(int l, int r) { if (l > r) return 0; return segSum(l, r, 0, n - 1, 0); } private long segSum(int segL, int segR, int l, int r, int segIdx) { if (segL == l && segR == r) return sumTree[segIdx]; if (segR <= l + (r - l) / 2) return segSum(segL, segR, l, l + (r - l) / 2, 2 * segIdx + 1); if (segL >= l + (r - l) / 2 + 1) return segSum(segL, segR, l + (r - l) / 2 + 1, r, 2 * segIdx + 2); return segSum(segL, l + (r - l) / 2, l, l + (r - l) / 2, 2 * segIdx + 1) + segSum(l + (r - l) / 2 + 1, segR, l + (r - l) / 2 + 1, r, 2 * segIdx + 2); } /********End of code for sum********/ /***********************************/ /*******Start of code for max*******/ /***********************************/ // Build the max tree node-by-node private long buildMax(int l, int r, int segIdx) { return maxTree[segIdx] = (l == r) ? ogArr[l] : Math.max(buildMax(l, (l + (r - l) / 2), 2 * segIdx + 1), buildMax(l + (r - l) / 2 + 1, r, 2 * segIdx + 2)); } // Change a single element public void changeForMax(int idx, long to) { changeForMax(0, n - 1, idx, to, 0); } private long changeForMax(int l, int r, int idx, long to, int segIdx) { return maxTree[segIdx] = (l == r && l == idx) ? (ogArr[idx] = to) : Math.max(changeForMax(l, l + (r - l) / 2, idx, to, 2 * segIdx + 1), changeForMax(l + (r - l) / 2 + 1, r, idx, to, 2 * segIdx + 2)); } public long segMax(int segL, int segR) { if (segL > segR) return 0; return segMax(0, n - 1, segL, segR, 0); } private long segMax(int l, int r, int segL, int segR, int segIdx) { int midL = l + (r - l) / 2; if (segL == segR && segL == l) return ogArr[segL]; if (segR <= midL) return segMax(l, midL, segL, segR, 2 * segIdx + 1); if (segL >= midL + 1) return segMax(midL + 1, r, segL, segR, 2 * segIdx + 2); return Math.max(segMax(l, midL, segL, midL, 2 * segIdx + 1), segMax(midL + 1, r, midL + 1, segR, 2 * segIdx + 2)); } /*******End of code for max*********/ /***********************************/ /*******Start of code for min*******/ /***********************************/ private long buildMin(int l, int r, int segIdx) { return minTree[segIdx] = (l == r) ? ogArr[l] : Math.min(buildMin(l, (l + (r - l) / 2), 2 * segIdx + 1), buildMin(l + (r - l) / 2 + 1, r, 2 * segIdx + 2)); } // Change a single element public void pointUpdate(int idx, long to) { pointUpdate(0, n - 1, idx, to, 0); } private long pointUpdate(int l, int r, int idx, long to, int segIdx) { asmtPush(l, r, segIdx); return minTree[segIdx] = (l == r && l == idx) ? (to) : Math.min(pointUpdate(l, l + (r - l) / 2, idx, to, 2 * segIdx + 1), pointUpdate(l + (r - l) / 2 + 1, r, idx, to, 2 * segIdx + 2)); } // Change a whole segment public void rangeUpdate(int segL, int segR, long to) { rangeUpdate(0, n - 1, segL, segR, to, 0); } private long rangeUpdate(int l, int r, int segL, int segR, long to, int segIdx) { asmtPush(l, r, segIdx); // Since we will obviously recurse. if (l == segL && r == segR) { prpgtMarked[segIdx] = true; return minTree[segIdx] = to; } int midL = l + (r - l) / 2; if (segR <= midL) return minTree[segIdx] = rangeUpdate(l, midL, segL, segR, to, 2 * segIdx + 1); if (segL >= midL + 1) return minTree[segIdx] = rangeUpdate(midL + 1, r, segL, segR, to, 2 * segIdx + 2); return minTree[segIdx] = Math.min(rangeUpdate(l, midL, segL, midL, to, 2 * segIdx + 1), rangeUpdate(midL + 1, r, midL + 1, segR, to, 2 * segIdx + 2)); } public long rangeMin(int segL, int segR) { if (segL > segR) return 0; return rangeMin(0, n - 1, segL, segR, 0); } private long rangeMin(int l, int r, int segL, int segR, int segIdx) { asmtPush(l, r, segIdx); int midL = l + (r - l) / 2; if (segL == l && segR == r) return minTree[segIdx]; if (segR <= midL) return rangeMin(l, midL, segL, segR, 2 * segIdx + 1); if (segL >= midL + 1) return rangeMin(midL + 1, r, segL, segR, 2 * segIdx + 2); return Math.min(rangeMin(l, midL, segL, midL, 2 * segIdx + 1), rangeMin(midL + 1, r, midL + 1, segR, 2 * segIdx + 2)); } /*******End of code for min*********/ /***********************************/ /*** Auxiliary functions for all modes ***/ // If it is determined that a whole segment has to be assigned some value // 'v', all children are bound to have the exact value 'v'. void asmtPush(int l, int r, int segIdx) { if (!prpgtMarked[segIdx]) return; int child1 = 2 * segIdx + 1, child2 = 2 * segIdx + 2; if (child2 > 4 * n - 1) child2 = child1; if (child1 > 4 * n - 1) return; minTree[child1] = minTree[child2] = minTree[segIdx]; prpgtMarked[child1] = prpgtMarked[child2] = true; prpgtMarked[segIdx] = false; } /*** Auxiliary functions for all modes end***/ public String toString() { return CFPS.toString(minTree); } } @SuppressWarnings("serial") static class CountMap<T> extends HashMap<T, Integer>{ CountMap() { } CountMap(T[] arr) { this.putCM(arr); } public Integer putCM(T key) { if (super.containsKey(key)) { return super.put(key, super.get(key) + 1); } else { return super.put(key, 1); } } public Integer removeCM(T key) { Integer count = super.get(key); if (count == null) return -1; if (count == 1) return super.remove(key); else return super.put(key, super.get(key) - 1); } public Integer getCM(T key) { Integer count = super.get(key); if (count == null) return 0; return count; } public void putCM(T[] arr) { for (T l : arr) this.putCM(l); } } static void coprimeGenerator(int m, int n, ArrayList<Point> coprimes, int limit, int numCoprimes) { if (m > limit) return; if (m <= limit && n <= limit) coprimes.add(new Point(m, n)); if (coprimes.size() > numCoprimes) return; coprimeGenerator(2 * m - n, m, coprimes, limit, numCoprimes); coprimeGenerator(2 * m + n, m, coprimes, limit, numCoprimes); coprimeGenerator(m + 2 * n, n, coprimes, limit, numCoprimes); } static long hash(long i) { return (i * 2654435761L % gigamod); } static long hash2(long key) { long h = Long.hashCode(key); h ^= (h >>> 20) ^ (h >>> 12) ^ (h >>> 7) ^ (h >>> 4); return h & (gigamod-1); } // Maps elements in a 2D matrix serially to elements in // a 1D array. static int mapTo1D(int row, int col, int n, int m) { return row * m + col; } // Inverse of what the one above does. static int[] mapTo2D(int idx, int n, int m) { int[] rnc = new int[2]; rnc[0] = idx / m; rnc[1] = idx % m; return rnc; } static class Point implements Comparable<Point> { long x; long y; long id; Point() { x = y = id = 0; } Point(Point p) { this.x = p.x; this.y = p.y; this.id = p.id; } Point(long a, long b, long id) { this.x = a; this.y = b; this.id = id; } Point(long a, long b) { this.x = a; this.y = b; } @Override public int compareTo(Point o) { if (this.x < o.x) return -1; if (this.x > o.x) return 1; if (this.y < o.y) return -1; if (this.y > o.y) return 1; return 0; } public boolean equals(Point that) { return this.compareTo(that) == 0; } } static double distance(Point p1, Point p2) { return Math.sqrt(Math.pow(p2.y-p1.y, 2) + Math.pow(p2.x-p1.x, 2)); } static HashMap<Integer, Integer> smolNumPrimeFactorization(int num) { if (smallestFactorOf == null) primeGenerator(2750132); CountMap<Integer> fnps = new CountMap<>(); while (num != 1) { fnps.putCM(smallestFactorOf[num]); num /= smallestFactorOf[num]; } return fnps; } // Returns map of factor and its power in the number. static HashMap<Long, Integer> primeFactorization(long num) { HashMap<Long, Integer> map = new HashMap<>(); while (num % 2 == 0) { num /= 2; Integer pwrCnt = map.get(2L); map.put(2L, pwrCnt != null ? pwrCnt + 1 : 1); } for (long i = 3; i * i <= num; i += 2) { while (num % i == 0) { num /= i; Integer pwrCnt = map.get(i); map.put(i, pwrCnt != null ? pwrCnt + 1 : 1); } } // If the number is prime, we have to add it to the // map. if (num != 1) map.put(num, 1); return map; } static HashSet<Long> divisors(long num) { HashSet<Long> divisors = new HashSet<Long>(); divisors.add(1L); divisors.add(num); for (long i = 2; i * i <= num; i++) { if (num % i == 0) { divisors.add(num/i); divisors.add(i); } } return divisors; } // Returns the index of the first element // larger than or equal to val. static int bsearch(int[] arr, int val, int lo, int hi) { int idx = -1; while (lo <= hi) { int mid = lo + (hi - lo)/2; if (arr[mid] >= val) { idx = mid; hi = mid - 1; } else lo = mid + 1; } return idx; } static int bsearch(long[] arr, long val, int lo, int hi) { int idx = -1; while (lo <= hi) { int mid = lo + (hi - lo)/2; if (arr[mid] >= val) { idx = mid; hi = mid - 1; } else lo = mid + 1; } return idx; } // Returns the index of the last element // smaller than or equal to val. static int bsearch(long[] arr, long val, int lo, int hi, boolean sMode) { int idx = -1; while (lo <= hi) { int mid = lo + (hi - lo)/2; if (arr[mid] >= val) { hi = mid - 1; } else { idx = mid; lo = mid + 1; } } return idx; } static int bsearch(int[] arr, long val, int lo, int hi, boolean sMode) { int idx = -1; while (lo <= hi) { int mid = lo + (hi - lo)/2; if (arr[mid] > val) { hi = mid - 1; } else { idx = mid; lo = mid + 1; } } return idx; } static long factorial(long n) { if (n <= 1) return 1; long factorial = 1; for (int i = 1; i <= n; i++) factorial = mod(factorial * i); return factorial; } static long factorialInDivision(long a, long b) { if (a == b) return 1; if (b < a) { long temp = a; a = b; b = temp; } long factorial = 1; for (long i = a + 1; i <= b; i++) factorial = mod(factorial * i); return factorial; } static long nCr(long n, long r, long[] fac) { long p = 998244353; // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r /*long fac[] = new long[(int)n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;*/ return (fac[(int)n] * modInverse(fac[(int)r], p) % p * modInverse(fac[(int)n - (int)r], p) % p) % p; } static long modInverse(long n, long p) { return power(n, p - 2, p); } static long power(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if ((y & 1)==1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } static long nPr(long n, long r) { return factorialInDivision(n, n - r); } static int logk(long n, long k) { return (int)(Math.log(n) / Math.log(k)); } // Sieve of Eratosthenes: static boolean[] primeGenerator(int upto) { isPrime = new boolean[upto + 1]; smallestFactorOf = new int[upto + 1]; Arrays.fill(smallestFactorOf, 1); Arrays.fill(isPrime, true); isPrime[1] = isPrime[0] = false; for (long i = 2; i < upto + 1; i++) if (isPrime[(int) i]) { smallestFactorOf[(int) i] = (int) i; // Mark all the multiples greater than or equal // to the square of i to be false. for (long j = i; j * i < upto + 1; j++) { if (isPrime[(int) j * (int) i]) { isPrime[(int) j * (int) i] = false; smallestFactorOf[(int) j * (int) i] = (int) i; } } } return isPrime; } static long gcd(long a, long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } static int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } static long gcd(long[] arr) { int n = arr.length; long gcd = arr[0]; for (int i = 1; i < n; i++) { gcd = gcd(gcd, arr[i]); } return gcd; } static int gcd(int[] arr) { int n = arr.length; int gcd = arr[0]; for (int i = 1; i < n; i++) { gcd = gcd(gcd, arr[i]); } return gcd; } static long lcm(long[] arr) { long lcm = arr[0]; int n = arr.length; for (int i = 1; i < n; i++) { lcm = (lcm * arr[i]) / gcd(lcm, arr[i]); } return lcm; } static long lcm(long a, long b) { return (a * b)/gcd(a, b); } static boolean less(int a, int b) { return a < b ? true : false; } static boolean isSorted(int[] a) { for (int i = 1; i < a.length; i++) { if (less(a[i], a[i - 1])) return false; } return true; } static boolean isSorted(long[] a) { for (int i = 1; i < a.length; i++) { if (a[i] < a[i - 1]) return false; } return true; } static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } static void swap(long[] a, int i, int j) { long temp = a[i]; a[i] = a[j]; a[j] = temp; } static void swap(double[] a, int i, int j) { double temp = a[i]; a[i] = a[j]; a[j] = temp; } static void swap(char[] a, int i, int j) { char temp = a[i]; a[i] = a[j]; a[j] = temp; } static void sort(int[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); } static void sort(char[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); } static void sort(long[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); } static void sort(double[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); } static void reverseSort(int[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); int n = arr.length; for (int i = 0; i < n/2; i++) swap(arr, i, n - 1 - i); } static void reverseSort(char[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); int n = arr.length; for (int i = 0; i < n/2; i++) swap(arr, i, n - 1 - i); } static void reverse(char[] arr) { int n = arr.length; for (int i = 0; i < n / 2; i++) swap(arr, i, n - 1 - i); } static void reverseSort(long[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); int n = arr.length; for (int i = 0; i < n/2; i++) swap(arr, i, n - 1 - i); } static void reverseSort(double[] arr) { shuffleArray(arr, 0, arr.length - 1); Arrays.sort(arr); int n = arr.length; for (int i = 0; i < n/2; i++) swap(arr, i, n - 1 - i); } static void shuffleArray(long[] arr, int startPos, int endPos) { Random rnd = new Random(); for (int i = startPos; i < endPos; ++i) { long tmp = arr[i]; int randomPos = i + rnd.nextInt(endPos - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } static void shuffleArray(int[] arr, int startPos, int endPos) { Random rnd = new Random(); for (int i = startPos; i < endPos; ++i) { int tmp = arr[i]; int randomPos = i + rnd.nextInt(endPos - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } static void shuffleArray(double[] arr, int startPos, int endPos) { Random rnd = new Random(); for (int i = startPos; i < endPos; ++i) { double tmp = arr[i]; int randomPos = i + rnd.nextInt(endPos - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } private static void shuffleArray(char[] arr, int startPos, int endPos) { Random rnd = new Random(); for (int i = startPos; i < endPos; ++i) { char tmp = arr[i]; int randomPos = i + rnd.nextInt(endPos - i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } static boolean isPrime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static String toString(int[] dp) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dp.length; i++) sb.append(dp[i] + " "); return sb.toString(); } static String toString(boolean[] dp) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dp.length; i++) sb.append(dp[i] + " "); return sb.toString(); } static String toString(long[] dp) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dp.length; i++) sb.append(dp[i] + " "); return sb.toString(); } static String toString(char[] dp) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dp.length; i++) sb.append(dp[i] + ""); return sb.toString(); } static String toString(int[][] dp) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dp.length; i++) { for (int j = 0; j < dp[i].length; j++) { sb.append(dp[i][j] + " "); } sb.append('\n'); } return sb.toString(); } static String toString(long[][] dp) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dp.length; i++) { for (int j = 0; j < dp[i].length; j++) { sb.append(dp[i][j] + " "); } sb.append('\n'); } return sb.toString(); } static String toString(double[][] dp) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dp.length; i++) { for (int j = 0; j < dp[i].length; j++) { sb.append(dp[i][j] + " "); } sb.append('\n'); } return sb.toString(); } static String toString(char[][] dp) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dp.length; i++) { for (int j = 0; j < dp[i].length; j++) { sb.append(dp[i][j] + " "); } sb.append('\n'); } return sb.toString(); } static long mod(long a, long m) { return (a%m + m) % m; } static long mod(long num) { return (num % gigamod + gigamod) % gigamod; } // Uses weighted quick-union with path compression. static class UnionFind { private int[] parent; // parent[i] = parent of i private int[] size; // size[i] = number of sites in tree rooted at i // Note: not necessarily correct if i is not a root node private int count; // number of components public UnionFind(int n) { count = n; parent = new int[n]; size = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; size[i] = 1; } } // Number of connected components. public int count() { return count; } // Find the root of p. public int find(int p) { while (p != parent[p]) p = parent[p]; return p; } public boolean connected(int p, int q) { return find(p) == find(q); } public int numConnectedTo(int node) { return size[find(node)]; } // Weighted union. public void union(int p, int q) { int rootP = find(p); int rootQ = find(q); if (rootP == rootQ) return; // make smaller root point to larger one if (size[rootP] < size[rootQ]) { parent[rootP] = rootQ; size[rootQ] += size[rootP]; } else { parent[rootQ] = rootP; size[rootP] += size[rootQ]; } count--; } public static int[] connectedComponents(UnionFind uf) { // We can do this in nlogn. int n = uf.size.length; int[] compoColors = new int[n]; for (int i = 0; i < n; i++) compoColors[i] = uf.find(i); HashMap<Integer, Integer> oldToNew = new HashMap<>(); int newCtr = 0; for (int i = 0; i < n; i++) { int thisOldColor = compoColors[i]; Integer thisNewColor = oldToNew.get(thisOldColor); if (thisNewColor == null) thisNewColor = newCtr++; oldToNew.put(thisOldColor, thisNewColor); compoColors[i] = thisNewColor; } return compoColors; } } static class UGraph { // Adjacency list. private HashSet<Integer>[] adj; private static final String NEWLINE = "\n"; private int E; public UGraph(int V) { adj = (HashSet<Integer>[]) new HashSet[V]; E = 0; for (int i = 0; i < V; i++) adj[i] = new HashSet<Integer>(); } public void addEdge(int from, int to) { if (adj[from].contains(to)) return; E++; adj[from].add(to); adj[to].add(from); } public HashSet<Integer> adj(int from) { return adj[from]; } public int degree(int v) { return adj[v].size(); } public int V() { return adj.length; } public int E() { return E; } public String toString() { StringBuilder s = new StringBuilder(); s.append(V() + " vertices, " + E() + " edges " + NEWLINE); for (int v = 0; v < V(); v++) { s.append(v + ": "); for (int w : adj[v]) { s.append(w + " "); } s.append(NEWLINE); } return s.toString(); } public static void dfsMark(int current, boolean[] marked, UGraph g) { if (marked[current]) return; marked[current] = true; Iterable<Integer> adj = g.adj(current); for (int adjc : adj) dfsMark(adjc, marked, g); } public static void dfsMark(int current, int from, long[] distTo, boolean[] marked, UGraph g, ArrayList<Integer> endPoints) { if (marked[current]) return; marked[current] = true; if (from != -1) distTo[current] = distTo[from] + 1; HashSet<Integer> adj = g.adj(current); int alreadyMarkedCtr = 0; for (int adjc : adj) { if (marked[adjc]) alreadyMarkedCtr++; dfsMark(adjc, current, distTo, marked, g, endPoints); } if (alreadyMarkedCtr == adj.size()) endPoints.add(current); } public static void bfsOrder(int current, UGraph g) { } public static void dfsMark(int current, int[] colorIds, int color, UGraph g) { if (colorIds[current] != -1) return; colorIds[current] = color; Iterable<Integer> adj = g.adj(current); for (int adjc : adj) dfsMark(adjc, colorIds, color, g); } public static int[] connectedComponents(UGraph g) { int n = g.V(); int[] componentId = new int[n]; Arrays.fill(componentId, -1); int colorCtr = 0; for (int i = 0; i < n; i++) { if (componentId[i] != -1) continue; dfsMark(i, componentId, colorCtr, g); colorCtr++; } return componentId; } public static boolean hasCycle(UGraph ug) { int n = ug.V(); boolean[] marked = new boolean[n]; boolean[] hasCycleFirst = new boolean[1]; for (int i = 0; i < n; i++) { if (marked[i]) continue; hcDfsMark(i, ug, marked, hasCycleFirst, -1); } return hasCycleFirst[0]; } // Helper for hasCycle. private static void hcDfsMark(int current, UGraph ug, boolean[] marked, boolean[] hasCycleFirst, int parent) { if (marked[current]) return; if (hasCycleFirst[0]) return; marked[current] = true; HashSet<Integer> adjc = ug.adj(current); for (int adj : adjc) { if (marked[adj] && adj != parent && parent != -1) { hasCycleFirst[0] = true; return; } hcDfsMark(adj, ug, marked, hasCycleFirst, current); } } } static class Digraph { // Adjacency list. private HashSet<Integer>[] adj; private static final String NEWLINE = "\n"; private int E; public Digraph(int V) { adj = (HashSet<Integer>[]) new HashSet[V]; E = 0; for (int i = 0; i < V; i++) adj[i] = new HashSet<Integer>(); } public void addEdge(int from, int to) { if (adj[from].contains(to)) return; E++; adj[from].add(to); } public HashSet<Integer> adj(int from) { return adj[from]; } public int V() { return adj.length; } public int E() { return E; } public Digraph reversed() { Digraph dg = new Digraph(V()); for (int i = 0; i < V(); i++) for (int adjVert : adj(i)) dg.addEdge(adjVert, i); return dg; } public String toString() { StringBuilder s = new StringBuilder(); s.append(V() + " vertices, " + E() + " edges " + NEWLINE); for (int v = 0; v < V(); v++) { s.append(v + ": "); for (int w : adj[v]) { s.append(w + " "); } s.append(NEWLINE); } return s.toString(); } public static int[] KosarajuSharirSCC(Digraph dg) { int[] id = new int[dg.V()]; Digraph reversed = dg.reversed(); // Gotta perform topological sort on this one to get the stack. Stack<Integer> revStack = Digraph.topologicalSort(reversed); // Initializing id and idCtr. id = new int[dg.V()]; int idCtr = -1; // Creating a 'marked' array. boolean[] marked = new boolean[dg.V()]; while (!revStack.isEmpty()) { int vertex = revStack.pop(); if (!marked[vertex]) sccDFS(dg, vertex, marked, ++idCtr, id); } return id; } private static void sccDFS(Digraph dg, int source, boolean[] marked, int idCtr, int[] id) { marked[source] = true; id[source] = idCtr; for (Integer adjVertex : dg.adj(source)) if (!marked[adjVertex]) sccDFS(dg, adjVertex, marked, idCtr, id); } public static Stack<Integer> topologicalSort(Digraph dg) { // dg has to be a directed acyclic graph. // We'll have to run dfs on the digraph and push the deepest nodes on stack first. // We'll need a Stack<Integer> and a int[] marked. Stack<Integer> topologicalStack = new Stack<Integer>(); boolean[] marked = new boolean[dg.V()]; // Calling dfs for (int i = 0; i < dg.V(); i++) if (!marked[i]) runDfs(dg, topologicalStack, marked, i); return topologicalStack; } static void runDfs(Digraph dg, Stack<Integer> topologicalStack, boolean[] marked, int source) { marked[source] = true; for (Integer adjVertex : dg.adj(source)) if (!marked[adjVertex]) runDfs(dg, topologicalStack, marked, adjVertex); topologicalStack.add(source); } } static class FastReader { private BufferedReader bfr; private StringTokenizer st; public FastReader() { bfr = new BufferedReader(new InputStreamReader(System.in)); } String next() { if (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(bfr.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } char nextChar() { return next().toCharArray()[0]; } String nextString() { return next(); } int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } double[] nextDoubleArray(int n) { double[] arr = new double[n]; for (int i = 0; i < arr.length; i++) arr[i] = nextDouble(); return arr; } long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } int[][] nextIntGrid(int n, int m) { int[][] grid = new int[n][m]; for (int i = 0; i < n; i++) { char[] line = fr.next().toCharArray(); for (int j = 0; j < m; j++) grid[i][j] = line[j] - 48; } return grid; } } } // NOTES: // ASCII VALUE OF 'A': 65 // ASCII VALUE OF 'a': 97 // Range of long: 9 * 10^18 // ASCII VALUE OF '0': 48 // Primes upto 'n' can be given by (n / (logn)).
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
7381765459796a954574ad9b525daf89
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class Solution { private static ArrayList<Integer> prime = new ArrayList<>(); public static void main(String[] args) throws IOException { Scanner in=new Scanner(System.in); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringBuffer out = new StringBuffer(); int T = 1; OUTER: while(T-->0) { int a=in.nextInt(), b=in.nextInt(), k=in.nextInt(); int n=a+b; if((a!=0 && k>n-2) || (b==1 && k>0) || (a==0 && k>0)) { out.append("No"); } else { int x[]=new int[n]; for(int i=0, cnt_1=1; i<n && cnt_1<b; i++) { x[i]=1; cnt_1+=1; } x[n-1]=1; int y[]=Arrays.copyOf(x, n); if(k==0) { } else if(k<=a) { y[b-2]=0; y[k+(b-2)]=1; } else { y[n-2]=1; int extra=k-a; y[(b-2)-extra]=0; } out.append("Yes\n"); for(int i=n-1; i>=0; i--) out.append(y[i]); out.append("\n"); for(int i=n-1; i>=0; i--) out.append(x[i]); } } System.out.print(out); } private static int gcd(int a, int b) { if (a==0) return b; return gcd(b%a, a); } private static int toInt(String s) { return Integer.parseInt(s); } private static long toLong(String s) { return Long.parseLong(s); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
4d3b8bf190c54d2f6e7b16d4138133ff
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
// Don't place your source in a package import java.util.*; import java.lang.*; import java.io.*; import java.math.*; // Please name your class Main public class Main { static Scanner in = new Scanner(System.in); public static void main (String[] args) throws java.lang.Exception { PrintWriter out = new PrintWriter(System.out); int T=1; for(int t=0;t<T;t++){ int a=Int(); int b=Int(); int k=Int(); Solution sol=new Solution(); sol.solution(out,a,b,k); } out.flush(); } public static long Long(){ return in.nextLong();} public static int Int(){ return in.nextInt(); } public static String Str(){ return in.next(); } } class Solution{ public void solution(PrintWriter out,int a,int b,int k){ //both (a 0) (b 1) //result (k one) if((a==0||b==0)&&(k!=0)){ System.out.println("NO"); return; } if(b==1){ if(k==0){ System.out.println("YES"); StringBuilder s1=new StringBuilder(); for(int i=0;i<b;i++)s1.append("1"); for(int i=0;i<a;i++)s1.append("0"); System.out.println(s1.toString()); System.out.println(s1.toString()); } else{ System.out.println("NO"); } return; } if(a+b-2<k){ System.out.println("NO"); return; } char A[]=new char[a+b]; char B[]=new char[a+b]; Arrays.fill(A,'0'); Arrays.fill(B,'0'); for(int i=0;i<b;i++){ A[i]='1'; B[i]='1'; } if(a>=k){ int cnt=0; B[b-1]='0'; for(int i=b-1;i<B.length;i++){ if(cnt==k){ B[i]='1'; break; } cnt++; } } else{ B[B.length-1]='1'; k-=a; for(int i=b-2;i>=1;i--){ k--; if(k==0){ B[i]='0'; break; } } } System.out.println("YES"); System.out.println(new String(A)); System.out.println(new String(B)); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
0e0361bb2015e6f6dd7dbef3b1f80fc1
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; import java.math.*; public class cf { static PrintWriter pw = new PrintWriter(System.out); static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws IOException, InterruptedException { int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt(); if ((k != 0 && (b == 1 || a == 0 || k >= a + b - 1))) { pw.println("NO"); } else { StringBuilder s1 = new StringBuilder(); StringBuilder s2 = new StringBuilder(); if (k != 0) { s1.append(1); s2.append(1); s1.append(1); s2.append(0); a--; b -= 2; for (int i = 0; i < k - 1; i++) { if (a == 0) { s1.append(1); s2.append(1); b--; } else { s1.append(0); s2.append(0); a--; } } s1.append(0); s2.append(1); } while (b-- > 0) { s1.append(1); s2.append(1); } while (a-- > 0) { s1.append(0); s2.append(0); } pw.println("YES" + '\n' + s1 + '\n' + s2); } pw.close(); } public static class pair implements Comparable<pair> { int x; int y; public pair(int x, int y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } public static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) return this.z - other.z; return this.y - other.y; } else { return this.x - other.x; } } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
2ae63da8d8f77fdedd03383bc95d0110
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
/******************************************************************************* * author : dante1 * created : 23/02/2021 14:35 *******************************************************************************/ import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; // import java.math.BigInteger; import java.util.*; public class d { public static void main(String[] args) { int T = 1; TEST: while (T-- > 0) { int z = in.nextInt(), o = in.nextInt(), k = in.nextInt(); if (k > 0 && (z == 0 || o == 1 || o+z-2 < k)) { out.println("No"); continue TEST; } out.println("YES"); char[] s = new char[o+z]; int i = 0; for (int c = 1; c <= o; c++) s[i++] = '1'; for (int c = 1; c <= z; c++) s[i++] = '0'; print(s); int long_shift = Math.min(z, k), one_shift = Math.max(0, k-z); swap(s, o - 1, o - 1 + long_shift); i = o - 2; while (one_shift-- > 0) { s[i+1] = s[i]; if (one_shift == 0) { s[i] = '0'; } i--; } print(s); } out.flush(); } static void swap(char[] a, int i, int j) { char temp = a[i]; a[i] = a[j]; a[j] = temp; } static void print(char[] s) { for (char c : s) { out.print(c); } out.println(); } // Handle I/O static int MOD = (int) (1e9 + 7); static FastScanner in = new FastScanner(); static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); st = null; } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readIntArray(int size) { int[] arr = new int[size]; for (int i = 0; i < size; i++) { arr[i] = nextInt(); } return arr; } long nextLong() { return Long.parseLong(next()); } long[] readLongArray(int size) { long[] arr = new long[size]; for (int i = 0; i < size; i++) { arr[i] = nextLong(); } return arr; } double nextDouble() { return Double.parseDouble(next()); } double[] readDoubleArray(int size) { double[] arr = new double[size]; for (int i = 0; i < size; i++) { arr[i] = nextDouble(); } return arr; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
c2deef11a52c8736b57cc2071321b09f
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
/******************************************************************************* * author : dante1 * created : 23/02/2021 14:35 *******************************************************************************/ import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; // import java.math.BigInteger; import java.util.*; public class d { public static void main(String[] args) { int T = 1; TEST: while (T-- > 0) { int z = in.nextInt(), o = in.nextInt(), k = in.nextInt(); if (k > 0 && (z == 0 || o == 1 || o+z-2 < k)) { out.println("No"); continue TEST; } StringBuilder x = new StringBuilder(); for (int i = 1; i <= o; i++) { x.append("1"); } for (int i = 1; i <= z; i++) { x.append("0"); } char[] y = x.toString().toCharArray(); int lsr = Math.min(z, k), ls1 = Math.max(0, k-z); swap(y, o-1, o-1+lsr); int i = o-2; while (ls1-- > 0) { y[i+1] = y[i]; if (ls1 == 0) { y[i] = '0'; } i--; } out.println("YES"); out.println(x); out.println(String.valueOf(y)); } out.flush(); } static void swap(char[] a, int i, int j) { char temp = a[i]; a[i] = a[j]; a[j] = temp; } // Handle I/O static int MOD = (int) (1e9 + 7); static FastScanner in = new FastScanner(); static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); st = null; } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readIntArray(int size) { int[] arr = new int[size]; for (int i = 0; i < size; i++) { arr[i] = nextInt(); } return arr; } long nextLong() { return Long.parseLong(next()); } long[] readLongArray(int size) { long[] arr = new long[size]; for (int i = 0; i < size; i++) { arr[i] = nextLong(); } return arr; } double nextDouble() { return Double.parseDouble(next()); } double[] readDoubleArray(int size) { double[] arr = new double[size]; for (int i = 0; i < size; i++) { arr[i] = nextDouble(); } return arr; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
0e3e2e361dbb65115b60c4832c2b5521
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.awt.event.MouseAdapter; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; public class Main { public static void main(String[] args) throws Exception { new Main().run(); } static int groups = 0; static int[] fa; static int[] sz; static void init1(int n) { groups = n; fa = new int[n]; for (int i = 1; i < n; ++i) { fa[i] = i; } sz = new int[n]; Arrays.fill(sz, 1); } static int root(int p) { while (p != fa[p]) { fa[p] = fa[fa[p]]; p = fa[p]; } return p; } static void combine(int p, int q) { int i = root(p); int j = root(q); if (i == j) { return; } fa[i] = j; if (sz[i] < sz[j]) { fa[i] = j; sz[j] += sz[i]; } else { fa[j] = i; sz[i] += sz[j]; } groups--; } public static String roundS(double result, int scale) { String fmt = String.format("%%.%df", scale); return String.format(fmt, result); } int[] unique(int a[]) { int p = 1; for (int i = 1; i < a.length; ++i) { if (a[i] != a[i - 1]) { a[p++] = a[i]; } } return Arrays.copyOf(a, p); } public static int bigger(long[] a, long key) { return bigger(a, 0, a.length, key); } public static int bigger(long[] a, int lo, int hi, long key) { while (lo < hi) { int mid = (lo + hi) >>> 1; if (a[mid] > key) { hi = mid; } else { lo = mid + 1; } } return lo; } static int h[]; static int to[]; static int ne[]; static int m = 0; public static void addEdge(int u, int v, int w) { to[++m] = v; ne[m] = h[u]; h[u] = m; } int w[]; int cc = 0; void add(int u, int v, int ww) { to[++cc] = u; w[cc] = ww; ne[cc] = h[v]; h[v] = cc; to[++cc] = v; w[cc] = ww; ne[cc] = h[u]; h[u] = cc; } // List<int[]> li = new ArrayList<>(); // // void go(int j){ // d[j] = l[j] = ++N; // int cd = 0; // for(int i=h[j];i!=0;i= ne[i]){ // int v= to[i]; // if(d[v]==0){ // fa[v] = j; // cd++; // go(v); // l[j] = Math.min(l[j],l[v]); // if(d[j]<=l[v]){ // cut[j] = true; // } // if(d[j]<l[v]){ // int ma = Math.max(j,v); // int mi = Math.min(j,v); // li.add(new int[]{mi,ma}); // } // }else if(fa[j]!=v){ // l[j] = Math.min(l[j],d[v]); // } // } // if(fa[j]==-1&&cd==1){ // cut[j] = false; // } // if (l[j] == d[j]) { // while(p>0){ // mk[stk[p-1]] = id; // } // id++; // } // } // int mk[]; // int id= 0; // int l[]; // boolean cut[]; // int p = 0; // int d[];int N = 0; // int stk[]; static class S { int l = 0; int r = 0; int miss = 0; int cnt = 0; int c = 0; public S(int l, int r) { this.l = l; this.r = r; } } static S a[]; static int[] o; static void init11(int[] f) { o = f; int len = o.length; a = new S[len * 4]; build1(1, 0, len - 1); } static void build1(int num, int l, int r) { S cur = new S(l, r); if (l == r) { cur.c = o[l]; a[num] = cur; return; } else { int m = (l + r) >> 1; int le = num << 1; int ri = le | 1; build1(le, l, m); build1(ri, m + 1, r); a[num] = cur; pushup(num, le, ri); } } static int query1(int num, int l, int r) { if (a[num].l >= l && a[num].r <= r) { return a[num].c; } else { int m = (a[num].l + a[num].r) >> 1; int le = num << 1; int ri = le | 1; int mi = -1; if (r > m) { int res = query1(ri, l, r); mi = Math.max(mi, res); } if (l <= m) { int res = query1(le, l, r); mi = Math.max(mi, res); } return mi; } } static void pushup(int num, int le, int ri) { a[num].c = Math.max(a[le].c, a[ri].c); } // int root[] = new int[10000]; // // void dfs(int j) { // // clr[j] = 1; // // for (int i = h[j]; i != 0; i = ne[i]) { // int v = to[i]; // dfs(v); // } // for (Object go : qr[j]) { // int g = (int) go; // int id1 = qs[g][0]; // int id2 = qs[g][1]; // int ck; // if (id1 == j) { // ck = id2; // } else { // ck = id1; // } // // if (clr[ck] == 0) { // continue; // } else if (clr[ck] == 1) { // qs[g][2] = ck; // } else { // qs[g][2] = root(ck); // } // } // root[j] = fa[j]; // // clr[j] = 2; // } int clr[]; List[] qr; int qs[][]; int rr = 100; LinkedList<Integer> cao; void df(int n,LinkedList<Integer> li){ int sz = li.size(); if(sz>=rr||sz>=11) return; int v = li.getLast(); if(v==n){ cao = new LinkedList<>(li); rr = sz; return; } List<Integer> res = new ArrayList<>(li); Collections.reverse(res); for(int u:res){ for(int vv:res){ if(u+vv>v&&u+vv<=n){ li.addLast(u+vv); df(n,li); li.removeLast(); }else if(u+vv>n){break;} } } } Random rd = new Random(1274873); static long mul(long a, long b, long p) { long res=0,base=a; while(b>0) { if((b&1L)>0) res=(res+base)%p; base=(base+base)%p; b>>=1; } return res; } static long mod_pow(long k,long n,long p){ long res = 1L; long temp = k%p; while(n!=0L){ if((n&1L)==1L){ res = mul(res,temp,p); } temp = mul(temp,temp,p); n = n>>1L; } return res%p; } long gen(long x){ while(true) { long f = rd.nextLong()%x; if (f >=1 &&f<=x-1) { return f; } } } boolean robin_miller(long x){ if(x==1) return false; if(x==2) return true; if(x==3) return true; if((x&1)==0) return false; long y = x%6; if(y==1||y==5){ long ck = x-1; while((ck&1)==0) ck>>>=1; long as[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; for(int i=0;i<as.length;++i){ long a = as[i]; long ck1= ck; a = mod_pow(a,ck1,x); while(ck1<x){ y = mod_pow(a,2, x); if (y == 1 && a != 1 && a != x - 1) return false; a = y; ck1 = ck1<<1; } if (a != 1) return false; } return true; }else{ return false; } } long inv(long a, long MOD) { //return fpow(a, MOD-2, MOD); return a==1?1:(long )(MOD-MOD/a)*inv(MOD%a, MOD)%MOD; } long C(long n,long m, long MOD) { if(m+m>n)m=n-m; long up=1,down=1; for(long i=0;i<m;i++) { up=up*(n-i)%MOD; down=down*(i+1)%MOD; } return up*inv(down, MOD)%MOD; } // int g[][] = {{1,2,3},{0,3,4},{0,3},{0,1,2,4},{1,3}}; // int res= 0; // void go(int i,int a[],int x[],boolean ck[]){ // if(i==5){ // int an = 0; // for(int j=0;i<5;++j){ // int id = a[j]; // if(ct[id]>3) continue; // int all =0; // for(int g:g[id]){ // all |= a[g]; // } // if(all&(gz[id])==gz[id]){ // an++; // } // } // if(an>res){ // res = an; // } // return; // } // for(int j=0;j<5;++j){ // if(!ck[j]){ // ck[j] = true; // a[i] = x[j]; // go(i+1,a,x,ck); // ck[j] = false; // } // } // // // } // x = r[0], y = r[1] , gcd(x,y) = r[2] public static long[] ex_gcd(long a,long b){ if(b==0) { return new long[]{1,0,a}; } long []r = ex_gcd(b,a%b); return new long[]{r[1], r[0]-(a/b)*r[1], r[2]}; } void chinese_rm(long m[],long r[]){ long res[] = ex_gcd(m[0],m[1]); long rm = r[1]-r[0]; if(rm%res[2]==0){ } } // void go(int i,int c,int cl[]){ // cl[i] = c; // for(int j=h[i];j!=-1;j=ne[j]){ // int v = to[j]; // if(cl[v]==0){ // go(v,-c,cl); // } // } // // } int go(int rt,int h[],int ne[],int to[],int pa){ int all = 3010; for(int i=h[rt];i!=-1;i=ne[i]){ int v = to[i]; if(v==pa) continue; int ma = 0; for(int j=h[rt];j!=-1;j=ne[j]) { int u = to[j]; if(u==pa) continue; if(u!=v){ int r = 1 + go(u,h,ne,to,rt); ma = Math.max(ma,r); } } all = Math.min(all,ma); } if(all==3010||all==0) return 1; return all; } boolean next_perm(int[] a){ int len = a.length; for(int i=len-2,j = 0;i>=0;--i){ if(a[i]<a[i+1]){ j = len-1; for(;a[j]<=a[i];--j); int p = a[j]; a[j] = a[i]; a[i] = p; j = i+1; for(int ed = len-1;j<ed;--ed) { p = a[ed]; a[ed] = a[j]; a[j++] = p; } return true; } } return false; } boolean ok = false; void ck(int[] d,int l,String a,String b,String c,int n,boolean chose[],int add){ if(ok) return; if(l==-1){ if(add==0) { for (int u : d) { print(u + " "); } ok = true; } return; } int i1 = a.charAt(l)-'A'; int i2 = b.charAt(l)-'A'; int i3 = c.charAt(l)-'A'; if(d[i1]==-1&&d[i2]==-1) { if(i1==i2){ for (int i = n-1; i >=0; --i) { if (chose[i]) continue; int s = (i + i + add); int w = s % n; if (d[i3] != -1 && d[i3] != w) continue; if (chose[w] && d[i3] != w) continue; if (w == i && i3 != i2) continue; boolean hsw = d[i3]==w; chose[w] = true; chose[i] = true; d[i1] = i; d[i2] = i; d[i3] = w; int nadd = s/n; ck(d, l-1,a,b,c,n,chose,nadd); d[i1] = -1; d[i2] = -1; if(!hsw) { d[i3] = -1; chose[w] = false; } chose[i] = false; } }else { for (int i = n-1; i >=0; --i) { if (chose[i]) continue; chose[i] = true; d[i1] = i; for (int j = n-1; j >=0; --j) { if (chose[j]) continue; int s = (i + j + add); int w = s % n; if (d[i3] != -1 && d[i3] != w) continue; if (chose[w] && d[i3] != w) continue; if (w == j && i3 != i2) continue; if (w == i && i3 != i1) continue; boolean hsw = d[i3] == w; chose[w] = true; chose[j] = true; d[i2] = j; d[i3] = w; int nadd = s / n; ck(d, l - 1, a, b, c, n, chose, nadd); d[i2] = -1; if (!hsw) { d[i3] = -1; chose[w] = false; } chose[j] = false; } chose[i] = false; d[i1] = -1; } } }else if(d[i1]==-1){ if(d[i3]==-1) { for (int i = n - 1; i >= 0; --i) { if (chose[i]) continue; int s = (i + d[i2] + add); int w = s % n; if (d[i3] != -1 && d[i3] != w) continue; if (chose[w] && d[i3] != w) continue; if (w == i && i3 != i1) continue; if (w == d[i2] && i3 != i2) continue; boolean hsw = d[i3] == w; chose[i] = true; chose[w] = false; d[i1] = i; d[i3] = w; int nadd = s / n; ck(d, l - 1, a, b, c, n, chose, nadd); d[i1] = -1; if (!hsw) { d[i3] = -1; chose[w] = false; } chose[i] = false; } }else{ int s = d[i3]-add-d[i2]; int nadd = 0; if(s<0){ s += n; nadd = 1; } if(chose[s]) return; chose[s] = true; d[i1] = s; ck(d, l - 1, a, b, c, n, chose, nadd); chose[s] = false; d[i1] = -1; } }else if(d[i2]==-1){ if(d[i3]==-1) { for (int i = n - 1; i >= 0; --i) { if (chose[i]) continue; int s = (i + d[i1] + add); int w = s % n; // if (d[i3] != -1 && d[i3] != w) continue; if (chose[w] && d[i3] != w) continue; if (w == i && i3 != i2) continue; if (w == d[i1] && i3 != i1) continue; boolean hsw = d[i3] == w; chose[i] = true; chose[w] = true; d[i2] = i; d[i3] = w; int nadd = s / n; ck(d, l - 1, a, b, c, n, chose, nadd); d[i2] = -1; if (!hsw) { d[i3] = -1; chose[w] = false; } chose[i] = false; } }else{ int s = d[i3]-add-d[i1]; int nadd = 0; if(s<0){ s += n; nadd = 1; } if(chose[s]) return; chose[s] = true; d[i2] = s; ck(d, l - 1, a, b, c, n, chose, nadd); chose[s] = false; d[i2] = -1; } }else{ if(d[i3]==-1){ int w =(d[i1]+d[i2]+add); int nadd = w/n; w %= n; if(w==d[i2]&&i3!=i2) return; if(w==d[i1]&&i3!=i1) return; if(chose[w]) return; d[i3] = w; chose[d[i3]] = true; ck(d, l - 1, a, b, c, n, chose, nadd); chose[d[i3]] = false; d[i3] = -1; }else{ int w = d[i1]+d[i2]+add; int nadd = w/n; if(d[i3]==w%n){ ck(d, l - 1, a, b, c, n, chose, nadd); }else{ return; } } } } int d[][] ; void go(int rt,int h[],int ne[],int[] to){ d[rt][1] = 1; for(int i=h[rt];i!=-1;i = ne[i]){ go(to[i],h,ne,to); d[rt][1] += Math.min(d[to[i]][1],d[to[i]][0]); d[rt][0] += d[to[i]][1]; } } void solve() { int n = ni(); int m = ni(); int k = ni(); if(k==0){ out.println("YES"); for(int i=0;i<m;++i){ out.print(1); } for(int i=0;i<n;++i){ out.print(0); } out.println(); for(int i=0;i<m;++i){ out.print(1); } for(int i=0;i<n;++i){ out.print(0); } out.println(); return; } if(n==0){ out.println("NO"); return; } if(m==1){ out.println("NO"); return; } if(k>n+m-2){ out.print("NO"); return; } out.println("YES"); for(int i=0;i<m;++i){ out.print(1); } for(int i=0;i<n;++i){ out.print(0); } out.println(); if(k<=n){ for(int i=0;i<m-1;++i){ out.print(1); } int sy = n-k; for(int i=0;i<k;++i) { out.print(0); } out.print(1); for(int i=0;i<sy;++i) { out.print(0); } return; }else{ out.print(1); int oo = n+m-k-2; for(int i=0;i<oo;++i){ out.print(1); } out.print(0); m -= oo; for(int i=0;i<m-2;++i){ out.print(1); } for(int i=0;i<n-1;++i){ out.print(0); } out.println(1); } // n >=2 // int n = ni(); // int p = ni(); // // int h[] = new int[n+1]; // Arrays.fill(h,-1); // int to[] = new int[2*n+5]; // int ne[] = new int[2*n+5]; // int ct = 0; // // for(int i=0;i<p;i++){ // int x = ni(); // int y = ni(); // to[ct] = x; // ne[ct] = h[y]; // h[y] = ct++; // // to[ct] = y; // ne[ct] = h[x]; // h[x] = ct++; // // } // // println(go(1,h,ne,to,-1)); // int n= ni(); // //int m = ni(); // int l = 2*n; // // String s[] = new String[2*n+1]; // // long a[] = new long[2*n+1]; // for(int i=1;i<=n;++i){ // s[i] = ns(); // s[i+n] = s[i]; // a[i] = ni(); // a[i+n] = a[i]; // } // // long dp[][] = new long[l+1][l+1]; // long dp1[][] = new long[l+1][l+1]; // // for(int i = l;i>=1;--i) { // // Arrays.fill(dp[i],-1000000000); // Arrays.fill(dp1[i],1000000000); // } // // for(int i = l;i>=1;--i) { // dp[i][i] = a[i]; // dp1[i][i] = a[i]; // } // // // // for(int i = l;i>=1;--i) { // // for (int j = i+1; j <= l&&j-i+1<=n; ++j) { // // // for(int e=i;e<j;++e){ // if(s[e+1].equals("t")){ // dp[i][j] = Math.max(dp[i][j], dp[i][e]+dp[e+1][j]); // dp1[i][j] = Math.min(dp1[i][j], dp1[i][e]+dp1[e+1][j]); // }else{ // // long f[] = {dp[i][e]*dp[e+1][j],dp1[i][e]*dp1[e+1][j],dp[i][e]*dp1[e+1][j],dp1[i][e]*dp[e+1][j]}; // // for(long u:f) { // dp[i][j] = Math.max(dp[i][j], u); // dp1[i][j] = Math.min(dp1[i][j], u); // } // } // // // } // // } // } // long ma = -100000000; // List<Integer> li = new ArrayList<>(); // for (int j = 1; j <= n; ++j) { // if(dp[j][j+n-1]==ma){ // li.add(j); // }else if(dp[j][j+n-1]>ma){ // ma = dp[j][j+n-1]; // li.clear(); // li.add(j); // } // // } // println(ma); // for(int u:li){ // print(u+" "); // } // println(); // println(get(490)); // int num =1; // while(true) { // int n = ni(); // int m = ni(); // if(n==0&&m==0) break; // int p[] = new int[n]; // int d[] = new int[n]; // for(int j=0;j<n;++j){ // p[j] = ni(); // d[j] = ni(); // } // int dp[][] = new int[8001][22]; // int choose[][] = new int[8001][22]; // // for(int v=0;v<=8000;++v){ // for(int u=0;u<=21;++u) { // dp[v][u] = -100000; // choose[v][u] =-1; // } // } // dp[4000][0] = 0; // // for(int j=0;j<n;++j){ // for(int g = m-1 ;g>=0; --g){ // if(p[j] - d[j]>=0) { // for (int v = 4000; v >= -4000; --v) { // if (v + 4000 + p[j] - d[j] >= 0 && v + 4000 + p[j] - d[j] <= 8000 && dp[v + 4000][g] >= 0) { // int ck1 = dp[v + 4000 + p[j] - d[j]][g + 1]; // if (ck1 < dp[v + 4000][g] + p[j] + d[j]) { // dp[v + 4000 + p[j] - d[j]][g + 1] = dp[v + 4000][g] + p[j] + d[j]; // choose[v + 4000 + p[j] - d[j]][g + 1] = j; // } // } // // } // }else{ // for (int v = -4000; v <= 4000; ++v) { // if (v + 4000 + p[j] - d[j] >= 0 && v + 4000 + p[j] - d[j] <= 8000 && dp[v + 4000][g] >= 0) { // int ck1 = dp[v + 4000 + p[j] - d[j]][g + 1]; // if (ck1 < dp[v + 4000][g] + p[j] + d[j]) { // dp[v + 4000 + p[j] - d[j]][g + 1] = dp[v + 4000][g] + p[j] + d[j]; // choose[v + 4000 + p[j] - d[j]][g + 1] = j; // } // } // // } // // // // // // } // } // } // int big = 0; // int st = 0; // boolean ok = false; // for(int v=0;v<=4000;++v){ // int v1 = -v; // if(dp[v+4000][m]>0){ // big = dp[v+4000][m]; // st = v+4000; // ok = true; // } // if(dp[v1+4000][m]>0&&dp[v1+4000][m]>big){ // big = dp[v1+4000][m]; // st = v1+4000; // ok = true; // } // if(ok){ // break; // } // } // int f = 0; // int s = 0; // List<Integer> res = new ArrayList<>(); // while(choose[st][m]!=-1){ // int j = choose[st][m]; // res.add(j+1); // f += p[j]; // s += d[j]; // st -= p[j]-d[j]; // m--; // } // Collections.sort(res); // println("Jury #"+num); // println("Best jury has value " + f + " for prosecution and value " + s + " for defence:"); // for(int u=0;u<res.size();++u){ // print(" "); // print(res.get(u)); // } // println(); // println(); // num++; // } // int n = ni(); // int m = ni(); // // int dp[][] = new int[n][4]; // // for(int i=0;i<n;++i){ // for(int j=0;j<m;++j){ // for(int c = 0;c<4;++c){ // if(c==0){ // dp[i][j][] = // } // } // } // } } static void pushdown(int num, int le, int ri) { } long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } InputStream is; PrintWriter out; void run() throws Exception { is = System.in; out = new PrintWriter(System.out); solve(); out.flush(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private char ncc() { int b = readByte(); return (char) b; } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private String nline() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b) || b == ' ') { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[][] nm(int n, int m) { char[][] a = new char[n][]; for (int i = 0; i < n; i++) a[i] = ns(m); return a; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private long[] nal(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) { } ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0'); else return minus ? -num : num; b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) { } ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') num = num * 10 + (b - '0'); else return minus ? -num : num; b = readByte(); } } void print(Object obj) { out.print(obj); } void println(Object obj) { out.println(obj); } void println() { out.println(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
bff8b96bd9072def996d81f918f2f958
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.InputMismatchException; import java.util.*; import java.io.*; import java.lang.*; public class Main{ public static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static long gcd(long a, long b){ if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a*b)/gcd(a, b); } public static void sortbyColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } static long func(long a[],int size,int s){ long max1=a[s]; long maxc=a[s]; for(int i=s+1;i<size;i++){ maxc=Math.max(a[i],maxc+a[i]); max1=Math.max(maxc,max1); } return max1; } public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> { public U x; public V y; public Pair(U x, V y) { this.x = x; this.y = y; } public int hashCode() { return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode()); } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<U, V> p = (Pair<U, V>) o; return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y)); } public int compareTo(Pair<U, V> b) { int cmpU = x.compareTo(b.x); return cmpU != 0 ? cmpU : y.compareTo(b.y); } public String toString() { return String.format("(%s, %s)", x.toString(), y.toString()); } } static class MultiSet<U extends Comparable<U>> { public int sz = 0; public TreeMap<U, Integer> t; public MultiSet() { t = new TreeMap<>(); } public void add(U x) { t.put(x, t.getOrDefault(x, 0) + 1); sz++; } public void remove(U x) { if (t.get(x) == 1) t.remove(x); else t.put(x, t.get(x) - 1); sz--; } } static void shuffle(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } } static long myceil(long a, long b){ return (a+b-1)/b; } static long C(long n,long r){ long count=0,temp=n; long ans=1; long num=n-r+1,div=1; while(num<=n){ ans*=num; //ans+=MOD; ans%=MOD; ans*=mypow(div,MOD-2); //ans+=MOD; ans%=MOD; num++; div++; } ans+=MOD; return ans%MOD; } static long fact(long a){ long i,ans=1; for(i=1;i<=a;i++){ ans*=i; ans%=MOD; } return ans%=MOD; } static void sieve(int n){ is_sieve[0]=1; is_sieve[1]=1; int i,j,k; for(i=2;i<n;i++){ if(is_sieve[i]==0){ sieve[i]=i; tr.add(i); for(j=i*i;j<n;j+=i){ if(j>n||j<0){ break; } is_sieve[j]=1; sieve[j]=i; } } } } static void calc(int n){ int i,j; dp[n-1]=0; if(n>1) dp[n-2]=1; for(i=n-3;i>=0;i--){ long ind=n-i-1; dp[i]=((ind*(long)mypow(10,ind-1))%MOD+dp[i+1])%MOD; } } static long mypow(long x,long y){ long temp; if( y == 0) return 1; temp = mypow(x, y/2); if (y%2 == 0) return (temp*temp)%MOD; else return ((x*temp)%MOD*(temp)%MOD)%MOD; } static long dist[],dp[]; static int visited[]; static ArrayList<Pair<Integer,String>> adj[]; //static int dp[][][]; static int R,G,B,MOD=1000000007; static int[] par,size,memo; static int[] sieve,is_sieve; static TreeSet<Integer> tr; static char ch[][], ch1[][]; // static void lengen(int arr[],int ind){ // memo[ind]=Math.max(lengen(arr,ind+1),lis(arr,)) // } static int lis(int arr[],int n,int ind,int cur){ if(ind>=n){ return memo[ind]=0; } else if(ind>=0&&memo[ind]>-1){ return memo[ind]; } else if(cur<arr[ind+1]){ return memo[ind]=Math.max(lis(arr,n,ind+1,arr[ind+1])+1,lis(arr,n,ind+1,cur)); }else{ return memo[ind]=lis(arr,n,ind+1,cur); } } public static void main(String args[]){ InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter w = new PrintWriter(outputStream); int t,i,j,tno=0,tte; //t=in.nextInt(); t=1; //tte=t; while(t-->0){ long a,b,k; a=in.nextLong(); b=in.nextLong(); k=in.nextLong(); if((a+b-2>=0&&k>a+b-2)||(b==1&&k>0)||(a==0&&k>0)){ w.println("No"); continue; } w.println("Yes"); for(i=0;i<b;i++){ w.print(1); } for(i=0;i<a;i++){ w.print(0); } w.println(); if(k<=a){ for(i=0;i<b-1;i++){ w.print(1); } for(i=0;i<a+1;i++){ if(i==k){ w.print(1); }else{ w.print(0); } } }else{ long x=k-a; for(i=0;i<b;i++){ if(i==b-x-1){ w.print(0); }else{ w.print(1); } } for(i=0;i<a-1;i++){ w.print(0); } w.print(1); } w.println(); } w.close(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
9a102b56775db47238b6a639659abe8a
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.math.BigInteger; //import javafx.util.*; public final class B { static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); static ArrayList<ArrayList<Integer>> g,lang; static long mod=1000000007; static int D1[],D2[],par[]; static boolean set[]; public static void main(String args[])throws IOException { int a=i(),b=i(),k=i(); if(a==0 || b==1) { if(k==0) { System.out.println("YES"); for(int i=0; i<b; i++)System.out.print(1); for(int i=0; i<a; i++)System.out.print(0); System.out.println(); for(int i=0; i<b; i++)System.out.print(1); for(int i=0; i<a; i++)System.out.print(0); System.out.println(); } else System.out.println("NO"); return; } if(k>a+b-2) { System.out.println("NO"); return; } int X[]=new int[a+b]; int Y[]=new int[a+b]; for(int i=0; i<b; i++) { X[i]=1; Y[i]=1; } for(int i=b; i<a+b; i++) { X[i]=0; Y[i]=0; } int cnt=0; int last=b-1; while(cnt<Math.min(k, a)) { swap(Y,last,last+1); last++; cnt++; } last=b-2; for(int i=cnt; i<k; i++) { swap(Y,last,last+1); last--; } ans.append("YES\n"); for(int i:X)ans.append(i); ans.append("\n"); for(int i:Y)ans.append(i); ans.append("\n"); System.out.println(ans); } static void swap(int X[],int a,int b) { int t=X[a]; X[a]=X[b]; X[b]=t; } static long min(long a,long b,long c) { return Math.min(a, Math.min(c, b)); } static void dfs(int n) { set[n]=true; for(int c:g.get(n)) { if(!set[c])dfs(c); } } static void print(int a) { System.out.println("! "+a); } static int ask(int a,int b) { System.out.println("? "+a+" "+b); return i(); } static int find(int a) { if(par[a]<0)return a; return par[a]=find(par[a]); } static void union(int a,int b) { a=find(a); b=find(b); if(a!=b) { par[a]+=par[b]; //transfers the size par[b]=a; //changes the parent } } static ArrayList<Integer> IND(int B[],HashMap<Integer,Integer> mp) { ArrayList<Integer> A=new ArrayList<>(); for(int i:B) { if(mp.containsKey(i)) { A.add(i); int f=mp.get(i)-1; if(f==0) mp.remove(i); else mp.put(i, f); } } return A; } static HashMap<Integer,Integer> hash(int A[],int index) { HashMap<Integer,Integer> mp=new HashMap<Integer,Integer>(); for(int i=index; i<A.length; i++) { int f=mp.getOrDefault(A[i], 0)+1; mp.put(A[i], f); } return mp; } static void swap(char A[],int a,int b) { char ch=A[a]; A[a]=A[b]; A[b]=ch; } static long lower_Bound(long A[],int low,int high, long x) { if (low > high) if (x >= A[high]) return A[high]; int mid = (low + high) / 2; if (A[mid] == x) return A[mid]; if (mid > 0 && A[mid - 1] <= x && x < A[mid]) return A[mid - 1]; if (x < A[mid]) return lower_Bound( A, low, mid - 1, x); return lower_Bound(A, mid + 1, high, x); } static void sort(long[] a) //check for long { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void setGraph(int N) { set=new boolean[N+1]; //size=new int[N+1]; //par=new int[N+1]; g=new ArrayList<ArrayList<Integer>>(); lang=new ArrayList<ArrayList<Integer>>(); //tg=new ArrayList<ArrayList<Integer>>(); for(int i=0; i<=N; i++) { g.add(new ArrayList<Integer>()); lang.add(new ArrayList<Integer>()); //tg.add(new ArrayList<Integer>()); } } static long pow(long a,long b) { long mod=1000000007; long pow=1; long x=a; while(b!=0) { if((b&1)!=0)pow=(pow*x)%mod; x=(x*x)%mod; b/=2; } return pow; } static long toggleBits(long x)//one's complement || Toggle bits { int n=(int)(Math.floor(Math.log(x)/Math.log(2)))+1; return ((1<<n)-1)^x; } static int countBits(long a) { return (int)(Math.log(a)/Math.log(2)+1); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static boolean isPrime(long N) { if (N<=1) return false; if (N<=3) return true; if (N%2 == 0 || N%3 == 0) return false; for (int i=5; i*i<=N; i=i+6) if (N%i == 0 || N%(i+2) == 0) return false; return true; } static long GCD(long a,long b) { if(b==0) { return a; } else return GCD(b,a%b ); } //Debugging Functions Starts static void print(char A[]) { for(char c:A)System.out.print(c+" "); System.out.println(); } static void print(boolean A[]) { for(boolean c:A)System.out.print(c+" "); System.out.println(); } static void print(int A[]) { for(int a:A)System.out.print(a+" "); System.out.println(); } static void print(long A[]) { for(long i:A)System.out.print(i+ " "); System.out.println(); } static void print(ArrayList<Integer> A) { for(int a:A)System.out.print(a+" "); System.out.println(); } //Debugging Functions END //---------------------- //IO FUNCTIONS STARTS static HashMap<Integer,Integer> Hash(int A[]) { HashMap<Integer,Integer> mp=new HashMap<>(); for(int a:A) { int f=mp.getOrDefault(a,0)+1; mp.put(a, f); } return mp; } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i<N; i++) { A[i]=in.nextInt(); } return A; } static long[] inputLong(int N) { long A[]=new long[N]; for(int i=0; i<A.length; i++)A[i]=in.nextLong(); return A; } //IO FUNCTIONS END } //Code For FastReader //Code For FastReader //Code For FastReader //Code For FastReader class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(st==null || !st.hasMoreElements()) { try { st=new StringTokenizer(br.readLine()); } catch(IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""; try { str=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
f7253f95ae5347ecbffc2e7f17d6cd29
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class Main{ public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); solve(in, out); out.close(); } static int L,R,top,bottom; static int cnt,edge; public static void solve(InputReader sc, PrintWriter pw) { // int t=sc.nextInt(); int t=1; u:while(t-->0){ int a,b,k; a=sc.nextInt(); b=sc.nextInt(); k=sc.nextInt(); char[] chrr=new char[a+b]; for(int i=0;i<b;i++) chrr[i]='1'; for(int i=b;i<a+b;i++) chrr[i]='0'; String s; if(a==0||b==1){ if(k>0) pw.println("No"); else{ pw.println("Yes"); s=new String(chrr); pw.println(s); pw.println(s); } continue; } if(k>a+b-2){ pw.println("No"); continue; } pw.println("Yes"); s=new String(chrr); pw.println(s); chrr[b-1-(Math.max(k,a)-a)]='0'; chrr[b-1+Math.min(k,a)]='1'; s=new String(chrr); pw.println(s); } } public static long find_val(long n){ char[] chrr=(""+n).toCharArray(); Arrays.sort(chrr); return Long.parseLong(new StringBuilder(new String(chrr)).reverse().toString())-Long.parseLong(new String(chrr)); } public static int ask(int l, int r, InputReader sc){ System.out.println("? "+l+" "+r); System.out.flush(); return sc.nextInt(); } public static void sort(long []arr){ ArrayList<Long> list=new ArrayList<>(); for(int i=0;i<arr.length;i++) list.add(arr[i]); Collections.sort(list); for(int i=0;i<arr.length;i++) arr[i]=list.get(i); } public static void swap(char []chrr, int i, int j){ char temp=chrr[i]; chrr[i]=chrr[j]; chrr[j]=temp; } public static int num(int n){ int a=0; while(n>0){ a+=(n&1); n>>=1; } return a; } static class Pair{ int a, b; Pair(int a,int b){ this.a=a; this.b=b; } //* } /*/ public int compareTo(Pair p){ return (b-p.b); } public int hashCode(){ int hashcode = (a+" "+b).hashCode(); return hashcode; } public boolean equals(Object obj){ if (obj instanceof Pair) { Pair p = (Pair) obj; return (p.a==this.a && p.b == this.b); } return false; } } //*/ static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static int gcd(int a, int b) { if (b == 0) return a; return a>b?gcd(b, a % b):gcd(a, b % a); } static long fast_pow(long base,long n,long M){ if(n==0) return 1; if(n==1) return base; long halfn=fast_pow(base,n/2,M); if(n%2==0) return ( halfn * halfn ) % M; else return ( ( ( halfn * halfn ) % M ) * base ) % M; } static long modInverse(long n,long M){ return fast_pow(n,M-2,M); } public static void feedArr(long []arr,InputReader sc){ for(int i=0;i<arr.length;i++) arr[i]=sc.nextLong(); } public static void feedArr(double []arr,InputReader sc){ for(int i=0;i<arr.length;i++) arr[i]=sc.nextDouble(); } public static void feedArr(int []arr,InputReader sc){ for(int i=0;i<arr.length;i++) arr[i]=sc.nextInt(); } public static void feedArr(String []arr,InputReader sc){ for(int i=0;i<arr.length;i++) arr[i]=sc.next(); } public static String printArr(int []arr){ StringBuilder sbr=new StringBuilder(); for(int i:arr) sbr.append(i+" "); return sbr.toString(); } public static String printArr(long []arr){ StringBuilder sbr=new StringBuilder(); for(long i:arr) sbr.append(i+" "); return sbr.toString(); } public static String printArr(String []arr){ StringBuilder sbr=new StringBuilder(); for(String i:arr) sbr.append(i+" "); return sbr.toString(); } public static String printArr(double []arr){ StringBuilder sbr=new StringBuilder(); for(double i:arr) sbr.append(i+" "); return sbr.toString(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
c0b0b7f0bc861e55f4cef81523d427fd
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); DGeniussGambit solver = new DGeniussGambit(); solver.solve(1, in, out); out.close(); } static class DGeniussGambit { public void solve(int testNumber, FastReader in, PrintWriter out) { int a = in.nextInt(); int b = in.nextInt(); int k = in.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < b; i++) { sb.append("1"); } for (int i = 0; i < a; i++) { sb.append("0"); } if (k == 0) { out.println("Yes"); out.println(sb.toString()); out.println(sb.toString()); return; } if ((b == 1 || a == 0)) { out.println("No"); return; } if (k > a + b - 2) { out.println("No"); return; } out.println("Yes"); out.println(sb.toString()); int p = b - 1; while (k > 0 && p < a + b - 1) { swap(sb, p); k--; p++; } if (k == 0) { out.println(sb.toString()); return; } p = b - 2; while (p >= 0 && k > 0) { swap(sb, p); p--; k--; } out.println(sb.toString()); } private void swap(StringBuilder sb, int p) { char tmp = sb.charAt(p); sb.setCharAt(p, sb.charAt(p + 1)); sb.setCharAt(p + 1, tmp); } } static class FastReader { BufferedReader br; StringTokenizer st = new StringTokenizer(""); public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } public String next() { while (st == null || (!st.hasMoreElements())) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
c549c6c36db9719254ccd61e6938312b
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.math.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<------------------- public class a{ static long[] count,count1,count2; static boolean[] prime; static Node[] nodes,nodes1,nodes2; static NodeInt[] nodesInt,nodesInt1; static long[] arr; static long[][] cost; static int[] arrInt,darrInt,farrInt; static long[][] dp; static char[] ch,ch1; static long[] darr,farr; static long[][] mat,mat1; static boolean[] vis; static long x,h; static long maxl; static double dec; static long mx = (long)1e7; static long inf = (long)1e15; static String s,s1,s2,s3,s4; static long minl; static long mod = ((long)(1e9))+7; // static int minl = -1; // static long n; static int n,n1,n2,q,r1,c1,r2,c2; static long a; static long b; static long c; static long d; static long y,z; static int m; static int ans; static long k; static FastScanner sc; static String[] str,str1; static Set<Integer> set,set1,set2; static SortedSet<Long> ss; static List<Long> list,list1,list2,list3; static PriorityQueue<Node> pq,pq1; static LinkedList<Node> ll,ll1,ll2; static Map<Integer,List<Integer>> map1; static Map<Long,Integer> map; static StringBuilder sb,sb1,sb2; static int index; static long[] sum; static int[] dx = {0,-1,0,1,-1,1,-1,1}; static int[] dy = {-1,0,1,0,-1,-1,1,1}; // public static void solve(){ // FastScanner sc = new FastScanner(); // // int t = sc.nextInt(); // int t = 1; // for(int tt = 0 ; tt < t ; tt++){ // // s = sc.next(); // // s1 = sc.next(); // n = sc.nextInt(); // m = sc.nextInt(); // // int k = sc.nextInt(); // // sb = new StringBuilder(); // map = new HashMap<>(); // map1 = new HashMap<>(); // // q = sc.nextInt(); // // sb = new StringBuilder(); // // long k = sc.nextLong(); // // ch = sc.next().toCharArray(); // // count = new int[200002]; // // m = sc.nextInt(); // for(int o = 0 ; o < m ; o++){ // int l = sc.nextInt()-1; // int r = sc.nextInt()-1; // } // } // } //--------------->>>>IF YOU ARE HERE FOR QUICKSORT HACK THEN SORRY NO HACK FOR YOU<<<------------------- public static void solve(){ int a = sc.nextInt(); int b = sc.nextInt(); int k = sc.nextInt(); sb = new StringBuilder(); sb1 = new StringBuilder(); int n = a+b; int[] count1 = new int[n]; int[] count2 = new int[n]; for(int i = 0 ; i < b ; i++){ count1[i] = 1; count2[i] = 1; } if(k == 0){ for(int i = 0 ; i < n ; i++){ sb.append(count1[i]); sb1.append(count2[i]); } System.out.println("Yes"); System.out.println(sb); System.out.println(sb1); return; } if(k > (a+b-2) || (b == 0 && k > 0) || (b == 1 && k > 0)){ System.out.println("No"); return; } int shiftBy = Math.min(k,a); count2[b-1] = 0; count2[b-1+shiftBy] = 1; k -= a; int curr = b-2; while(k > 0){ count2[curr] = 0; count2[curr+1] = 1; curr -= 1; k -= 1; } int a1 = 0; int a2 = 0; for(int i = 0 ; i < n ; i++){ sb.append(count1[i]); sb1.append(count2[i]); if(count1[i] == 0) a1 += 1; if(count2[i] == 0) a2 += 1; } if(count1[0] == 0 || count2[0] == 0 || a1 != a || a2 != a){ System.out.println("No"); return; } System.out.println("Yes"); System.out.println(sb); System.out.println(sb1); } public static void main(String[] args) { sc = new FastScanner(); // Scanner sc = new Scanner(System.in); // int t = sc.nextInt(); int t = 1; // int l = 1; while(t > 0){ // n = sc.nextInt(); // n = sc.nextLong(); // k = sc.nextLong(); // x = sc.nextLong(); // y = sc.nextLong(); // z = sc.nextLong(); // a = sc.nextLong(); // b = sc.nextLong(); // c = sc.nextLong(); // d = sc.nextLong(); // x = sc.nextLong(); // y = sc.nextLong(); // z = sc.nextLong(); // d = sc.nextLong(); // n = sc.nextInt(); // n1 = sc.nextInt(); // m = sc.nextInt(); // q = sc.nextInt(); // k = sc.nextLong(); // x = sc.nextLong(); // d = sc.nextLong(); // s = sc.next(); // ch = sc.next().toCharArray(); // ch1 = sc.next().toCharArray(); // n = 6; // arr = new long[n]; // for(int i = 0 ; i < n ; i++){ // arr[i] = sc.nextLong(); // } // arrInt = new int[n]; // for(int i = 0 ; i < n ; i++){ // arrInt[i] = sc.nextInt(); // } // x = sc.nextLong(); // y = sc.nextLong(); // ch = sc.next().toCharArray(); // m = n; // m = sc.nextInt(); // darr = new long[m]; // for(int i = 0 ; i < m ; i++){ // darr[i] = sc.nextLong(); // } // k = sc.nextLong(); // m = n; // darrInt = new int[n]; // for(int i = 0 ; i < n ; i++){ // darrInt[i] = sc.nextInt(); // } // farrInt = new int[m]; // for(int i = 0; i < m ; i++){ // farrInt[i] = sc.nextInt(); // } // m = n; // mat = new long[n][m]; // for(int i = 0 ; i < n ; i++){ // for(int j = 0 ; j < m ; j++){ // mat[i][j] = sc.nextLong(); // } // } // m = n; // mat = new char[n][m]; // for(int i = 0 ; i < n ; i++){ // String s = sc.next(); // for(int j = 0 ; j < m ; j++){ // mat[i][j] = s.charAt(j); // } // } // str = new String[n]; // for(int i = 0 ; i < n ; i++) // str[i] = sc.next(); // nodes = new Node[n]; // for(int i = 0 ; i < n ;i++) // nodes[i] = new Node(sc.nextLong(),sc.nextLong()); // nodesInt = new NodeInt[n]; // for(int i = 0 ; i < n ;i++) // nodesInt[i] = new NodeInt(sc.nextInt(),sc.nextInt(),i); solve(); t -= 1; } } public static int log(long n,long base){ if(n == 0 || n == 1) return 0; if(n == base) return 1; double num = Math.log(n); double den = Math.log(base); if(den == 0) return 0; return (int)(num/den); } public static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static long lcm(long a, long b) { return (b/gcd(b, a % b)) * a; } public static long mod_inverse(long a,long mod){ long x1=1,x2=0; long p=mod,q,t; while(a%p!=0){ q = a/p; t = x1-q*x2; x1=x2; x2=t; t=a%p; a=p; p=t; } return x2<0 ? x2+mod : x2; } public static void swap(long[] curr,int i,int j){ long temp = curr[j]; curr[j] = curr[i]; curr[i] = temp; } static final Random random=new Random(); static void ruffleSortLong(long[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n); long temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static void ruffleSortInt(int[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n); int temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static void ruffleSortChar(char[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n); char temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static long binomialCoeff(long n, long k){ long res = 1; // Since C(n, k) = C(n, n-k) if (k > n - k) k = n - k; // Calculate value of // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] for (long i = 0; i < k; ++i) { res = (res*(n - i)); res = (res/(i + 1)); } return res; } static long[] fact; public static long inv(long n){ return power(n, mod-2); } public static void fact(int n){ fact = new long[n+1]; fact[0] = 1; for(int j = 1;j<=n;j++) fact[j] = (fact[j-1]*(long)j)%mod; } public static long binom(int n, int k){ fact(n+1); long prod = fact[n]; prod*=inv(fact[n-k]); prod%=mod; prod*=inv(fact[k]); prod%=mod; return prod; } static long power(long x, long y){ if (y == 0) return 1; if (y%2 == 1) return (x*power(x, y-1))%mod; return power((x*x)%mod, y/2)%mod; } static void sieve(int n){ prime = new boolean[n+1]; for(int i=2;i<n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } } static class Node{ String first; long second; Node(String f,long s){ this.first = f; this.second = s; } } static class NodeInt{ int first; int second; int third; NodeInt(int f,int s,int third){ this.first = f; this.second = s; this.third = third; } } static long sq(long num){ return num*num; } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
f29587935bc44e11bb1b36ad935b617d
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class Genius_Gambit { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void shuffle(int[] a) { Random r = new Random(); for (int i = 0; i <= a.length - 2; i++) { int j = i + r.nextInt(a.length - i); swap(a, i, j); } Arrays.sort(a); } public static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } public static void main(String[] args) { // TODO Auto-generated method stub FastReader t = new FastReader(); PrintWriter o = new PrintWriter(System.out); int a = t.nextInt(); int b = t.nextInt(); int k = t.nextInt(); boolean flag = true; char[] A = new char[a + b]; char[] B = new char[a + b]; if (k >= 1) { --k; int n = a + b; A[n - 1] = '0'; B[n - 1] = '1'; --a; int i = n - 2; if (a < 0) flag = false; while (k > 0) { if (a > 0) { A[i] = B[i] = '0'; --i; --k; --a; } else if (b > 1) { A[i] = B[i] = '1'; --b; --k; --i; } else { flag = false; break; } } if (flag) { A[i] = '1'; B[i] = '0'; --i; --b; while (a > 0) { A[i] = B[i] = '0'; --i; --a; } while (b > 0) { A[i] = B[i] = '1'; --i; --b; } } if (B[0] != '1') flag = false; if (flag) { o.println("Yes"); o.println(new String(A)); o.println(new String(B)); } else { o.println("No"); } } else { int i = 0; while (i < b) { A[i] = B[i] = '1'; ++i; } while (i < a + b) { A[i] = B[i] = '0'; ++i; } o.println("Yes"); o.println(new String(A)); o.println(new String(B)); } o.flush(); o.close(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
c5e29c0b94b8bfb898735537672e5a18
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class EdB { static long[] mods = {1000000007, 998244353, 1000000009}; static long mod = mods[0]; public static MyScanner sc; public static PrintWriter out; public static void main(String[] omkar) throws Exception{ // TODO Auto-generated method stub sc = new MyScanner(); out = new PrintWriter(System.out); // String input1 = bf.readLine().trim(); // String input2 = bf.readLine().trim(); // COMPARING INTEGER OBJECTS U DO DOT EQUALS NOT == int a = sc.nextInt(); int b = sc.nextInt(); int k = sc.nextInt(); if (a == 0 && k != 0){ out.println("No"); } else if (a == 0){ out.println("Yes"); for(int j = 0;j<a+b;j++){ out.print(1); } out.println(); for(int j = 0;j<a+b;j++){ out.print(1); } out.println(); } else if (b == 1 && k != 0){ out.println("No"); } else if (b == 1){ out.println("Yes"); out.print(1); for(int j = 0;j<a+b-1;j++){ out.print(0); } out.println(); out.print(1); for(int j = 0;j<a+b-1;j++){ out.print(0); } out.println(); } else if (k < a+b-1){ out.println("Yes"); int[] a1 = new int[a+b]; int[] a2 = new int[a+b]; a1[0] = 1; a2[0] = 1; a1[1] = 1; a2[1+k] = 1; int onesleft = b-2; for(int j = 0;j<a+b;j++){ if (onesleft == 0) break; else if (a1[j] == 0 && a2[j] == 0){ onesleft--; a1[j] = 1; a2[j] = 1; } } for(int j = 0;j<a+b;j++){ out.print(a1[j]); } out.println(); for(int j = 0;j<a+b;j++){ out.print(a2[j]); } out.println(); } else{ out.println("No"); } // for(int j = 0;j<array.length;j++){ // out.print(array[j] + " "); // } // out.println(); out.close(); } public static void sort(int[] array){ ArrayList<Integer> copy = new ArrayList<>(); for (int i : array) copy.add(i); Collections.sort(copy); for(int i = 0;i<array.length;i++) array[i] = copy.get(i); } static String[] readArrayString(int n){ String[] array = new String[n]; for(int j =0 ;j<n;j++) array[j] = sc.next(); return array; } static int[] readArrayInt(int n){ int[] array = new int[n]; for(int j = 0;j<n;j++) array[j] = sc.nextInt(); return array; } static int[] readArrayInt1(int n){ int[] array = new int[n+1]; for(int j = 1;j<=n;j++){ array[j] = sc.nextInt(); } return array; } static long[] readArrayLong(int n){ long[] array = new long[n]; for(int j =0 ;j<n;j++) array[j] = sc.nextLong(); return array; } static double[] readArrayDouble(int n){ double[] array = new double[n]; for(int j =0 ;j<n;j++) array[j] = sc.nextDouble(); return array; } static int minIndex(int[] array){ int minValue = Integer.MAX_VALUE; int minIndex = -1; for(int j = 0;j<array.length;j++){ if (array[j] < minValue){ minValue = array[j]; minIndex = j; } } return minIndex; } static int minIndex(long[] array){ long minValue = Long.MAX_VALUE; int minIndex = -1; for(int j = 0;j<array.length;j++){ if (array[j] < minValue){ minValue = array[j]; minIndex = j; } } return minIndex; } static int minIndex(double[] array){ double minValue = Double.MAX_VALUE; int minIndex = -1; for(int j = 0;j<array.length;j++){ if (array[j] < minValue){ minValue = array[j]; minIndex = j; } } return minIndex; } static long power(long x, long y){ if (y == 0) return 1; if (y%2 == 1) return (x*power(x, y-1))%mod; return power((x*x)%mod, y/2)%mod; } static void verdict(boolean a){ out.println(a ? "YES" : "NO"); } public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } } //StringJoiner sj = new StringJoiner(" "); //sj.add(strings) //sj.toString() gives string of those stuff w spaces or whatever that sequence is
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
96ceaf65cc8b61aa36542bf080f5c336
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; import java.util.function.BinaryOperator; import java.util.stream.Collectors; public class Main { private final static long mod = 1000000007; private final static int MAXN = 1000001; private static long power(long x, long y, long m) { long temp; if (y == 0) return 1; temp = power(x, y / 2, m); temp = (temp * temp) % m; if (y % 2 == 0) return temp; else return ((x % m) * temp) % m; } private static long power(long x, long y) { return power(x, y, mod); } public int solve(int[] nums) { Map<Pair<Integer,Integer>,Integer>dp=new HashMap<>(); int ans=0; for(int i=1;i<nums.length;i++){ for(int j=i+1;j<nums.length;j++) { Pair<Integer,Integer>prev=new Pair<>(nums[j]-nums[i],nums[i]); Integer v=dp.get(prev); Pair<Integer,Integer>curr=new Pair<>(nums[i],nums[j]); if(v!=null){ dp.put(curr,Math.max(dp.get(prev),v+1)); } else { dp.put(curr, 2); } ans=Math.max(ans,dp.get(curr)); } } return ans; } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static int nextPowerOf2(int a) { return 1 << nextLog2(a); } static int nextLog2(int a) { return (a == 0 ? 0 : 32 - Integer.numberOfLeadingZeros(a - 1)); } private static long modInverse(long a, long m) { long m0 = m; long y = 0, x = 1; if (m == 1) return 0; while (a > 1) { long q = a / m; long t = m; m = a % m; a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } private static int[] getLogArr(int n) { int arr[] = new int[n + 1]; for (int i = 1; i < n + 1; i++) { arr[i] = (int) (Math.log(i) / Math.log(2) + 1e-10); } return arr; } private static int log[] = getLogArr(MAXN); private static long getLRSpt(long st[][], int L, int R, BinaryOperator<Long> binaryOperator) { int j = log[R - L + 1]; return binaryOperator.apply(st[L][j], st[R - (1 << j) + 1][j]); } private static long[][] getSparseTable(int array[], BinaryOperator<Long> binaryOperator) { int k = log[array.length + 1] + 1; long st[][] = new long[array.length + 1][k + 1]; for (int i = 0; i < array.length; i++) st[i][0] = array[i]; for (int j = 1; j <= k; j++) { for (int i = 0; i + (1 << j) <= array.length; i++) { st[i][j] = binaryOperator.apply(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]); } } return st; } private static long getULDRSpt(long st[][][][], int U, int L,int D, int R, BinaryOperator<Long> binaryOperator) { int k = log[D - U + 1]; int l = log[R - L + 1]; long a= binaryOperator.apply(st[U][L][k][l], st[D - (1 << k) + 1][R - (1 << l) + 1][k][l]); long b= binaryOperator.apply(st[U][R - (1 << l) + 1][k][l], st[D - (1 << k) + 1][L][k][l]); return binaryOperator.apply(a,b); } private static long[][][][] getSparseTable2D(int arr[][], BinaryOperator<Long>bo){ int n=arr.length; int m=arr[0].length; int k=log[n+1]+2; int l=log[m+1]+2; long st[][][][]=new long[n][m][k][l]; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ st[i][j][0][0]=arr[i][j]; } } for(int x=1;x<k;x++){ for(int y=1;y<l;y++){ for(int i=0;i+(1<<x)<=n;i++){ for(int j=0;j+(1<<y)<=m;j++){ st[i][j][x][y]=bo.apply(bo.apply(st[i][j][x - 1][y-1], st[i + (1 << (x - 1))][j][x - 1][y-1]), bo.apply(st[i][j+(1 << (y - 1))][x - 1][y-1], st[i + (1 << (x - 1))][j+(1 << (y - 1))][x - 1][y-1])); } } } } return st; } static class Subset { int parent; int rank; @Override public String toString() { return "" + parent; } } static int find(Subset[] Subsets, int i) { if (Subsets[i].parent != i) Subsets[i].parent = find(Subsets, Subsets[i].parent); return Subsets[i].parent; } static void union(Subset[] Subsets, int x, int y) { int xroot = find(Subsets, x); int yroot = find(Subsets, y); if (Subsets[xroot].rank < Subsets[yroot].rank) Subsets[xroot].parent = yroot; else if (Subsets[yroot].rank < Subsets[xroot].rank) Subsets[yroot].parent = xroot; else { Subsets[xroot].parent = yroot; Subsets[yroot].rank++; } } private static int maxx(Integer... a) { return Collections.max(Arrays.asList(a)); } private static int minn(Integer... a) { return Collections.min(Arrays.asList(a)); } private static long maxx(Long... a) { return Collections.max(Arrays.asList(a)); } private static long minn(Long... a) { return Collections.min(Arrays.asList(a)); } private static class Pair<T extends Comparable<T>, U extends Comparable<U>> implements Comparable<Pair<T, U>> { T a; U b; public Pair(T a, U b) { this.a = a; this.b = b; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return a.equals(pair.a) && b.equals(pair.b); } @Override public int hashCode() { return Objects.hash(a, b); } @Override public String toString() { return "(" + a + "," + b + ')'; } @Override public int compareTo(Pair<T, U> o) { return (this.a.equals(o.a) ? this.b.equals(o.b) ? 0 : this.b.compareTo(o.b) : this.a.compareTo(o.a)); } } public static int upperBound(List<Integer> list, int value) { int low = 0; int high = list.size(); while (low < high) { final int mid = (low + high) / 2; if (value >= list.get(mid)) { low = mid + 1; } else { high = mid; } } return low; } private static int[] getLPSArray(String pattern) { int i, j, n = pattern.length(); int[] lps = new int[pattern.length()]; lps[0] = 0; for (i = 1, j = 0; i < n; ) { if (pattern.charAt(i) == pattern.charAt(j)) { lps[i++] = ++j; } else if (j > 0) { j = lps[j - 1]; } else { lps[i++] = 0; } } return lps; } private static List<Integer> findPattern(String text, String pattern) { List<Integer> matchedIndexes = new ArrayList<>(); if (pattern.length() == 0) { return matchedIndexes; } int[] lps = getLPSArray(pattern); int i = 0, j = 0, n = text.length(), m = pattern.length(); while (i < n) { if (text.charAt(i) == pattern.charAt(j)) { i++; j++; } if (j == m) { matchedIndexes.add(i - j); j = lps[j - 1]; } if (i < n && text.charAt(i) != pattern.charAt(j)) { if (j > 0) { j = lps[j - 1]; } else { i++; } } } return matchedIndexes; } private static long getLCM(long a, long b) { return (Math.max(a, b) / gcd(a, b)) * Math.min(a, b); } static long fac[] = new long[2000005]; static long ifac[] = new long[2000005]; private static void preCompute(int n) { fac = new long[n + 1]; ifac = new long[n + 1]; fac[0] = ifac[0] = fac[1] = ifac[1] = 1; int i; for (i = 2; i < n + 1; i++) { fac[i] = (i * fac[i - 1]) % mod; ifac[i] = (power(i, mod - 2) * ifac[i - 1]) % mod; } } private static long C(int n, int r) { if (n < 0 || r < 0) return 1; if (r > n) return 1; return (fac[n] * ((ifac[r] * ifac[n - r]) % mod)) % mod; } static long getSum(long BITree[], int index) { long sum = 0; index = index + 1; while (index > 0) { sum += BITree[index]; index -= index & (-index); } return sum; } public static void updateBIT(long BITree[], int index, long val) { index = index + 1; while (index <= BITree.length - 1) { BITree[index] += val; index += index & (-index); } } long[] constructBITree(int arr[], int m) { int n = arr.length; long BITree[] = new long[m + 1]; for (int i = 1; i <= n; i++) BITree[i] = 0; for (int i = 0; i < n; i++) updateBIT(BITree, i, arr[i]); return BITree; } private static String getBinaryString(int a[], int l, int r){ if(l>r||l>a.length-1||r>a.length-1||l<0||r<0)return ""; StringBuilder sb = new StringBuilder(); int i=l; while(i<=r&&a[i]==0)i++; for (;i<=r;i++){ sb.append(a[i]); } return sb.toString(); } private static int cmpBS(String a, String b){ if(a.length()==b.length()){ return a.compareTo(b); } else return a.length()-b.length(); } public static int[] threeEqualParts(int[] A) { int ans[]=new int[2]; ans[0]=ans[1]=-1; int lo1=0,hi1=A.length-3,mid1,curr; while (lo1<=hi1){ mid1=lo1+(hi1-lo1)/2; int lo=mid1+1,hi=A.length-2,mid; String leftS=getBinaryString(A,0,mid1); String midS=getBinaryString(A,lo, hi);; String rightS=""; while(lo<=hi){ mid=lo+(hi-lo)/2; midS=getBinaryString(A,mid1+1, mid); rightS=getBinaryString(A,mid+1,A.length-1); if(midS.equals(rightS)&&leftS.equals(midS)){ ans[0]=mid1; ans[1]=mid+1; return ans; } else if(cmpBS(rightS,midS) < 0){ hi=mid-1; } else { lo=mid+1; } //System.out.println(mid1+" "+lo+" "+hi); } if(cmpBS(leftS,midS) < 0) { hi1=mid1-1; } else { lo1=mid1+1; } } return ans; } private static int upperBound(int a[], int l, int r, int x) { if (l > r) return -1; if (l == r) { if (a[l] <= x) { return -1; } else { return a[l]; } } int m = (l + r) / 2; if (a[m] <= x) { return upperBound(a, m + 1, r, x); } else { return upperBound(a, l, m, x); } } private static void mul(long A[][], long B[][]) { int i, j, k, n = A.length; long C[][] = new long[n][n]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { for (k = 0; k < n; k++) { C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % mod) % mod; } } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { A[i][j] = C[i][j]; } } } private static void power(long A[][], long base[][], long n) { if (n < 2) { return; } power(A, base, n / 2); mul(A, A); if (n % 2 == 1) { mul(A, base); } } private static void print(int... a) { System.out.println(Arrays.toString(a)); } static void reverse(Integer a[], int l, int r) { while (l < r) { int t = a[l]; a[l] = a[r]; a[r] = t; l++; r--; } } private static int cntBits(int n){ int cnt=0; while(n>0){ cnt+=n%2; n/=2; } return cnt; } public void rotate(Integer[] nums, int k) { k = k % nums.length; reverse(nums, 0, nums.length - k - 1); reverse(nums, nums.length - k, nums.length - 1); reverse(nums, 0, nums.length - 1); } private static boolean isSorted(int a[]) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) return false; } return true; } private static int upperBound(long csum[], long val){ int lo=0,hi=csum.length-1,mid,ans=csum.length; while(lo<=hi){ mid=lo+(hi-lo)/2; if(csum[mid]<=val){ lo=mid+1; } else { ans=mid; hi=mid-1; } } return ans; } private static int lowerBound(long csum[], long val){ int lo=0,hi=csum.length-1,mid,ans=-1; while(lo<=hi){ mid=lo+(hi-lo)/2; if(csum[mid]<val){ lo=mid+1; ans=mid; } else { hi=mid-1; } } return ans; } public int countRangeSum(int[] nums, int lower, int upper) { int i,j,k,n=nums.length,ans=0; long csum[]=new long[n]; long prev=0; for(i=0;i<n;i++){ csum[i]=prev+nums[i]; prev=csum[i]; } Arrays.sort(csum); ans=upperBound(csum, upper)-lowerBound(csum,lower)-1; for(i=0;i<n;i++){ ans+=upperBound(csum, upper+csum[i])-lowerBound(csum,lower+csum[i])-1; } return ans; } private static String reverse(String s) { if ("".equals(s)) return ""; return reverse(s.substring(1)) + s.charAt(0); } private static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } private static Map<Integer, Integer> bit = new HashMap<>(); private static void update(int i, int val){ while(i<=1000000){ bit.put(i,bit.getOrDefault(i,0)+val); i+=i&-i; } } private static long get(int i){ long sum=0; while (i>0){ sum+=bit.getOrDefault(i,0); i-=i&-i; } return sum; } private static Set<Long> getDivisors(long n) { Set<Long> divisors = new HashSet<>(); for (long i = 1; i <= Math.sqrt(n); i++) { if (n % i == 0) { divisors.add(i); divisors.add(n / i); } } return divisors; } private static int getMed(List<Integer> arrList, int offset, int limit) { List<Integer> tmp=new ArrayList<>(); for(int i=0;i<limit&&i+offset<arrList.size();i++){ tmp.add(arrList.get(i+offset)); } Collections.sort(tmp); return tmp.get((tmp.size()-1)/2); } public static void main(String[] args) throws Exception { long START_TIME = System.currentTimeMillis(); try (FastReader in = new FastReader(); FastWriter out = new FastWriter()) { int n,t, i, j, m, ti, tidx, gm, l=1, r=2,k; //for (t = in.nextInt(), tidx = 1; tidx <= t; tidx++) { //out.print(String.format("Case #%d: ", tidx)); long x = 0, y = 0, z = 0, sum = 0, bhc = 0, ans = 0,ans1=0,d,g; n=in.nextInt(); m=in.nextInt(); k=in.nextInt(); if(k>0&&k>n+m-2){ out.println("No"); } else if(k>0&&(m==1||n==0)){ out.println("No"); } else if(k==0){ out.println("Yes"); char ca[]=new char[n+m]; char cb[]=new char[n+m]; for(i=0;i<m;i++){ ca[i]=cb[i]='1'; } for(;i<n+m;i++){ ca[i]=cb[i]='0'; } out.println(new String(ca)); out.println(new String(cb)); } else { out.println("Yes"); char ca[]=new char[n+m]; char cb[]=new char[n+m]; boolean vis[]=new boolean[n+m]; for(i=1;i<n+m;i++){ ca[i]=cb[i]='0'; } vis[0]=true; ca[0]=cb[0]='1'; ca[1]='1'; for(i=0;i+1<n+m&&i<=k;i++); cb[i]='1'; vis[1]=vis[i]=true; m-=2; for(i=0;i<ca.length&&m>0;i++){ if(vis[i])continue; ca[i]=cb[i]='1'; vis[i]=true; m--; } out.println(new String(ca)); out.println(new String(cb)); } } if (args.length > 0 && "ex_time".equals(args[0])) { out.print("\nTime taken: "); out.println(System.currentTimeMillis() - START_TIME); } out.commit(); } catch (Exception e) { e.printStackTrace(); } } public static class FastReader implements Closeable { private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private StringTokenizer st; String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextIntArr(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } Integer[] nextIntegerArr(int n) { Integer[] arr = new Integer[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } double[] nextDoubleArr(int n) { double[] arr = new double[n]; for (int i = 0; i < n; i++) { arr[i] = nextDouble(); } return arr; } long[] nextLongArr(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } List<Long> nextLongList(int n) { List<Long> retList = new ArrayList<>(); for (int i = 0; i < n; i++) { retList.add(nextLong()); } return retList; } String[] nextStrArr(int n) { String[] arr = new String[n]; for (int i = 0; i < n; i++) { arr[i] = next(); } return arr; } int[][] nextIntArr2(int n, int m) { int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) { arr[i] = nextIntArr(m); } return arr; } long[][] nextLongArr2(int n, int m) { long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) { arr[i] = nextLongArr(m); } return arr; } @Override public void close() throws IOException { br.close(); } } public static class FastWriter implements Closeable { BufferedWriter bw; StringBuilder sb = new StringBuilder(); List<String> list = new ArrayList<>(); Set<String> set = new HashSet<>(); public FastWriter() { bw = new BufferedWriter(new OutputStreamWriter(System.out)); } <T> void commit() throws IOException { bw.write(sb.toString()); bw.flush(); sb = new StringBuilder(); } public <T> void print(T obj) throws IOException { sb.append(obj.toString()); commit(); } public void println() throws IOException { print("\n"); } public <T> void println(T obj) throws IOException { print(obj.toString() + "\n"); } <T> void printArrLn(T[] arr) throws IOException { for (int i = 0; i < arr.length - 1; i++) { print(arr[i] + " "); } println(arr[arr.length - 1]); } <T> void printArr2(T[][] arr) throws IOException { for (int j = 0; j < arr.length; j++) { for (int i = 0; i < arr[j].length - 1; i++) { print(arr[j][i] + " "); } println(arr[j][arr[j].length - 1]); } } <T> void printColl(Collection<T> coll) throws IOException { List<String> stringList = coll.stream().map(e -> ""+e).collect(Collectors.toList()); println(String.format("%s",String.join(" ", stringList))); } void printCharN(char c, int n) throws IOException { for (int i = 0; i < n; i++) { print(c); } } void printIntArr2(int[][] arr) throws IOException { for (int j = 0; j < arr.length; j++) { for (int i = 0; i < arr[j].length - 1; i++) { print(arr[j][i] + " "); } println(arr[j][arr[j].length - 1]); } } @Override public void close() throws IOException { bw.close(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
f934c628c68f9b746ee3fbdfdeb542f2
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
//stan hu tao //join nct ridin by first year culture reps 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.*; public class x1492D2 { public static void main(String hi[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int A = Integer.parseInt(st.nextToken()); int B = Integer.parseInt(st.nextToken()); int K = Integer.parseInt(st.nextToken()); //# of ones in result if(B == 1) { if(K == 0) { System.out.println("Yes"); StringBuilder sb = new StringBuilder("1"); for(int i=0; i < A; i++) sb.append(0); System.out.println(sb); System.out.println(sb); } else System.out.println("No"); } else if(A == 0) { if(K > 0) { System.out.println("No"); return; } StringBuilder sb = new StringBuilder(); for(int i=0; i < B; i++) sb.append("1"); System.out.println("Yes"); System.out.println(sb); System.out.println(sb); } else if(A+B-2 >= K) { System.out.println("Yes"); int N = A+B; char[] arr = new char[N]; char[] brr = new char[N]; Arrays.fill(arr, '?'); Arrays.fill(brr, '?'); arr[0] = brr[0] = '1'; arr[1] = brr[1+K] = '1'; arr[1+K] = brr[1] = '0'; A--; B-=2; for(int i=0; i < N; i++) if(arr[i] == '?') { if(A > 0) { arr[i] = brr[i] = '0'; A--; } else { arr[i] = brr[i] = '1'; B--; } } StringBuilder sb = new StringBuilder(); sb.append(arr).append("\n"); sb.append(brr).append("\n"); System.out.print(sb); } else System.out.println("No"); } static boolean debug = false; }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
4a6ab75fac00aef6b4ee4e2e08186ac6
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class experiment { static int M = 1_000_000_007; static int INF = 2_000_000_000; static final FastScanner fs = new FastScanner(); //variable public static void main(String[] args) throws IOException { int b = fs.nextInt(); int a = fs.nextInt(); int k = fs.nextInt(); StringBuilder x = new StringBuilder(); StringBuilder y = new StringBuilder(); if((a<2 || b<1 || a+b-2 < k)&&k!=0){ System.out.println("NO"); return; } System.out.println("YES"); if(k!=0) { a-=2; b--; k--; x.append('0'); y.append('1'); while(k-- >0) { if(a>0) { x.append('1'); y.append('1'); a--; }else if(b>0) { x.append('0'); y.append('0'); b--; }else { System.out.println("WRONG"); } } x.append('1'); y.append('0'); } while(b-- > 0) { x.append('0'); y.append('0'); } while(a-- > 0) { x.append('1'); y.append('1'); } if(k!=0) { x.append('1'); y.append('1'); } x.reverse(); y.reverse(); System.out.println(x+"\n"+y); } //class //function // Template static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } static long gcd(long a, long b) { if(a==0) return b; return gcd(b%a,a); } static void premutation(int n, ArrayList<Integer> arr,boolean[] chosen) { if(arr.size() == n) { }else { for(int i=1; i<=n; i++) { if(chosen[i]) continue; arr.add(i); chosen[i] = true; premutation(n,arr,chosen); arr.remove(i); chosen[i] = false; } } } static boolean isPalindrome(char[] c) { int n = c.length; for(int i=0; i<n/2; i++) { if(c[i] != c[n-i-1]) return false; } return true; } static long nCk(int n, int k) { return (modMult(fact(n),fastexp(modMult(fact(n-k),fact(k)),M-2))); } static long fact (long n) { long fact =1; for(int i=1; i<=n; i++) { fact = modMult(fact,i); } return fact%M; } static int modMult(long a,long b) { return (int) (a*b%M); } static int negMult(long a,long b) { return (int)((a*b)%M + M)%M; } static long fastexp(long x, int y){ if(y==1) return x; if(y == 0) return 1; long ans = fastexp(x,y/2); if(y%2 == 0) return modMult(ans,ans); else return modMult(ans,modMult(ans,x)); } static final Random random = new Random(); static void ruffleSort(int[] arr) { int n = arr.length; for(int i=0; i<n; i++) { int j = random.nextInt(n),temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } Arrays.sort(arr); } public static class Pairs implements Comparable<Pairs> { int f,s; Pairs(int f, int s) { this.f = f; this.s = s; } public int compareTo(Pairs p) { return Integer.compare(this.f,p.f); } } } class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer str = new StringTokenizer(""); String next() throws IOException { while(!str.hasMoreTokens()) str = new StringTokenizer(br.readLine()); return str.nextToken(); } char nextChar() throws IOException { return next().charAt(0); } int nextInt() throws IOException { return Integer.parseInt(next()); } float nextfloat() throws IOException { return Float.parseFloat(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } byte nextByte() throws IOException { return Byte.parseByte(next()); } int [] arrayIn(int n) throws IOException { int[] arr = new int[n]; for(int i=0; i<n; i++) { arr[i] = nextInt(); } return arr; } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
33510568affd162bcc784ff9714377c6
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; /** * # * * @author pttrung */ public class D_Round_704_Div2 { public static long MOD = 998244353; static int last; public static void main(String[] args) throws FileNotFoundException { // PrintWriter out = new PrintWriter(new FileOutputStream(new File( // "output.txt"))); PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(); int zero = in.nextInt(); int one = in.nextInt(); int k = in.nextInt(); boolean ok = true; int[] a = new int[zero + one]; int[] b = new int[zero + one]; int x = zero + one - 1; int y = x; if (k > 0) { if (one > 0 && zero > 0) { a[x--] = 0; b[y--] = 1; one--; zero--; k--; while (k > 0) { if (zero > 0) { zero--; x--; y--; } else if (one > 0) { one--; a[x--] = 1; b[y--] = 1; } k--; } a[x--] = 1; b[y--] = 0; } else { ok = false; } } if (k > 0 || (one == 0 && zero > 0)) { ok = false; } while (zero > 0) { x--; y--; zero--; } while (one > 0) { a[x--] = 1; b[y--] = 1; one--; } if (ok && a[0] != 0 && b[0] != 0) { out.println("YES"); for (int i : a) { out.print(i); } out.println(); for (int i : b) { out.print(i); } out.println(); } else { out.println("NO"); } out.close(); } public static int[] KMP(String val) { int i = 0; int j = -1; int[] result = new int[val.length() + 1]; result[0] = -1; while (i < val.length()) { while (j >= 0 && val.charAt(j) != val.charAt(i)) { j = result[j]; } j++; i++; result[i] = j; } return result; } public static boolean nextPer(int[] data) { int i = data.length - 1; while (i > 0 && data[i] < data[i - 1]) { i--; } if (i == 0) { return false; } int j = data.length - 1; while (data[j] < data[i - 1]) { j--; } int temp = data[i - 1]; data[i - 1] = data[j]; data[j] = temp; Arrays.sort(data, i, data.length); return true; } public static int digit(long n) { int result = 0; while (n > 0) { n /= 10; result++; } return result; } public static double dist(long a, long b, long x, long y) { double val = (b - a) * (b - a) + (x - y) * (x - y); val = Math.sqrt(val); double other = x * x + a * a; other = Math.sqrt(other); return val + other; } public static class Point implements Comparable<Point> { long x; int y; public Point(long start, int end) { this.x = start; this.y = end; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Point point = (Point) o; return x == point.x && y == point.y; } @Override public int hashCode() { return Objects.hash(x, y); } @Override public int compareTo(Point o) { return Long.compare(x, o.x); } } public static class FT { long[] data; FT(int n) { data = new long[n]; } public void update(int index, long value) { while (index < data.length) { data[index] += value; index += (index & (-index)); } } public long get(int index) { long result = 0; while (index > 0) { result += data[index]; index -= (index & (-index)); } return result; } } public static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } public static long pow(long a, long b) { if (b == 0) { return 1; } if (b == 1) { return a; } long val = pow(a, b / 2); if (b % 2 == 0) { return (val * val) % MOD; } else { return (val * ((val * a) % MOD)) % MOD; } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner() throws FileNotFoundException { // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true)); br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(); } } return st.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { st = null; try { return br.readLine(); } catch (Exception e) { throw new RuntimeException(); } } public boolean endLine() { try { String next = br.readLine(); while (next != null && next.trim().isEmpty()) { next = br.readLine(); } if (next == null) { return true; } st = new StringTokenizer(next); return st.hasMoreTokens(); } catch (Exception e) { throw new RuntimeException(); } } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
2681dee803d9b42359c62b2967f69bd7
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) {new Main().run();} FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); void run(){ work(); out.flush(); } long mod=1000000007; long gcd(long a,long b) { return a==0?b:gcd(b%a,a); } void work() { int a=ni(),b=ni(),k=ni(); if(a==0||b==1){ if(k==0){ out.println("Yes"); for(int i=0;i<a+b;i++){ if(i==0){ out.print(1); }else{ out.print(a==0?1:0); } } out.println(); for(int i=0;i<a+b;i++){ if(i==0){ out.print(1); }else{ out.print(a==0?1:0); } } }else{ out.println("No"); } }else{ if(k>=a+b-1){ out.println("No"); }else{ out.println("Yes"); int[] A=new int[a+b]; int[] B=new int[a+b]; int idx1=k; int idx2=0; A[idx1]=1; B[idx2]=1; for(int i=a+b-1,c=b-1;c>0;i--){ if(i!=idx1&&i!=idx2){ A[i]=1; B[i]=1; c--; } } for(int i=a+b-1;i>=0;i--){ out.print(A[i]); } out.println(); for(int i=a+b-1;i>=0;i--){ out.print(B[i]); } } } } //input @SuppressWarnings("unused") private ArrayList<Integer>[] ng(int n, int m) { ArrayList<Integer>[] graph=(ArrayList<Integer>[])new ArrayList[n]; for(int i=0;i<n;i++) { graph[i]=new ArrayList<>(); } for(int i=1;i<=m;i++) { int s=in.nextInt()-1,e=in.nextInt()-1; graph[s].add(e); graph[e].add(s); } return graph; } private ArrayList<long[]>[] ngw(int n, int m) { ArrayList<long[]>[] graph=(ArrayList<long[]>[])new ArrayList[n]; for(int i=0;i<n;i++) { graph[i]=new ArrayList<>(); } for(int i=1;i<=m;i++) { long s=in.nextLong()-1,e=in.nextLong()-1,w=in.nextLong(); graph[(int)s].add(new long[] {e,w}); graph[(int)e].add(new long[] {s,w}); } return graph; } private int ni() { return in.nextInt(); } private long nl() { return in.nextLong(); } private String ns() { return in.next(); } private long[] na(int n) { long[] A=new long[n]; for(int i=0;i<n;i++) { A[i]=in.nextLong(); } return A; } private int[] nia(int n) { int[] A=new int[n]; for(int i=0;i<n;i++) { A[i]=in.nextInt(); } return A; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br=new BufferedReader(new InputStreamReader(System.in)); } public String next() { while(st==null || !st.hasMoreElements())//回车,空行情况 { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
f6e32420c582accb460ad46701826ab1
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.util.*; import java.util.concurrent.LinkedBlockingDeque; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; // graph, dfs,bfs, get connected components,iscycle, isbipartite, dfs on trees public class scratch_25 { static class Graph{ public static class Vertex{ HashMap<Integer,Integer> nb= new HashMap<>(); // for neighbours of each vertex } public static HashMap<Integer,Vertex> vt; // for vertices(all) public Graph(){ vt= new HashMap<>(); } public static int numVer(){ return vt.size(); } public static boolean contVer(int ver){ return vt.containsKey(ver); } public static void addVer(int ver){ Vertex v= new Vertex(); vt.put(ver,v); } public static void addEdge(int ver1, int ver2, int weight){ if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){ return; } Vertex v1= vt.get(ver1); Vertex v2= vt.get(ver2); v1.nb.put(ver2,weight); // if previously there is an edge, then this replaces that edge v2.nb.put(ver1,weight); } public static void delEdge(int ver1, int ver2){ if(!vt.containsKey(ver1) || !vt.containsKey(ver2)){ return; } vt.get(ver1).nb.remove(ver2); vt.get(ver2).nb.remove(ver1); } public static void delVer(int ver){ if(!vt.containsKey(ver)){ return; } Vertex v1= vt.get(ver); ArrayList<Integer> arr= new ArrayList<>(v1.nb.keySet()); for (int i = 0; i <arr.size() ; i++) { int s= arr.get(i); vt.get(s).nb.remove(ver); } vt.remove(ver); } static boolean done[]; static int parent[]; static ArrayList<Integer>vals= new ArrayList<>(); public static boolean isCycle(int i){ Stack<Integer>stk= new Stack<>(); stk.push(i); while(!stk.isEmpty()){ int x= stk.pop(); vals.add(x); // System.out.print("current="+x+" stackinit="+stk); if(!done[x]){ done[x]=true; } else if(done[x] ){ return true; } ArrayList<Integer>ar= new ArrayList<>(vt.get(x).nb.keySet()); for (int j = 0; j <ar.size() ; j++) { if(parent[x]!=ar.get(j)){ parent[ar.get(j)]=x; stk.push(ar.get(j)); } } // System.out.println(" stackfin="+stk); } return false; } static int[]level; static int[] curr; static int[] fin; public static void dfs(int src){ done[src]=true; level[src]=0; Queue<Integer>q= new LinkedList<>(); q.add(src); while(!q.isEmpty()){ int x= q.poll(); ArrayList<Integer>arr= new ArrayList<>(vt.get(x).nb.keySet()); for (int i = 0; i <arr.size() ; i++) { int v= arr.get(i); if(!done[v]){ level[v]=level[x]+1; done[v]=true; q.offer(v); } } } } static int oc[]; static int ec[]; public static void dfs1(int src){ Queue<Integer>q= new LinkedList<>(); q.add(src); done[src]= true; // int count=0; while(!q.isEmpty()){ int x= q.poll(); // System.out.println("x="+x); int even= ec[x]; int odd= oc[x]; if(level[x]%2==0){ int val= (curr[x]+even)%2; if(val!=fin[x]){ // System.out.println("bc"); even++; vals.add(x); } } else{ int val= (curr[x]+odd)%2; if(val!=fin[x]){ // System.out.println("bc"); odd++; vals.add(x); } } ArrayList<Integer>arr= new ArrayList<>(vt.get(x).nb.keySet()); // System.out.println(arr); for (int i = 0; i <arr.size() ; i++) { int v= arr.get(i); if(!done[v]){ done[v]=true; oc[v]=odd; ec[v]=even; q.add(v); } } } } static long popu[]; static long happy[]; static long count[]; // total people crossing that pos static long sum[]; // total sum of happy people including that. public static void bfs(int x){ done[x]=true; long total= popu[x]; // long smile= happy[x]; ArrayList<Integer>nbrs= new ArrayList<>(vt.get(x).nb.keySet()); for (int i = 0; i <nbrs.size() ; i++) { int r= nbrs.get(i); if(!done[r]){ bfs(r); total+=count[r]; // smile+=sum[r]; } } count[x]=total; // sum[x]=smile; } public static void bfs1(int x){ done[x]=true; // long total= popu[x]; long smile= 0; ArrayList<Integer>nbrs= new ArrayList<>(vt.get(x).nb.keySet()); for (int i = 0; i <nbrs.size() ; i++) { int r= nbrs.get(i); if(!done[r]){ bfs1(r); // total+=count[r]; smile+=happy[r]; } } // count[x]=total; sum[x]=smile; } } static class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** * call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } /** * get next word */ static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } } static class Pair implements Comparable<Pair> { long x; long y; public Pair(long x, long y) { this.x = x; this.y = y;} @Override public String toString() { return x + " " + y; } @Override public int compareTo(Pair o) { if(this.x >o.x){ return 1; } else if(this.x==o.x){ return 0; } else{ return -1; } } } // After writing solution, quick scan for: // array out of bounds // special cases e.g. n=1? // // Big numbers arithmetic bugs: // int overflow // sorting, or taking max, or negative after MOD public static void main(String[] args) throws IOException { Reader.init(System.in); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); int zeros= Reader.nextInt(); int ones= Reader.nextInt()-1; // the first letter has to be a 1 so remember to print 1 before all int k= Reader.nextInt(); if(k==0){ out.append("Yes"+"\n"); out.append(1+""); for (int i = 0; i <ones ; i++) { out.append(1+""); } for (int i = 0; i <zeros ; i++) { out.append(0+""); } out.append("\n"); out.append(1+""); for (int i = 0; i <ones ; i++) { out.append(1+""); } for (int i = 0; i <zeros ; i++) { out.append(0+""); } } else if(k>zeros+ones-1 || zeros==0 || ones==0){ out.append("No"+"\n"); } else{ out.append("Yes"+"\n"); int first[]= new int[zeros+ones+1]; int sec[]= new int[zeros+ones+1]; Arrays.fill(first,-1); Arrays.fill(sec,-1); first[0]=1; sec[0]=1; first[1]=1; sec[1]=0; first[1+k]=0; sec[1+k]=1; zeros-=1; ones-=1; for (int i = 2; i <1+k ; i++) { if(ones>0){ first[i]=1; sec[i]=1; ones--; } else{ first[i]=0; sec[i]=0; zeros--; } } for (int i = 1+k+1; i <first.length ; i++) { if(ones>0){ first[i]=1; sec[i]=1; ones--; } else{ first[i]=0; sec[i]=0; zeros--; } } for (int i = 0; i <first.length ; i++) { out.append(first[i]+""); } out.append("\n"); for (int i = 0; i <first.length ; i++) { out.append(sec[i]+""); } out.append("\n"); } out.flush(); out.close(); } public static int localMinUtil(int[] arr, int low, int high, int n) { // Find index of middle element int mid = low + (high - low) / 2; // Compare middle element with its neighbours // (if neighbours exist) if(mid == 0 || arr[mid - 1] > arr[mid] && mid == n - 1 || arr[mid] < arr[mid + 1]) return mid; // If middle element is not minima and its left // neighbour is smaller than it, then left half // must have a local minima. else if(mid > 0 && arr[mid - 1] < arr[mid]) return localMinUtil(arr, low, mid - 1, n); // If middle element is not minima and its right // neighbour is smaller than it, then right half // must have a local minima. return localMinUtil(arr, mid + 1, high, n); } // A wrapper over recursive function localMinUtil() public static int localMin(int[] arr, int n) { return localMinUtil(arr, 0, n - 1, n); } public static String convert(String s,int n){ if(s.length()==n){ return s; } else{ int x= s.length(); int v=n-x; String str=""; for (int i = 0; i <v ; i++) { str+='0'; } str+=s; return str; } } public static int lower(int arr[],int key){ int low = 0; int high = arr.length-1; while(low < high){ int mid = low + (high - low)/2; if(arr[mid] >= key){ high = mid; } else{ low = mid+1; } } return low; } public static int upper(int arr[],int key){ int low = 0; int high = arr.length-1; while(low < high){ int mid = low + (high - low+1)/2; if(arr[mid] <= key){ low = mid; } else{ high = mid-1; } } return low; } static long modExp(long a, long b, long mod) { //System.out.println("a is " + a + " and b is " + b); if (a==1) return 1; long ans = 1; while (b!=0) { if (b%2==1) { ans = (ans*a)%mod; } a = (a*a)%mod; b/=2; } return ans; } public static long modmul(long a, long b, long mod) { return b == 0 ? 0 : ((modmul(a, b >> 1, mod) << 1) % mod + a * (b & 1)) % mod; } static long sum(long n){ // System.out.println("lol="+ (n*(n-1))/2); return (n*(n+1))/2; } public static ArrayList<Integer> Sieve(int n) { boolean arr[]= new boolean [n+1]; Arrays.fill(arr,true); arr[0]=false; arr[1]=false; for (int i = 2; i*i <=n ; i++) { if(arr[i]){ for (int j = 2; j <=n/i ; j++) { int u= i*j; arr[u]=false; }} } ArrayList<Integer> ans= new ArrayList<>(); for (int i = 0; i <n+1 ; i++) { if(arr[i]){ ans.add(i); } } return ans; } static long power( long x, long y, long p) { long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if((y & 1)==1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } public static long ceil_div(long a, long b){ return (a+b-1)/b; } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a*b)/gcd(a, b); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
d61066794f0ad2e78af515e1958c4c16
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; public class MainD { static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public boolean hasNext() { try { String string = reader.readLine(); if (string == null) { return false; } tokenizer = new StringTokenizer(string); return tokenizer.hasMoreTokens(); } catch (IOException e) { return false; } } } static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) { int t = 1; while (t -- > 0) { solve(); } out.close(); } static void solve() { int a,b,k; a = in.nextInt(); b = in.nextInt(); k = in.nextInt(); int n = a + b; byte[] x = new byte[n]; byte[] y = new byte[n]; x[0] = 1; y[0] = 1; b -= 1; int ax = a, ay = a; // x de ge shu int bx = b, by = b; boolean flag = true; if (k >= n - 1 && k != 0) { flag = false; } else { boolean hasDiff = false; for (int i = 1; i < n && flag; i++) { if (k > 0) { if (hasDiff) { if (ax > 1 && ay > 0) { x[i] = 0; y[i] = 0; ax --; ay --; } else if (bx > 0 && by > 1){ x[i] = 1; y[i] = 1; bx --; by --; } else { flag = false; } k --; } else { if (bx <= 0 || ay <= 0) { flag = false; } else { x[i] = 1; y[i] = 0; bx --; ay --; hasDiff = true; } k --; } } else { if (hasDiff) { hasDiff = false; if (ax > 0 && by > 0) { x[i] = 0; y[i] = 1; ax --; by --; } else { flag = false; } } else { if (ax == ay) { if (ax > 0) { ax --; ay --; x[i] = 0; y[i] = 0; } else { bx --; by --; x[i] = 1; y[i] = 1; } } else { flag = false; } } } } } if (flag) { out.println("YES"); for (int i = 0; i < n; i++) { out.print(x[i]); } out.println(); for (int i = 0; i < n; i++) { out.print(y[i]); } out.println(); } else { out.println("NO"); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
e65daeba33c080072ca2b36bd711c6e5
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 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 i, j, k, n, m, t, y, x, sum=0; static long mod = 1000000007; static FastScanner fs = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); static String str; static long ans =0; public static void main(String[] args) { t =1; while (t-- >0){ int a = fs.nextInt(); int b = fs.nextInt(); int k = fs.nextInt(); if((k>a && a==0) || (k>0 && b==1)){ out.println("No"); } else if(b==1){ out.println("Yes"); out.print(1); for(i=0;i<a;i++){ out.print(0); } out.println(); out.print(1); for(i=0;i<a;i++){ out.print(0); } } else if(k>=(b+a-1)) out.println("No"); else{ if(k<=a) { out.println("Yes"); n = a + b; int[] ans1 = new int[n]; int[] ans2 = new int[n]; ans1[n - k - 1] = 1; ans2[n - 1] = 1; for (i = 0; i < n; i++) { if (i < b - 1) { ans1[i] = 1; ans2[i] = 1; } } for (i = 0; i < n; i++) { out.print(ans1[i]); } out.println(); for (i = 0; i < n; i++) { out.print(ans2[i]); } } else{ out.println("Yes"); n = a + b; int[] ans1 = new int[n]; int[] ans2 = new int[n]; ans1[n-1] = 0; ans2[n-1] = 1; for (i = 0; i < n-1; i++) { if (i < b - k) { ans1[i] = 1; ans2[i] = 1; } if (i<b){ ans1[i]=1; ans2[i]=1; } if(i==n-1-k){ ans2[i]=0; } } for (i = 0; i < n; i++) { out.print(ans1[i]); } out.println(); for (i = 0; i < n; i++) { out.print(ans2[i]); } } } } out.close(); } private static void initialize(long[] arr, long val){ int n = arr.length; for(int i = 0;i<n;i++){ arr[i]=val; } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { this.first = first; this.second = second; } public int compareTo(Pair o) { return Long.compare(first, o.first); } } static void ruffleSort(int[] a) { //ruffle int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n), temp=a[i]; a[i]=a[oi]; a[oi]=temp; } //then sort Arrays.sort(a); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
51b8ade73f7be45f76db1eb156783e58
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*;import java.util.*;import java.math.*; public class Main { static long mod=1000000007l; static int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE; static long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE; static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static StringTokenizer st; static StringBuilder sb; static public void main(String[] args)throws Exception { st=new StringTokenizer(br.readLine()); int t=1; sb=new StringBuilder(50); o: while(t-->0) { int a=i(); int b=i(); int k=i(); if(k==0) { pl("Yes"); int n=a+b; char bb[]=new char[n]; char aa[]=new char[n]; for(int x=0;x<n;x++) { if(b!=0) { aa[x]=bb[x]='1'; b--; } else aa[x]=bb[x]='0'; } pl(new String(aa)); pl(new String(bb)); } else if(b==1)pl("No"); else { if(a+b-2>=k&&a>=1) { pl("Yes"); int n=a+b; char bb[]=new char[n]; char aa[]=new char[n]; aa[n-1]='0'; bb[n-1]='1'; aa[n-1-k]='1'; bb[n-1-k]='0'; b--; for(int x=0;x<n;x++) { if(aa[x]=='0'||aa[x]=='1')continue; if(b!=0) { aa[x]=bb[x]='1'; b--; } else aa[x]=bb[x]='0'; } pl(new String(aa)); pl(new String(bb)); } else pl("No"); } } p(sb); } static int[] so(int ar[]) { Integer r[]=new Integer[ar.length]; for(int x=0;x<ar.length;x++)r[x]=ar[x]; Arrays.sort(r); for(int x=0;x<ar.length;x++)ar[x]=r[x]; return ar; } static long[] so(long ar[]) { Long r[]=new Long[ar.length]; for(int x=0;x<ar.length;x++)r[x]=ar[x]; Arrays.sort(r); for(int x=0;x<ar.length;x++)ar[x]=r[x]; return ar; } static char[] so(char ar[]) { Character r[]=new Character[ar.length]; for(int x=0;x<ar.length;x++)r[x]=ar[x]; Arrays.sort(r); for(int x=0;x<ar.length;x++)ar[x]=r[x]; return ar; } static void s(String s){sb.append(s);} static void s(int s){sb.append(s);} static void s(long s){sb.append(s);} static void s(char s){sb.append(s);} static void s(double s){sb.append(s);} static void ss(){sb.append(' ');} static void sl(String s){sb.append(s);sb.append("\n");} static void sl(int s){sb.append(s);sb.append("\n");} static void sl(long s){sb.append(s);sb.append("\n");} static void sl(char s){sb.append(s);sb.append("\n");} static void sl(double s){sb.append(s);sb.append("\n");} static void sl(){sb.append("\n");} static int max(int ...a){int m=a[0];for(int e:a)m=(m>=e)?m:e;return m;} static int min(int ...a){int m=a[0];for(int e:a)m=(m<=e)?m:e;return m;} static int abs(int a){return Math.abs(a);} static long max(long ...a){long m=a[0];for(long e:a)m=(m>=e)?m:e;return m;} static long min(long ...a){long m=a[0];for(long e:a)m=(m<=e)?m:e;return m;} static long abs(long a){return Math.abs(a);} static int sq(int a){return (int)Math.sqrt(a);} static long sq(long a){return (long)Math.sqrt(a);} static long gcd(long a,long b){return b==0l?a:gcd(b,a%b);} static boolean pa(String s,int i,int j) { while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false; return true; } static int ncr(int n,int c,long m) { long a=1l; for(int x=n-c+1;x<=n;x++)a=((a*x)%m); long b=1l; for(int x=2;x<=c;x++)b=((b*x)%m); return (int)((a*(mul((int)b,m-2,m)%m))%m); } static boolean[] si(int n) { boolean bo[]=new boolean[n+1]; bo[0]=true;bo[1]=true; for(int x=4;x<=n;x+=2)bo[x]=true; for(int x=3;x*x<=n;x+=2) { if(!bo[x]) { int vv=(x<<1); for(int y=x*x;y<=n;y+=vv)bo[y]=true; } } return bo; } static int[] fac(int n) { int bo[]=new int[n+1]; for(int x=1;x<=n;x++)for(int y=x;y<=n;y+=x)bo[y]++; return bo; } static long mul(long a,long b,long m) { long r=1l; a%=m; while(b>0) { if((b&1)==1)r=(r*a)%m; b>>=1; a=(a*a)%m; } return r; } static int i()throws IOException { if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return Integer.parseInt(st.nextToken()); } static long l()throws IOException { if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return Long.parseLong(st.nextToken()); } static String s()throws IOException { if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return st.nextToken(); } static double d()throws IOException { if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); return Double.parseDouble(st.nextToken()); } static void p(Object p){System.out.print(p);} static void p(String p){System.out.print(p);} static void p(int p){System.out.print(p);} static void p(double p){System.out.print(p);} static void p(long p){System.out.print(p);} static void p(char p){System.out.print(p);} static void p(boolean p){System.out.print(p);} static void pl(Object p){System.out.println(p);} static void pl(String p){System.out.println(p);} static void pl(int p){System.out.println(p);} static void pl(char p){System.out.println(p);} static void pl(double p){System.out.println(p);} static void pl(long p){System.out.println(p);} static void pl(boolean p){System.out.println(p);} static void pl(){System.out.println();} static void s(int a[]) { for(int e:a) { sb.append(e); sb.append(' '); } sb.append("\n"); } static void s(long a[]) { for(long e:a) { sb.append(e); sb.append(' '); } sb.append("\n"); } static void s(int ar[][]) { for(int a[]:ar) { for(int e:a) { sb.append(e); sb.append(' '); } sb.append("\n"); } } static void s(char a[]) { for(char e:a) { sb.append(e); sb.append(' '); } sb.append("\n"); } static void s(char ar[][]) { for(char a[]:ar) { for(char e:a) { sb.append(e); sb.append(' '); } sb.append("\n"); } } static int[] ari(int n)throws IOException { int ar[]=new int[n]; if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken()); return ar; } static int[][] ari(int n,int m)throws IOException { int ar[][]=new int[n][m]; for(int x=0;x<n;x++) { if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken()); } return ar; } static long[] arl(int n)throws IOException { long ar[]=new long[n]; if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken()); return ar; } static long[][] arl(int n,int m)throws IOException { long ar[][]=new long[n][m]; for(int x=0;x<n;x++) { if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken()); } return ar; } static String[] ars(int n)throws IOException { String ar[]=new String[n]; if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); for(int x=0;x<n;x++) ar[x]=st.nextToken(); return ar; } static double[] ard(int n)throws IOException { double ar[]=new double[n]; if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken()); return ar; } static double[][] ard(int n,int m)throws IOException { double ar[][]=new double[n][m]; for(int x=0;x<n;x++) { if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken()); } return ar; } static char[] arc(int n)throws IOException { char ar[]=new char[n]; if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine()); for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0); return ar; } static char[][] arc(int n,int m)throws IOException { char ar[][]=new char[n][m]; for(int x=0;x<n;x++) { String s=br.readLine(); for(int y=0;y<m;y++)ar[x][y]=s.charAt(y); } return ar; } static void p(int ar[]) { StringBuilder sb=new StringBuilder(2*ar.length); for(int a:ar) { sb.append(a); sb.append(' '); } System.out.println(sb); } static void p(int ar[][]) { StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length); for(int a[]:ar) { for(int aa:a) { sb.append(aa); sb.append(' '); } sb.append("\n"); } p(sb); } static void p(long ar[]) { StringBuilder sb=new StringBuilder(2*ar.length); for(long a:ar) { sb.append(a); sb.append(' '); } System.out.println(sb); } static void p(long ar[][]) { StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length); for(long a[]:ar) { for(long aa:a) { sb.append(aa); sb.append(' '); } sb.append("\n"); } p(sb); } static void p(String ar[]) { int c=0; for(String s:ar)c+=s.length()+1; StringBuilder sb=new StringBuilder(c); for(String a:ar) { sb.append(a); sb.append(' '); } System.out.println(sb); } static void p(double ar[]) { StringBuilder sb=new StringBuilder(2*ar.length); for(double a:ar) { sb.append(a); sb.append(' '); } System.out.println(sb); } static void p(double ar[][]) { StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length); for(double a[]:ar) { for(double aa:a) { sb.append(aa); sb.append(' '); } sb.append("\n"); } p(sb); } static void p(char ar[]) { StringBuilder sb=new StringBuilder(2*ar.length); for(char aa:ar) { sb.append(aa); sb.append(' '); } System.out.println(sb); } static void p(char ar[][]) { StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length); for(char a[]:ar) { for(char aa:a) { sb.append(aa); sb.append(' '); } sb.append("\n"); } p(sb); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
1881b9369272966ea83ea2741ba5704f
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class D { public static void main(String[] args) { FastScanner sc = new FastScanner(); int a = sc.nextInt(); int b = sc.nextInt(); int k = sc.nextInt(); if(k >= a+b) System.out.println("No"); else if(k == 0) { char[] s = new char[a+b]; char[] t = new char[a+b]; for(int i = 0; i < s.length; i++){ if(b > 0) { s[i] = '1'; t[i] = '1'; b--; } else { s[i] = '0'; t[i] = '0'; } } StringBuilder sb = new StringBuilder(); sb.append("Yes\n"); sb.append(s); sb.append("\n"); sb.append(t); sb.append("\n"); PrintWriter pw = new PrintWriter(System.out); pw.println(sb.toString().trim()); pw.flush(); } else if(b == 1 || a == 0 || k >= a+b-1) System.out.println("No"); else { char[] s = new char[a+b]; char[] t = new char[a+b]; s[0] = '1'; t[0] = '1'; s[a+b-1] = '0'; s[a+b-k-1] = '1'; t[a+b-1] = '1'; t[a+b-k-1] = '0'; b -= 2; for(int i = 0; i < s.length; i++){ if(s[i] != 0) continue; if(b > 0) { s[i] = '1'; t[i] = '1'; b--; } else { s[i] = '0'; t[i] = '0'; } } StringBuilder sb = new StringBuilder(); sb.append("Yes\n"); sb.append(s); sb.append("\n"); sb.append(t); sb.append("\n"); PrintWriter pw = new PrintWriter(System.out); pw.println(sb.toString().trim()); pw.flush(); } } static class FastScanner { public BufferedReader reader; public StringTokenizer tokenizer; public FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return reader.readLine(); } catch(IOException e) { throw new RuntimeException(e); } } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
0a8a5432bf9ec7fd72d4c165587ce076
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; public class GeniussGambit_704D { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt(); if((a == 0 || b == 1) && k > 0 || a > 0 && b > 1 && k >= a + b - 1) { System.out.println("NO"); return; } System.out.println("YES"); char[] arr = new char[a + b]; for(int i = 0; i < b; i ++) arr[i] = '1'; for(int i = b; i < a + b; i ++) arr[i] = '0'; String s = String.valueOf(arr); System.out.println(s); if(a == 0 || b == 1) { System.out.println(s); return; } char[] arr2 = new char[a + b]; Arrays.fill(arr2, '0'); arr2[0] = '1'; int idx = b - 1 + Math.min(a, k); arr2[idx] = '1'; k -= Math.min(a, k); for(int i = 1; i < b; i ++) { int j = b - i; if(i - 1 != k) arr2[j] = '1'; } System.out.println(String.valueOf(arr2)); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
86e1d98e0c5fb5911e35c27c128f950d
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String args[]) { FastReader input=new FastReader(); PrintWriter out=new PrintWriter(System.out); int T=1; while(T-->0) { int a,b,k; a=input.nextInt(); b=input.nextInt(); k=input.nextInt(); if(a==0) { if(k>0) { out.println("No"); } else { out.println("Yes"); StringBuilder sb=new StringBuilder(""); for(int i=0;i<b;i++) { sb.append("1"); } out.println(sb.toString()); out.println(sb.toString()); } } else { if(k>a+b-2 || (b==1 && k>0)) { out.println("No"); } else { char ch[][]=new char[2][a+b]; ch[0][0]='1'; ch[1][0]='1'; if(b>1) { ch[0][1]='1'; int x=b-2; ch[1][2+k-1]='1'; for(int i=2;i<a+b;i++) { if(i!=2+k-1 && x>0) { ch[0][i]='1'; x--; } } for(int i=0;i<a+b;i++) { if(ch[0][i]!='1') { ch[0][i]='0'; } if(i!=1) { if(ch[0][i]=='1') { ch[1][i]='1'; } } } for(int i=0;i<a+b;i++) { if(ch[1][i]!='1') { ch[1][i]='0'; } } } for(int i=0;i<a+b;i++) { if(ch[0][i]!='1') { ch[0][i]='0'; } if(ch[1][i]!='1') { ch[1][i]='0'; } } out.println("Yes"); out.println(ch[0]); out.println(ch[1]); } } } out.close(); } static long kadenesAlgorithm(int arr[],int n) { long mf=0,mh=0; for(int i=0;i<n;i++) { mh+=arr[i]; if(mh<0) { mh=0; } else { mf=Math.max(mf,mh); } } if(mf==0) { mf=Long.MIN_VALUE; for(int i=0;i<n;i++) { mf=Math.max(mf,arr[i]); } return mf; } else { return mf; } } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""; try { str=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
f8afbb814e918920ff465bc932718817
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int k = sc.nextInt(); if(a==0){ if(k==0){ System.out.println("Yes"); for (int i = 1 ;i <= a+b ;i++){ System.out.print(1); } System.out.println(); for (int i = 1 ;i <= a+b ;i++){ System.out.print(1); } }else { System.out.println("No"); return; } return; } if(b==1){ if(k==0){ System.out.println("Yes"); System.out.print(1); for (int i = 1 ;i < a+b ;i++){ System.out.print(0); } System.out.println(); System.out.print(1); for (int i = 1 ;i < a+b ;i++){ System.out.print(0); } }else { System.out.println("No"); return; } return; } if(k>=a+b-1){ System.out.println("No"); return; } int ta [] = new int[a+b+1]; int tb [] = new int[a+b+1]; ta[1]=1; tb[1]=1; ta[2]=1; tb[2+k]=1; int x = b-2; for (int i = 3;i<=a+b;i++){ if(x==0){ break; } if(i==k+2){ continue; } ta[i]=tb[i]=1; x--; } System.out.println("Yes"); for (int i = 1;i <= a+b;i++){ System.out.print(ta[i]); } System.out.println(); for (int i = 1;i <= a+b;i++){ System.out.print(tb[i]); } System.out.println(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
2ef2703f587bfb87464e6d981fa5207e
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; import java.math.*; /** * * @Har_Har_Mahadev */ public class A { private static long INF = 2000000000000000000L, M = 1000000007, MM = 998244353; private static int N = 0; public static void process() throws IOException { int a = sc.nextInt(),b = sc.nextInt(),k = sc.nextInt(); if(k == 0) { StringBuilder ans1 = new StringBuilder(); StringBuilder ans2 = new StringBuilder(); for(int i=0; i<b; i++)ans1.append("1"); for(int i=0; i<a; i++)ans1.append("0"); for(int i=0; i<b; i++)ans2.append("1"); for(int i=0; i<a; i++)ans2.append("0"); System.out.println("YES"); System.out.println(ans1); System.out.println(ans2); return; } // case for b = 1 int n = a+b; if(b == 1 || a == 0) { System.out.println("NO"); return; } if(k > n-2) { System.out.println("NO"); return; } System.out.println("YES"); int arr1[] = new int[n]; int arr2[] = new int[n]; arr1[0] = 1; arr2[0] = 1; arr2[n-1] = 1; arr1[n-k-1] = 1; b-=2; for(int i=0; i<n; i++) { if(arr1[i] == 0 && arr2[i] == 0 && b > 0) { arr1[i] = 1; arr2[i] = 1; b--; } } for(int e : arr1)System.out.print(e); System.out.println(); for(int e : arr2)System.out.print(e); System.out.println(); } //============================================================================= //--------------------------The End--------------------------------- //============================================================================= static FastScanner sc; static PrintWriter out; public static void main(String[] args) throws IOException { boolean oj = true; if (oj) { sc = new FastScanner(); out = new PrintWriter(System.out); } else { sc = new FastScanner(100); out = new PrintWriter("output.txt"); } int t = 1; // t = sc.nextInt(); while (t-- > 0) { process(); } out.flush(); out.close(); } static class Pair implements Comparable<Pair> { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (!(o instanceof Pair)) return false; // Pair key = (Pair) o; // return x == key.x && y == key.y; // } // // @Override // public int hashCode() { // int result = x; // result = 31 * result + y; // return result; // } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static void println(Object o) { out.println(o); } static void println() { out.println(); } static void print(Object o) { out.print(o); } static void pflush(Object o) { out.println(o); out.flush(); } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static int max(int x, int y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int abs(int x) { return Math.abs(x); } static long abs(long x) { return Math.abs(x); } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } public static int gcd(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static int lcm(int a, int b) { return (a * b) / gcd(a, b); } public static int lower_bound(int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] >= x) high = mid; else low = mid + 1; } return low; } public static int upper_bound(int[] arr, int x) { int low = 0, high = arr.length, mid = -1; while (low < high) { mid = (low + high) / 2; if (arr[mid] > x) high = mid; else low = mid + 1; } return low; } ///////////////////////////////////////////////////////////////////////////////////////////////////////// static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() throws FileNotFoundException { br = new BufferedReader(new InputStreamReader(System.in)); } FastScanner(int a) throws FileNotFoundException { br = new BufferedReader(new FileReader("input.txt")); } String next() throws IOException { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String nextLine() throws IOException { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readArray(int n) throws IOException { int[] A = new int[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextInt(); } return A; } long[] readArrayLong(int n) throws IOException { long[] A = new long[n]; for (int i = 0; i != n; i++) { A[i] = sc.nextLong(); } return A; } } static void ruffleSort(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); long temp = a[i]; a[i] = a[r]; a[r] = temp; } Arrays.sort(a); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
f5c5324528dcb96d38e2cd452fd7f192
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import javax.print.DocFlavor; import javax.swing.text.html.parser.Entity; import java.awt.*; import java.io.*; import java.lang.reflect.Array; import java.util.*; import java.util.List; import java.util.stream.Collectors; public class Main { static FastScanner sc; static PrintWriter pw; static final long INF = 2000000000000000l; static final int MOD = 1000000007; static final int N = 1005; static long mul(long a, long b, long mod) { return (a * b) % mod; } public static long pow(long a, long n, long mod) { long res = 1; while(n != 0) { if((n & 1) == 1) { res = mul(res, a, mod); } a = mul(a, a, mod); n >>= 1; } return res; } /*public static int inv(int a) { return pow(a, MOD-2, mod); }*/ public static List<Integer> getPrimes() { List<Integer> ans = new ArrayList<>(); boolean[] prime = new boolean[N]; Arrays.fill(prime, true); prime[0] = prime[1] = false; for(int i = 2; i < N; ++i) { if(prime[i]) { ans.add(i); if (i * 1l * i <= N) for (int j = i * i; j < N; j += i) prime[j] = false; } } return ans; } public static long gcd(long a, long b) { if(b == 0) return a; else return gcd(b, a % b); } public static class A { long x; long y; A(long a, long b) { this.x = a; this.y = b; } } public static void solve() throws IOException { int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt(); if( (k > a + b - 2 && a != 0 && b != 1) || (a == 0 && k != 0) || (b == 1 && k != 0)) pw.println("NO"); else { pw.println("YES"); if(a == 0) { for(int i = 0; i < b; ++i) pw.print("1"); pw.println(); for(int i = 0; i < b; ++i) pw.print("1"); } else if(b == 1) { pw.print("1"); for(int i = 0; i < a; ++i) pw.print("0"); pw.println(); pw.print("1"); for(int i = 0; i < a; ++i) pw.print("0"); } else { for(int i = 0; i < b; ++i) pw.print("1"); for(int i = 0; i < a; ++i) pw.print("0"); pw.println(); pw.print("1"); if(b == 2) { for(int i = 0; i < k; ++i) pw.print("0"); pw.print("1"); for(int i = 0; i < a - k; ++i) pw.print("0"); } else { if(b - 2 < a + b - 2 - k) { for(int i = 0; i < b - 2; ++i) pw.print("1"); for(int i = 0; i < k; ++i) pw.print("0"); pw.print("1"); for(int i = 0; i < a - k; ++i) pw.print("0"); } else { for (int i = 0; i < a + b - 2 - k; ++i) pw.print("1"); pw.print("0"); for (int i = 0; i < (b - 2) - (a + b - 2 - k); ++i) pw.print("1"); for (int i = 0; i < a - 1; ++i) pw.print("0"); pw.print("1"); } } } } pw.println(); } public static void main(String[] args) throws IOException { sc = new FastScanner(System.in); pw = new PrintWriter(System.out); int xx = 1; while(xx > 0) { solve(); xx--; } pw.close(); } } class FastScanner { static StringTokenizer st = new StringTokenizer(""); static BufferedReader br; public FastScanner(InputStream inputStream) { br = new BufferedReader(new InputStreamReader(inputStream)); } public String next() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
43fcd9f98aa7b5360c0e73a5778c0205
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class D1492 { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int a = sc.nextInt(); int b = sc.nextInt(); int k = sc.nextInt(); int[] x = new int[a + b]; int[] y = new int[a + b]; int[] z = new int[a + b]; boolean yes = true; if (a == 0) { if (k == 0) { Arrays.fill(x, 1); Arrays.fill(y, 1); } else { yes = false; } } else if (k == 0) { int cur = a + b - 1; while (a > 0) { x[cur] = 0; y[cur] = 0; z[cur] = 0; a--; cur--; } while (b > 0) { x[cur] = 1; y[cur] = 1; z[cur] = 0; cur--; b--; } } else { x[0] = 1; y[0] = 1; z[0] = 0; b--; if (b == 0 || a + b < k + 1) { yes = false; } else { int cur = a + b; while (a + b > k + 1) { if (a > 1) { x[cur] = 0; y[cur] = 0; z[cur] = 0; a--; cur--; } else { x[cur] = 1; y[cur] = 1; z[cur] = 0; cur--; b--; } } x[cur] = 0; y[cur] = 1; z[cur] = 1; cur--; a--; b--; x[1] = 1; y[1] = 0; z[1] = 0; while (cur > 1) { if (a > 0) { x[cur] = 0; y[cur] = 0; z[cur] = 1; a--; } else { x[cur] = 1; y[cur] = 1; z[cur] = 1; b--; } cur--; } } } if (yes) { pw.println("YES"); for (int xx : x) { pw.print(xx); } pw.println(); for (int xx : y) { pw.print(xx); } pw.println(); } else { pw.println("NO"); } pw.close(); } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
459a38ebbd884db4cfd953f671b90b6a
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class codeforces { public static void main(String[] args) throws Exception { int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); if(c>=a+b) { pw.println("No"); }else if(a==0||b==0||b==1){ if(c==0) { pw.println("Yes"); for(int i=0;i<b;i++)pw.print(1); for(int i=0;i<a;i++)pw.print(0); pw.println(); for(int i=0;i<b;i++)pw.print(1); for(int i=0;i<a;i++)pw.print(0); pw.println(); }else { pw.println("No"); } }else { if(c>=a+b-1) { pw.println("No"); }else { pw.println("Yes"); for(int i=0;i<b;i++)pw.print(1); for(int i=0;i<a;i++)pw.print(0); pw.println(); int[]ans=new int[a+b]; for(int i=a;i<a+b;i++) { if(i==a) { if(c<=a) { ans[a-c]=1; c=0; }else { ans[0]=1; c-=a; } }else { if(c>0) { ans[i-1]=1; c--; }else { ans[i]=1; } } } for(int i=a+b-1;i>-1;i--)pw.print(ans[i]); pw.println(); } } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Double(x).hashCode() * 31 + new Double(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } static long mod = 1000000007; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
1bc737d56b0e15ba429d8fd94c979874
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; ////*************************************************************************** /* public class E_Gardener_and_Tree implements Runnable{ public static void main(String[] args) throws Exception { new Thread(null, new E_Gardener_and_Tree(), "E_Gardener_and_Tree", 1<<28).start(); } public void run(){ WRITE YOUR CODE HERE!!!! JUST WRITE EVERYTHING HERE WHICH YOU WRITE IN MAIN!!! } } */ /////************************************************************************** public class D_Genius_s_Gambit{ public static void main(String[] args) { FastScanner s= new FastScanner(); //PrintWriter out=new PrintWriter(System.out); //end of program //out.println(answer); //out.close(); StringBuilder res = new StringBuilder(); int a=s.nextInt(); int b=s.nextInt(); int k=s.nextInt(); if(k==0){ StringBuilder res2 = new StringBuilder(); for(int i=0;i<b;i++){ res2.append("1"); } for(int i=0;i<a;i++){ res2.append("0"); } res.append("YES \n"); res.append(res2+" \n"); res.append(res2+" \n"); } else{ b--; if(a>0 && b==0){ res.append("NO \n"); } else if(a==0 && b>0){ res.append("NO \n"); } else if(a==0 && b==0){ res.append("NO \n"); } else{ int max=(a+b-2+1); // System.out.println(max+" max"); if(k>max){ res.append("NO \n"); } else{ StringBuilder res2 = new StringBuilder(); StringBuilder res3 = new StringBuilder(); int count=1; res2.append("0"); res3.append("1"); int yo1=0; a--; b--; while((yo1<a) &&(count<k)){ res2.append("0"); res3.append("0"); count++; yo1++; } int yo2=0; while((yo2<b) &&(count<k)){ res2.append("1"); res3.append("1"); count++; yo2++; } res2.append("1"); res3.append("0"); while(yo1<a){ res2.append("0"); res3.append("0"); yo1++; } while(yo2<b){ res2.append("1"); res3.append("1"); yo2++; } res2.append("1"); res3.append("1"); res2.reverse(); res3.reverse(); res.append("YES \n"); res.append(res2+" \n"); res.append(res3+" \n"); } } } System.out.println(res); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
8d8a5abf851cbd900bb4f625c47e985d
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; public final class Solution { static PrintWriter out = new PrintWriter(System.out); static FastReader in = new FastReader(); static long mod = (long) 1e9 + 7; static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(1, 0), new Pair(0, -1), new Pair(0, 1)}; //Find two binary integers 𝑥 and 𝑦 (𝑥≥𝑦) such that // //both 𝑥 and 𝑦 consist of 𝑎 zeroes and 𝑏 ones; //𝑥−𝑦 (also written in binary form) has exactly 𝑘 ones. public static void main(String[] args) { //int t = i(); int t = 1; while (t-- > 0) { int a = i(); int b = i(); int k = i(); if (b == 0) { printNo(); continue; } if (b == 1 && k > 0) { printNo(); continue; } if (k == 0) { printYes(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < b; i++) { sb.append(1); } for (int i = 0; i < a; i++) { sb.append(0); } out.println(sb.toString()); out.println(sb.toString()); continue; } if (a == 0) { printNo(); continue; } if (a + b >= k + 2) { printYes(); StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); for (int i = 0; i < b - 1; i++) { sb.append(1); sb2.append(1); } for (int i = 0; i < a - 1; i++) { sb.append(0); sb2.append(0); } sb.append(0); sb2.append(1); sb.insert(a + b - k - 1, 1); sb2.insert(a + b - k - 1, 0); out.println(sb.toString()); out.println(sb2.toString()); continue; } else { printNo(); continue; } } out.flush(); } static boolean isPS(double number) { double sqrt = Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static int sd(long i) { int d = 0; while (i > 0) { d += i % 10; i = i / 10; } return d; } static int[] leastPrime; static void sieveLinear(int N) { int[] primes = new int[N]; int idx = 0; leastPrime = new int[N + 1]; for (int i = 2; i <= N; i++) { if (leastPrime[i] == 0) { primes[idx++] = i; leastPrime[i] = i; } int curLP = leastPrime[i]; for (int j = 0; j < idx; j++) { int p = primes[j]; if (p > curLP || (long) p * i > N) { break; } else { leastPrime[p * i] = p; } } } } static int lower(long A[], long x) { int l = -1, r = A.length; while (r - l > 1) { int m = (l + r) / 2; if (A[m] >= x) { r = m; } else { l = m; } } return r; } static int upper(long A[], long x) { int l = -1, r = A.length; while (r - l > 1) { int m = (l + r) / 2; if (A[m] <= x) { l = m; } else { r = m; } } return l; } static void swap(int A[], int a, int b) { int t = A[a]; A[a] = A[b]; A[b] = t; } static int lowerBound(int A[], int low, int high, int x) { if (low > high) { if (x >= A[high]) { return A[high]; } } int mid = (low + high) / 2; if (A[mid] == x) { return A[mid]; } if (mid > 0 && A[mid - 1] <= x && x < A[mid]) { return A[mid - 1]; } if (x < A[mid]) { return lowerBound(A, low, mid - 1, x); } return lowerBound(A, mid + 1, high, x); } static long pow(long a, long b) { long pow = 1; long x = a; while (b != 0) { if ((b & 1) != 0) { pow = (pow * x) % mod; } x = (x * x) % mod; b /= 2; } return pow; } static boolean isPrime(long N) { if (N <= 1) { return false; } if (N <= 3) { return true; } if (N % 2 == 0 || N % 3 == 0) { return false; } for (int i = 5; i * i <= N; i = i + 6) { if (N % i == 0 || N % (i + 2) == 0) { return false; } } return true; } static void print(char A[]) { for (char c : A) { out.print(c); } out.println(); } static void print(boolean A[]) { for (boolean c : A) { out.print(c + " "); } out.println(); } static void print(int A[]) { for (int c : A) { out.print(c + " "); } out.println(); } static void print(long A[]) { for (long i : A) { out.print(i + " "); } out.println(); } static void print(List<Integer> A) { for (int a : A) { out.print(a + " "); } } static void printYes() { out.println("YES"); } static void printNo() { out.println("NO"); } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static String s() { return in.nextLine(); } static int[] input(int N) { int A[] = new int[N]; for (int i = 0; i < N; i++) { A[i] = in.nextInt(); } return A; } static long[] inputLong(int N) { long A[] = new long[N]; for (int i = 0; i < A.length; i++) { A[i] = in.nextLong(); } return A; } static int GCD(int a, int b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } static long GCD(long a, long b) { if (b == 0) { return a; } else { return GCD(b, a % b); } } } class BIT { int n; int[] tree; public BIT(int n) { this.n = n; this.tree = new int[n + 1]; } public static int lowbit(int x) { return x & (-x); } public void update(int x) { while (x <= n) { ++tree[x]; x += lowbit(x); } } public int query(int x) { int ans = 0; while (x > 0) { ans += tree[x]; x -= lowbit(x); } return ans; } public int query(int x, int y) { return query(y) - query(x - 1); } } class SegmentTree { long[] t; public SegmentTree(int n) { t = new long[n + n]; Arrays.fill(t, Long.MIN_VALUE); } public long get(int i) { return t[i + t.length / 2]; } public void add(int i, long value) { i += t.length / 2; t[i] = value; for (; i > 1; i >>= 1) { t[i >> 1] = Math.max(t[i], t[i ^ 1]); } } // max[a, b] public long max(int a, int b) { long res = Long.MIN_VALUE; for (a += t.length / 2, b += t.length / 2; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) { if ((a & 1) != 0) { res = Math.max(res, t[a]); } if ((b & 1) == 0) { res = Math.max(res, t[b]); } } return res; } } class Pair { int i, j; Pair(int i, int j) { this.i = i; this.j = j; } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
28ee58afd000afe818b3cd2e36f5a869
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class Main { private static final FastIO fastIO = new FastIO(); private static final String yes = "YES"; private static final String no = "NO"; public static void main(String[] args) { int a = fastIO.nextInt(); int b = fastIO.nextInt(); int k = fastIO.nextInt(); if(a == 0 && b == 1) fastIO.appendln((k == 0)? "YES\n1\n1" : no); else if(k > a + b - 2) fastIO.appendln(no); else compute(a, b, k); fastIO.printAll(); } public static void compute(int a, int b, int k){ int[] x = new int[a + b]; int[] y = new int[a + b]; int l = b - 1; int count = 0; for(int i = 0; i < b; i++){ x[i] = 1; y[i] = 1; } if(k <= a){ y[l] = 0; y[l + k] = 1; } else { k -= a; y[a + b - 1] = 1; y[l - k] = 0; } for(int i = 0; i < a + b; i++){ if(y[i] != 0) ++count; } if(y[0] != 0 && count == b){ fastIO.appendln(yes); out(x, a + b); out(y, a + b); } else fastIO.appendln(no); } public static void out(int[] ans, int max){ for(int i = 0; i < max; i++) fastIO.append(ans[i]); fastIO.appendln(); } private static class FastIO { private final BufferedReader in; private final StringBuilder out; private final char LINE_BREAK = '\n'; private StringTokenizer tokens; public FastIO() { in = new BufferedReader(new InputStreamReader(System.in)); out = new StringBuilder(); } public String next() { while (tokens == null || !tokens.hasMoreElements()) { try { tokens = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } } return tokens.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { String str = ""; try { str = in.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public FastIO append(Object... objects){ for(Object o: objects) out.append(o); return this; } public FastIO appendln(Object... objects){ return append(objects).append(LINE_BREAK); } public void printAll(){ System.out.println(out.toString()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
0479abb7fa3703495238eea4379bd156
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.awt.Point; public class CFTemplate { static final long MOD = 1000000007L; //static final long MOD2 = 1000000009L; //static final long MOD = 998244353L; //static final long INF = 500000000000L; static final int INF = 1100000000; static final int NINF = -100000; static FastScanner sc; static PrintWriter pw; static final int[][] dirs = {{-1,0},{1,0},{0,-1},{0,1}}; public static void main(String[] args) { sc = new FastScanner(); pw = new PrintWriter(System.out); int A = sc.ni(); int B = sc.ni()-1; int K = sc.ni(); int N = A+B+1; int[] X = new int[N]; X[0] = 1; int[] Y = new int[N]; Y[0] = 1; if (K==0) { //X==Y for (int i = 0; i < B; i++) { X[i+1] = 1; Y[i+1] = 1; } } else if (A==0 || B==0 || K >= A+B) { pw.println("No"); pw.close(); return; } else { for (int i = 0; i < B; i++) { X[i+1] = 1; Y[i+1] = 1; } for (int i = 1; i < N-K; i++) { if (Y[i]==1 && Y[i+K]==0) { Y[i] = 0; Y[i+K] = 1; break; } } } pw.println("Yes"); for (int x: X) pw.print(x); pw.println(); for (int y: Y) pw.print(y); pw.println(); pw.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in), 32768); st = null; } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } int[] intArray(int N, int mod) { int[] ret = new int[N]; for (int i = 0; i < N; i++) ret[i] = ni()+mod; return ret; } long nl() { return Long.parseLong(next()); } long[] longArray(int N, long mod) { long[] ret = new long[N]; for (int i = 0; i < N; i++) ret[i] = nl()+mod; return ret; } double nd() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
e99dc580e1149c15aba34b3bea934f65
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; public class CF704 { static int a, b, k; public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); PrintWriter out = new PrintWriter(System.out); a = Integer.parseInt(st.nextToken()); b = Integer.parseInt(st.nextToken()); k = Integer.parseInt(st.nextToken()); if (a == 0 || b == 1 || k == 0) { if (k != 0) out.println("No"); else { out.println("Yes"); for (int j = 0; j < 2; ++j) { for (int i = 0; i < b; ++i) out.print(1); for (int i = 0; i < a; ++i) out.print(0); out.println(); } } out.close(); System.exit(0); } if (a + b - 2 < k) { out.print("No"); out.close(); System.exit(0); } out.println("Yes"); if (k == 1) { for (int i = 0; i < b - 1; ++i) out.print(1); for (int i = 0; i < a - 1; ++i) out.print(0); out.println("10"); for (int i = 0; i < b - 1; ++i) out.print(1); for (int i = 0; i < a - 1; ++i) out.print(0); out.println("01"); out.close(); return; } int cnta = a - 1, cntb = b - 2; out.print(11); for (int i = 0; i < k - 1; ++i) { if (cnta == 0) { --cntb; out.print(1); } else { out.print(0);; --cnta; } } out.print(0); while (cnta-- > 0) out.print(0); while (cntb-- > 0) out.print(1); out.println(); cnta = a - 1; cntb = b - 2; out.print(10); for (int i = 0; i < k - 1; ++i) { if (cnta == 0) { --cntb; out.print(1); } else { out.print(0);; --cnta; } } out.print(1); while (cnta-- > 0) out.print(0); while (cntb-- > 0) out.print(1); out.println(); out.close(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 8
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
dda323c786a23b20883bfea677d64298
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public final class D { public static void main(String[] args) { final FastScanner fs = new FastScanner(); final int a = fs.nextInt(); final int b = fs.nextInt(); final int k = fs.nextInt(); if (k == 0) { final char[] l = new char[a + b]; final char[] r = new char[a + b]; Arrays.fill(l, '0'); Arrays.fill(r, '0'); for (int i = 0; i < b; i++) { l[i] = r[i] = '1'; } System.out.println("Yes"); System.out.println(l); System.out.println(r); return; } if (a == 0 || b == 1 || k > (a + b - 2)) { System.out.println("No"); return; } final char[] l = new char[a + b]; final char[] r = new char[a + b]; Arrays.fill(l, '0'); Arrays.fill(r, '0'); for (int i = 0; i < b; i++) { l[i] = r[i] = '1'; } if (0 <= k && k <= a) { r[b - 1] = '0'; r[b + k - 1] = '1'; } else { r[a + b - 1 - k] = '0'; r[a + b - 1] = '1'; } System.out.println("Yes"); System.out.println(l); System.out.println(r); } static final class Utils { private static class Shuffler { private static void shuffle(int[] x) { final Random r = new Random(); for (int i = 0; i <= x.length - 2; i++) { final int j = i + r.nextInt(x.length - i); swap(x, i, j); } } private static void shuffle(long[] x) { final Random r = new Random(); for (int i = 0; i <= x.length - 2; i++) { final int j = i + r.nextInt(x.length - i); swap(x, i, j); } } private static void swap(int[] x, int i, int j) { final int t = x[i]; x[i] = x[j]; x[j] = t; } private static void swap(long[] x, int i, int j) { final long t = x[i]; x[i] = x[j]; x[j] = t; } } public static void shuffleSort(int[] arr) { Shuffler.shuffle(arr); Arrays.sort(arr); } public static void shuffleSort(long[] arr) { Shuffler.shuffle(arr); Arrays.sort(arr); } private Utils() {} } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); private String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { //noinspection CallToPrintStackTrace e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { final int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } long[] nextLongArray(int n) { final long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
ac5ad8fd45ffadea12586b776da45b43
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public final class D { public static void main(String[] args) { final FastScanner fs = new FastScanner(); final int a = fs.nextInt(); final int b = fs.nextInt(); final int k = fs.nextInt(); if (k == 0) { final char[] l = new char[a + b]; final char[] r = new char[a + b]; Arrays.fill(l, '0'); Arrays.fill(r, '0'); for (int i = 0; i < b; i++) { l[i] = r[i] = '1'; } System.out.println("Yes"); System.out.println(l); System.out.println(r); return; } if (a == 0 || b == 1 || k > (a + b - 2)) { System.out.println("No"); return; } final char[] l = new char[a + b]; final char[] r = new char[a + b]; Arrays.fill(l, '0'); Arrays.fill(r, '0'); for (int i = 0; i < b; i++) { l[i] = r[i] = '1'; } if (0 <= k && k <= a) { r[b - 1] = '0'; r[b + k - 1] = '1'; } else { final int zero = a + b - 1 - k; r[zero] = '0'; r[a + b - 1] = '1'; } System.out.println("Yes"); System.out.println(l); System.out.println(r); } static final class Utils { private static class Shuffler { private static void shuffle(int[] x) { final Random r = new Random(); for (int i = 0; i <= x.length - 2; i++) { final int j = i + r.nextInt(x.length - i); swap(x, i, j); } } private static void shuffle(long[] x) { final Random r = new Random(); for (int i = 0; i <= x.length - 2; i++) { final int j = i + r.nextInt(x.length - i); swap(x, i, j); } } private static void swap(int[] x, int i, int j) { final int t = x[i]; x[i] = x[j]; x[j] = t; } private static void swap(long[] x, int i, int j) { final long t = x[i]; x[i] = x[j]; x[j] = t; } } public static void shuffleSort(int[] arr) { Shuffler.shuffle(arr); Arrays.sort(arr); } public static void shuffleSort(long[] arr) { Shuffler.shuffle(arr); Arrays.sort(arr); } private Utils() {} } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); private String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { //noinspection CallToPrintStackTrace e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { final int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } long[] nextLongArray(int n) { final long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
deaa5faae773038500288a48eab51249
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.StringTokenizer; public final class D { public static void main(String[] args) { final FastScanner fs = new FastScanner(); final int a = fs.nextInt(); final int b = fs.nextInt(); int k = fs.nextInt(); if (k == 0) { final char[] l = new char[a + b]; final char[] r = new char[a + b]; Arrays.fill(l, '0'); Arrays.fill(r, '0'); for (int i = 0; i < b; i++) { l[i] = r[i] = '1'; } System.out.println("Yes"); System.out.println(l); System.out.println(r); return; } if (a == 0 || b == 1 || k >= (a + b - 1)) { System.out.println("No"); } else { final char[] l = new char[a + b]; final char[] r = new char[a + b]; Arrays.fill(l, '0'); Arrays.fill(r, '0'); for (int i = 0; i < b; i++) { l[i] = '1'; } if (0 <= k && k <= a) { for (int i = 0; i < b - 1; i++) { r[i] = '1'; } r[b + k - 1] = '1'; } else { r[a + b - 1] = '1'; k -= a; int ll = b - 1 - k; int idx = 0; for (int i = 0; i < ll; i++) { r[idx++] = '1'; } idx++; for (int i = 0; i < k; i++) { r[idx++] = '1'; } } System.out.println("Yes"); System.out.println(l); System.out.println(r); } // System.out.println(Integer.toBinaryString(56)); // System.out.println(Integer.toBinaryString(35)); // System.out.println(Integer.toBinaryString(56 - 35)); // test(); } // 1111111100 // 1011111110 private static void test() { final int a = 1; final int b = 1; final List<Integer> l = new ArrayList<>(); for (int i = 0; i < (1 << 2); i++) { if (Integer.bitCount(i) == 2) { l.add((1 << 2) | i); } } for (int num : l) { for (int num2 : l) { if (num >= num2) { // if (num2 == 67) { System.out.println( Integer.bitCount(num - num2) + " " + Integer.toBinaryString(num) + " " + Integer .toBinaryString(num2)); // } } } } } static final class Utils { private static class Shuffler { private static void shuffle(int[] x) { final Random r = new Random(); for (int i = 0; i <= x.length - 2; i++) { final int j = i + r.nextInt(x.length - i); swap(x, i, j); } } private static void shuffle(long[] x) { final Random r = new Random(); for (int i = 0; i <= x.length - 2; i++) { final int j = i + r.nextInt(x.length - i); swap(x, i, j); } } private static void swap(int[] x, int i, int j) { final int t = x[i]; x[i] = x[j]; x[j] = t; } private static void swap(long[] x, int i, int j) { final long t = x[i]; x[i] = x[j]; x[j] = t; } } public static void shuffleSort(int[] arr) { Shuffler.shuffle(arr); Arrays.sort(arr); } public static void shuffleSort(long[] arr) { Shuffler.shuffle(arr); Arrays.sort(arr); } private Utils() {} } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); private String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { //noinspection CallToPrintStackTrace e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] nextIntArray(int n) { final int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } long[] nextLongArray(int n) { final long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
58a4e95b3bb4f9efd0eeff8393d88bc9
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class D { BufferedReader input; BufferedWriter output; StringTokenizer st; // My Solution void solve() throws IOException { int zeroes = getInt(); int ones = getInt()-1; int k = getInt(); if(k==0){ StringBuilder s = new StringBuilder(); ones++; int limit = zeroes+ones; for (int i = 0; i < limit; i++) { if(ones>0){ s.append(1); ones--; }else { s.append(0); } } print("Yes\n"+s.toString()+"\n"+s.toString()); }else { StringBuilder xBuilder = new StringBuilder(); StringBuilder yBuilder = new StringBuilder(); zeroes--; ones--; if(k-1>zeroes+ones || ones<0 || zeroes<0){ print("No"); }else { int i=0; while (ones>0 || zeroes>0 || i<=k+1){ if(i==0){ xBuilder.append(1); yBuilder.append(1); }else if(i==1){ xBuilder.append(1); yBuilder.append(0); }else if(i==k+1){ xBuilder.append(0); yBuilder.append(1); }else if(ones>0){ xBuilder.append(1); yBuilder.append(1); ones--; }else if(zeroes>0){ xBuilder.append(0); yBuilder.append(0); zeroes--; } i++; } print("Yes\n"+xBuilder.toString()+"\n"+yBuilder.toString()); } } } // Some basic functions int min(int...i){ int min = Integer.MAX_VALUE; for (int value : i) min = Math.min(min, value); return min; } int max(int...i){ int max = Integer.MIN_VALUE; for (int value : i) max = Math.max(max, value); return max; } // Printing stuff void print(int... i) throws IOException { for (int value : i) output.write(value + " "); } void print(long... l) throws IOException { for (long value : l) output.write(value + " "); } void print(String... s) throws IOException { for (String value : s) output.write(value); } void nextLine() throws IOException { output.write("\n"); } // Taking Inputs int[][] getIntMat(int n, int m) throws IOException { int[][] mat = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mat[i][j] = getInt(); return mat; } char[][] getCharMat(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) { String s = input.readLine(); for (int j = 0; j < m; j++) mat[i][j] = s.charAt(j); } return mat; } int getInt() throws IOException { if(st ==null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine()); return Integer.parseInt(st.nextToken()); } int[] getInts(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = getInt(); return a; } long getLong() throws IOException { if(st==null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine()); return Long.parseLong(st.nextToken()); } long[] getLongs(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = getLong(); return a; } // Checks whether the code is running on OnlineJudge or LocalSystem boolean isOnlineJudge() { if (System.getProperty("ONLINE_JUDGE") != null) return true; try { return System.getProperty("LOCAL")==null; } catch (Exception e) { return true; } } // Handling CodeExecution public static void main(String[] args) throws Exception { new D().run(); } void run() throws IOException { // Defining Input Streams if (isOnlineJudge()) { input = new BufferedReader(new InputStreamReader(System.in)); output = new BufferedWriter(new OutputStreamWriter(System.out)); } else { input = new BufferedReader(new FileReader("input.txt")); output = new BufferedWriter(new FileWriter("output.txt")); } // Running Logic solve(); output.flush(); // Run example test cases if (!isOnlineJudge()) { BufferedReader output = new BufferedReader(new FileReader("output.txt")); BufferedReader answer = new BufferedReader(new FileReader("answer.txt")); StringBuilder outFile = new StringBuilder(); StringBuilder ansFile = new StringBuilder(); String temp; while ((temp = output.readLine()) != null) outFile.append(temp.trim()); while ((temp = answer.readLine()) != null) ansFile.append(temp.trim()); if (outFile.toString().equals(ansFile.toString())) System.out.println("Test Cases Passed!!!"); else System.out.println("Failed..."); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
c60134255b0ed761a54eb07c347264a7
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class D { BufferedReader input; BufferedWriter output; StringTokenizer st; // My Solution void solve() throws IOException { int zeroes = getInt(); int ones = getInt()-1; int k = getInt(); if(k==0){ StringBuilder s = new StringBuilder(); ones++; int limit = zeroes+ones; for (int i = 0; i < limit; i++) { if(ones>0){ s.append(1); ones--; }else { s.append(0); } } print("Yes\n"+s.toString()+"\n"+s.toString()); }else { StringBuilder xBuilder = new StringBuilder(); StringBuilder yBuilder = new StringBuilder(); zeroes--; ones--; if(k-1>zeroes+ones || ones<0 || zeroes<0){ print("No"); }else { int i=0; while (ones>0 || zeroes>0 || i<5 || i==k+1){ if(i==0){ xBuilder.append(1); yBuilder.append(1); }else if(i==1){ xBuilder.append(1); yBuilder.append(0); }else if(i==k+1){ xBuilder.append(0); yBuilder.append(1); }else{ if(ones>0){ xBuilder.append(1); yBuilder.append(1); ones--; }else if(zeroes>0){ xBuilder.append(0); yBuilder.append(0); zeroes--; } } i++; } print("Yes\n"+xBuilder.toString()+"\n"+yBuilder.toString()); } } } // Some basic functions int min(int...i){ int min = Integer.MAX_VALUE; for (int value : i) min = Math.min(min, value); return min; } int max(int...i){ int max = Integer.MIN_VALUE; for (int value : i) max = Math.max(max, value); return max; } // Printing stuff void print(int... i) throws IOException { for (int value : i) output.write(value + " "); } void print(long... l) throws IOException { for (long value : l) output.write(value + " "); } void print(String... s) throws IOException { for (String value : s) output.write(value); } void nextLine() throws IOException { output.write("\n"); } // Taking Inputs int[][] getIntMat(int n, int m) throws IOException { int[][] mat = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mat[i][j] = getInt(); return mat; } char[][] getCharMat(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) { String s = input.readLine(); for (int j = 0; j < m; j++) mat[i][j] = s.charAt(j); } return mat; } int getInt() throws IOException { if(st ==null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine()); return Integer.parseInt(st.nextToken()); } int[] getInts(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = getInt(); return a; } long getLong() throws IOException { if(st==null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine()); return Long.parseLong(st.nextToken()); } long[] getLongs(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = getLong(); return a; } // Checks whether the code is running on OnlineJudge or LocalSystem boolean isOnlineJudge() { if (System.getProperty("ONLINE_JUDGE") != null) return true; try { return System.getProperty("LOCAL")==null; } catch (Exception e) { return true; } } // Handling CodeExecution public static void main(String[] args) throws Exception { new D().run(); } void run() throws IOException { // Defining Input Streams if (isOnlineJudge()) { input = new BufferedReader(new InputStreamReader(System.in)); output = new BufferedWriter(new OutputStreamWriter(System.out)); } else { input = new BufferedReader(new FileReader("input.txt")); output = new BufferedWriter(new FileWriter("output.txt")); } // Running Logic solve(); output.flush(); // Run example test cases if (!isOnlineJudge()) { BufferedReader output = new BufferedReader(new FileReader("output.txt")); BufferedReader answer = new BufferedReader(new FileReader("answer.txt")); StringBuilder outFile = new StringBuilder(); StringBuilder ansFile = new StringBuilder(); String temp; while ((temp = output.readLine()) != null) outFile.append(temp.trim()); while ((temp = answer.readLine()) != null) ansFile.append(temp.trim()); if (outFile.toString().equals(ansFile.toString())) System.out.println("Test Cases Passed!!!"); else System.out.println("Failed..."); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
076089c78d8d93d5680ba8b7c5fd191e
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class D { BufferedReader input; BufferedWriter output; StringTokenizer st; // My Solution void solve() throws IOException { int zeroes = getInt(); int ones = getInt()-1; int k = getInt(); if(k==0){ StringBuilder s = new StringBuilder(); ones++; int limit = zeroes+ones; for (int i = 0; i < limit; i++) { if(ones>0){ s.append(1); ones--; }else { s.append(0); } } print("Yes\n"+s.toString()+"\n"+s.toString()); }else { StringBuilder xBuilder = new StringBuilder(); StringBuilder yBuilder = new StringBuilder(); xBuilder.append(1); yBuilder.append(0); zeroes--; ones--; if(k-1>zeroes+ones || ones<0 || zeroes<0){ print("No"); }else { for(int i=0; i<k-1; i++){ if(ones>0){ xBuilder.append(1); yBuilder.append(1); ones--; }else { xBuilder.append(0); yBuilder.append(0); zeroes--; } } xBuilder.append(0); yBuilder.append(1); StringBuilder exBuilder = new StringBuilder(); StringBuilder eyBuilder = new StringBuilder(); int limit = zeroes+ones; for(int i=0; i<limit; i++){ if(ones>0){ exBuilder.append(1); eyBuilder.append(1); ones--; }else { exBuilder.append(0); eyBuilder.append(0); zeroes--; } } String x = "1"+xBuilder.toString()+exBuilder.toString(); String y = "1"+yBuilder.toString()+eyBuilder.toString(); print("Yes\n"+x+"\n"+y); } } } // Some basic functions int min(int...i){ int min = Integer.MAX_VALUE; for (int value : i) min = Math.min(min, value); return min; } int max(int...i){ int max = Integer.MIN_VALUE; for (int value : i) max = Math.max(max, value); return max; } // Printing stuff void print(int... i) throws IOException { for (int value : i) output.write(value + " "); } void print(long... l) throws IOException { for (long value : l) output.write(value + " "); } void print(String... s) throws IOException { for (String value : s) output.write(value); } void nextLine() throws IOException { output.write("\n"); } // Taking Inputs int[][] getIntMat(int n, int m) throws IOException { int[][] mat = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mat[i][j] = getInt(); return mat; } char[][] getCharMat(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) { String s = input.readLine(); for (int j = 0; j < m; j++) mat[i][j] = s.charAt(j); } return mat; } int getInt() throws IOException { if(st ==null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine()); return Integer.parseInt(st.nextToken()); } int[] getInts(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = getInt(); return a; } long getLong() throws IOException { if(st==null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine()); return Long.parseLong(st.nextToken()); } long[] getLongs(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = getLong(); return a; } // Checks whether the code is running on OnlineJudge or LocalSystem boolean isOnlineJudge() { if (System.getProperty("ONLINE_JUDGE") != null) return true; try { return System.getProperty("LOCAL")==null; } catch (Exception e) { return true; } } // Handling CodeExecution public static void main(String[] args) throws Exception { new D().run(); } void run() throws IOException { // Defining Input Streams if (isOnlineJudge()) { input = new BufferedReader(new InputStreamReader(System.in)); output = new BufferedWriter(new OutputStreamWriter(System.out)); } else { input = new BufferedReader(new FileReader("input.txt")); output = new BufferedWriter(new FileWriter("output.txt")); } // Running Logic solve(); output.flush(); // Run example test cases if (!isOnlineJudge()) { BufferedReader output = new BufferedReader(new FileReader("output.txt")); BufferedReader answer = new BufferedReader(new FileReader("answer.txt")); StringBuilder outFile = new StringBuilder(); StringBuilder ansFile = new StringBuilder(); String temp; while ((temp = output.readLine()) != null) outFile.append(temp.trim()); while ((temp = answer.readLine()) != null) ansFile.append(temp.trim()); if (outFile.toString().equals(ansFile.toString())) System.out.println("Test Cases Passed!!!"); else System.out.println("Failed..."); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
dd0f0da0890c472690c22144db0bedad
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
/* ID: abdelra29 LANG: JAVA PROG: zerosum */ /* TO LEARN 2-euler tour */ /* TO SOLVE */ /* bit manipulation shit 1-Computer Systems: A Programmer's Perspective 2-hacker's delight */ /* TO WATCH */ import java.util.*; import java.math.*; import java.io.*; import java.util.stream.Collectors; public class A{ static FastScanner scan=new FastScanner(); public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); static int countBits(int number) { return (int)(Math.log(number) / Math.log(2) + 1); } public static void main(String[] args) throws Exception { /* very important tips 1-just fucking think backwards once in your shitty life 2-consider brute forcing and finding some patterns and observations 3-when you're in contest don't get out because you think there is no enough time 4-don't get stuck on one approach */ // File file=new File("D:\\input\\out.txt"); //scan=new FastScanner("halfnice.in"); // out = new PrintWriter("moop.out"); /* READING 3-Introduction to DP with Bitmasking codefoces 4-Bit Manipulation hackerearth 5-read more about mobious and inculsion-exclusion 6-read more about fermat little theorem */ //System.out.println(0^1^1); int tt =1; //cal(100,110,12); // tt=scan.nextInt(); int T=1; outer:while(tt-->0) { int a=scan.nextInt(),b=scan.nextInt(),k=scan.nextInt(); int tmpB=b; /* for(int i=1;i<=10000;i++) { for(int j=1;j<=i;j++) { if(countBits(i)-Integer.bitCount(i)==a&&Integer.bitCount(i)==b&&countBits(j)-Integer.bitCount(j)==a&&Integer.bitCount(j)==b) { // out.println(Integer.bitCount(i-j)); if(Integer.bitCount(i-j)==k) { out.println(i+" "+j+" "+Integer.toBinaryString(i)+" "+Integer.toBinaryString(j)+" "+Integer.toBinaryString(i- j)); } } } }*/ // Integer.toBinaryString(64); if(k==0) { StringBuilder res1=new StringBuilder(""); StringBuilder res2=new StringBuilder(""); for(int i=0;i<b;i++) res1.append("1"); for(int i=0;i<a;i++) res1.append("0"); for(int i=0;i<b;i++) res2.append("1"); for(int i=0;i<a;i++) res2.append("0"); out.println("Yes"); out.println(res1); out.println(res2); out.close(); return; } StringBuilder res1=new StringBuilder("0"); StringBuilder res2=new StringBuilder("1"); k--; a--; if(a<0) { out.println("No"); out.close(); return; } ArrayDeque<Character>deq1=new ArrayDeque<Character>(); ArrayDeque<Character>deq2=new ArrayDeque<Character>(); deq1.addFirst('0'); deq2.addFirst('1'); while(k>0&&a>0) { deq1.addFirst('0'); deq2.addFirst('0'); a--; k--; } if(k>0) { while(k>0) { deq2.addFirst('1'); deq1.addFirst('1'); b--; k--; } b--; deq1.addFirst('1'); deq2.addFirst('0'); if(b<=0) { out.println("No"); out.close(); return ; } while(b>0) { deq1.addFirst('1'); deq2.addFirst('1'); b--; } out.println("Yes"); res1=new StringBuilder(""); res2=new StringBuilder(""); for(char c:deq1) res1.append(c); for(char c:deq2) res2.append(c); out.println(res1); out.println(res2); out.close(); return; } deq1.addFirst('1'); deq2.addFirst('0'); // a--; b--; if(a>0&&b<=0) { out.println("No"); out.close(); return; } if(a<0) { out.println("No"); out.close(); return; } while(a>0) { deq1.addFirst('0'); deq2.addFirst('0'); a--; } if(b<=0) { out.println("No"); out.close(); return; } while(b>0) { deq1.addFirst('1'); deq2.addFirst('1'); b--; } out.println("Yes"); res1=new StringBuilder(""); res2=new StringBuilder(""); for(char c:deq1) res1.append(c); for(char c:deq2) res2.append(c); out.println(res1); out.println(res2); } out.close(); } static class special implements Comparable<special>{ int cnt,idx; String s; public special(int cnt,int idx,String s) { this.cnt=cnt; this.idx=idx; this.s=s; } @Override public int hashCode() { return (int)42; } @Override public boolean equals(Object o){ // System.out.println("FUCK"); if (o == this) return true; if (o.getClass() != getClass()) return false; special t = (special)o; return t.cnt == cnt && t.idx == idx; } public int compareTo(special o1) { if(o1.cnt==cnt) { return o1.idx-idx; } return o1.cnt-cnt; } } static long binexp(long a,long n) { if(n==0) return 1; long res=binexp(a,n/2); if(n%2==1) return res*res*a; else return res*res; } static long powMod(long base, long exp, long mod) { if (base == 0 || base == 1) return base; if (exp == 0) return 1; if (exp == 1) return (base % mod+mod)%mod; long R = (powMod(base, exp/2, mod) % mod+mod)%mod; R *= R; R %= mod; if ((exp & 1) == 1) { return (base * R % mod+mod)%mod; } else return (R %mod+mod)%mod; } static double dis(double x1,double y1,double x2,double y2) { return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } static long mod(long x,long y) { if(x<0) x=x+(-x/y+1)*y; return x%y; } public static long pow(long b, long e) { long r = 1; while (e > 0) { if (e % 2 == 1) r = r * b ; b = b * b; e >>= 1; } return r; } private static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int object : arr) list.add(object); Collections.sort(list); //Collections.reverse(list); for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i); } private static void sort2(long[] arr) { List<Long> list = new ArrayList<>(); for (Long object : arr) list.add(object); Collections.sort(list); Collections.reverse(list); for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i); } static class FastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } } static class Pair implements Comparable<Pair>{ public long x, y,z; public Pair(long x1, long y1,long z1) { x=x1; y=y1; z=z1; } public Pair(long x1, long y1) { x=x1; y=y1; } @Override public int hashCode() { return (int)(x + 31 * y); } public String toString() { return x + " " + y+" "+z; } @Override public boolean equals(Object o){ if (o == this) return true; if (o.getClass() != getClass()) return false; Pair t = (Pair)o; return t.x == x && t.y == y&&t.z==z; } public int compareTo(Pair o) { return (int)(x-o.x); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
56014080ef187387cd7d251d4364bf20
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; // THIS TEMPLATE MADE BY AKSH BANSAL. public class Solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static void sort(int a[]){ // int -> long ArrayList<Integer> arr=new ArrayList<>(); // Integer -> Long for(int i=0;i<a.length;i++) arr.add(a[i]); Collections.sort(arr); for(int i=0;i<a.length;i++) a[i]=arr.get(i); } private static long gcd(long a, long b){ if(b==0)return a; return gcd(b,a%b); } private static long pow(long x,long y){ if(y==0)return 1; long temp = pow(x, y/2); if(y%2==1){ return x*temp*temp; } else{ return temp*temp; } } static int log(long n){ int res = 0; while(n>0){ res++; n/=2; } return res; } static int mod = (int)1e9+7; static PrintWriter out; static FastReader sc ; public static void main(String[] args) throws IOException { sc = new FastReader(); out = new PrintWriter(System.out); // primes(); // ________________________________ int n = sc.nextInt(); int m = sc.nextInt(); int k = sc.nextInt(); solver(n, m, k); // ________________________________ out.flush(); } // a -> 1s & b -> 0s public static void solver(int b, int a, int k) { if(k==0){ out.println("YES"); String s = "1".repeat(a)+"0".repeat(b); out.println(s); out.println(s); return; } if(k>a+b-2 || a<2 || b<=0){ out.println("NO"); return; } out.println("YES"); StringBuilder x = new StringBuilder("1"); StringBuilder y = new StringBuilder("1"); a--; x.append("1"); y.append("0"); a-=1; b-=1; for(int i=0;i<k-1;i++){ if(a>0){ x.append("1"); y.append("1"); a--; } else{ x.append("0"); y.append("0"); b--; } } x.append("0"); y.append("1"); while(a-->0){ x.append("1"); y.append("1"); } while(b-->0){ x.append("0"); y.append("0"); } out.println(x); out.println(y); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
8a4c61c69bcc3b831c350f911781c5dd
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; public class Solve{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int zero=sc.nextInt(); int one=sc.nextInt(); int k=sc.nextInt(); if(zero==0 && one==1 && k==1) { System.out.println("YES"); System.out.println("10"+"\n"+"01"); } else{ if((k>(zero+one-2) && k!=0) || (one==1&&k!=0) || (zero==0 && k!=0)) { System.out.println("NO"); } else { char[] x=new char[zero+one]; int val=one; for(int i=0;i<x.length;i++) { if(val>=1) { x[i]='1'; val--; } else { x[i]='0'; } } char[] y=Arrays.copyOf(x,x.length); if(one+Math.min(zero, k)-1<y.length-1) { y[one-1]='0'; y[one+Math.min(zero, k)-1]='1'; // System.out.println("YES"); System.out.println(x); System.out.println(y); } else { y[y.length-k-1]='0'; y[y.length-1]='1'; System.out.println("YES"); System.out.println(x); System.out.println(y); } } } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
c2afba88f12100599d8f2bf056fc75cc
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; public class Solve{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int zero=sc.nextInt(); int one=sc.nextInt(); int k=sc.nextInt(); if(zero==0 && one==1 && k==1) { System.out.println("YES"); System.out.println("10"+"\n"+"01"); } else{ if((k>(zero+one-2) && k!=0) || (one==1&&k!=0) || (zero==0 && k!=0)) { System.out.println("NO"); } else { char[] x=new char[zero+one]; int val=one; for(int i=0;i<x.length;i++) { if(val>=1) { x[i]='1'; val--; } else { x[i]='0'; } } char[] y=Arrays.copyOf(x,x.length); int pos=0; for(int i=y.length-1;i>=0;i--) { if(y[i]=='1') { pos=i; break; } } int t=pos; int inc=t+1; if(one+Math.min(zero, k)-1<y.length-1) { y[one-1]='0'; y[one+Math.min(zero, k)-1]='1'; System.out.println("YES"); System.out.println(x); System.out.println(y); } else { y[y.length-k-1]='0'; y[y.length-1]='1'; System.out.println("YES"); System.out.println(x); System.out.println(y); } } } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
18e06c80bb554ac1ec92784042ee688d
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
//@author->.....future_me......// //..............Learning.........// /*Compete against yourself*/ import java.util.*; import java.io.*; import java.lang.*; import java.math.BigInteger; public class D { // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< // static FastReader sc = new FastReader(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws Exception { // try { // int t = sc.nextInt(); // while (t-- > 0) D.go(); out.flush(); // } catch (Exception e) { // return; // } } static void go() { int a=sc.nextInt(); int b=sc.nextInt(); int k=sc.nextInt(); StringBuilder y=new StringBuilder(""); StringBuilder kk=new StringBuilder(""); int temp1=b,temp2=a; while(temp1>0) { y.append("1"); temp1--; } while(temp2>0) { y.append("0"); temp2--; } if(k==0) { out.println("Yes"); out.println(y); out.println(y); return; } if(a+b-2<k) { out.println("No"); return; } if(b==1&&k>0||a==0) { out.println("No"); return; } char ans[]=y.toString().toCharArray(); int id=0; for(int i=0;i<ans.length-1;i++) { if(ans[i]!=ans[i+1]) { id=i; break; } } if(k<=a) { ans[id]='0'; for(int i=0;i<k;i++) { id++; } ans[id]='1'; }else { int i=id; for( i=id;i>=0&&a-i+id+1<=k;i--) { } ans[i]='0'; ans[i+k]='1'; // ans[id+k]='1'; } out.println("Yes"); out.println(y); // out.println(convert(y.toString())+" "+convert(String.valueOf(ans))); // // out.print(ans[ans.length-1]); // out.println(convert(y.toString())-convert(String.valueOf(ans))); // out.println(Long.toBinaryString(convert(y.toString())-convert(String.valueOf(ans)))); out.println(String.valueOf(ans)); } static boolean check(long x,int a,int b) { String s=Long.toBinaryString(x); int count=0; int c=0; for(int i=0;i<s.length();i++) { if((s.charAt(i)-'0')==1) { count++; }else { c++; } } if(count==b&&c==a) { return true; } return false; } static long convert(String x) { long two=0; for(int i=0;i<x.length();i++) { two=two+pow(2,x.length()-1-i)*(x.charAt(i)-'0'); } return two; } // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< // static void sort(long[] a) { ArrayList<Long> aa = new ArrayList<>(); for (long i : a) { aa.add(i); } Collections.sort(aa); for (int i = 0; i < a.length; i++) a[i] = aa.get(i); } static long pow(long x, long y) { long res = 1l; while (y != 0) { if (y % 2 == 1) { res = x * res; } y /= 2; x = x * x; } return res; } //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st== null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
5f06d95e8b5a01f5b06fb9a3b91985d0
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; public class codeforces { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String x[]=br.readLine().split(" "); int a=Integer.parseInt(x[0]); int b=Integer.parseInt(x[1]); int k=Integer.parseInt(x[2]); if((k>(a+b-2) && k!=0) || (b==1&&k!=0) || (a==0 && k!=0)) { System.out.println("NO"); return; } int s[]=new int[a+b]; int t[]=new int[a+b]; int i; int len=a+b; for(i=0;i<b;i++) { s[i]=1; t[i]=1; } if(b+Math.min(a, k)-1<len-1) { t[b-1]=0; t[b+Math.min(a, k)-1]=1; } else { t[len-k-1]=0; t[len-1]=1; } System.out.println("YES"); for(i=0;i<len;i++) { System.out.print(s[i]); } System.out.println(); for(i=0;i<len;i++) { System.out.print(t[i]); } System.out.println(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
7132f03a166c666cd9634e5e68d894c8
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class fourth { public static void main(String[] args) { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { // System.err.println("Error"); // System.out.println("Error"); } Scanner sc = new Scanner(System.in); int t = 1; while(t-->0){ int a = sc.nextInt(); int b= sc.nextInt(); int k = sc.nextInt(); char s1[] = new char[a+b]; char s2[] = new char[a+b]; int i = 0; int p = b; while(p-->0){ s1[i] = '1'; s2[i] = '1'; i++; } int j = i-1; p = a; while(p-->0){ s1[i] = '0'; s2[i] = '0'; i++; } if(k==0){ System.out.println("Yes"); System.out.println(new String(s1)); System.out.println(new String(s2)); continue; } if(a==0 || k>(a+b-2)) { System.out.println("No"); continue; } p = a+b-1; while(s1[p]=='0'){ if(p-k>0 && s1[p-k]=='1'){ s2[p-k]='0'; s2[p] = '1'; System.out.println("Yes"); System.out.println(new String(s1)); System.out.println(new String(s2)); break; } else{ p--; } } if(s1[p]=='0') continue; else{ System.out.println("No"); continue; } } sc.close(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
a6ca766523bab84b65269afc0de43fca
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class fourth { public static void main(String[] args) { try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { // System.err.println("Error"); // System.out.println("Error"); } Scanner sc = new Scanner(System.in); int t = 1; while(t-->0){ int a = sc.nextInt(); int b= sc.nextInt(); int k = sc.nextInt(); char s1[] = new char[a+b]; char s2[] = new char[a+b]; int i = 0; int p = b; while(p-->0){ s1[i] = '1'; s2[i] = '1'; i++; } int j = i-1; p = a; while(p-->0){ s1[i] = '0'; s2[i] = '0'; i++; } if(k==0){ System.out.println("Yes"); System.out.println(new String(s1)); System.out.println(new String(s2)); continue; } if(a==0 || k>(a+b-2)) { System.out.println("No"); continue; } p = a+b-1; while(s1[p]=='0'){ if(p-k>0 && s1[p-k]=='1'){ s2[p-k]='0'; s2[p] = '1'; System.out.println("Yes"); System.out.println(new String(s1)); System.out.println(new String(s2)); break; } else{ p--; } } if(s1[p]=='0' && p-k>0 && s1[p-k]=='1') continue; else{ System.out.println("No"); continue; } } sc.close(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
f37ed87b2a8cca320f33ce649ac3b71a
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.lang.*; public class X { public static void main(String[] args) { X ob=new X(); Scanner sc=new Scanner(System.in); int A=sc.nextInt(); int B=sc.nextInt(); int K=sc.nextInt(); ob.solve(A,B,K); } boolean solve(int A,int B, int K) { int[] X=new int[A+B]; int[] Y=new int[A+B]; if(K==0) { System.out.println("YES"); for(int i=0;(i+K)<(B);i++) { X[i]=Y[i]=1; } for(int i=0;(i)<(A+B);i++) { System.out.print(X[i]); } System.out.println(); for(int i=0;(i)<(A+B);i++) { System.out.print(Y[i]); } return true; } if((B+A)<=(K+1) || B==1 || A==0) { System.out.println("NO"); return false; } int right=Math.min(B-1,K); int left=Math.max(1,B-K); for(int i=0;i<left;i++) { X[i]=Y[i]=1; } for(int i=1;i<=right;i++) { X[(A+B)-i]=Y[(A+B)-i]=1; if(i==1) { X[(A+B)-i]=0; } } X[(A+B)-(K+1)]=1; System.out.println("YES"); for(int i=0;(i)<(A+B);i++) { System.out.print(X[i]); } System.out.println(); for(int i=0;(i)<(A+B);i++) { System.out.print(Y[i]); } return true; } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
393a801af0ca86e1bde9c708ba661be3
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
//package Practice; import java.util.*; public class codefor { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt(); if(b==1) { if(k!=0) System.out.println("NO"); else { String x=""; x="1"+"0".repeat(a); System.out.println("YES\n"+x+"\n"+x); } } else if(k<=a) { System.out.println("YES"); String x="",y=""; x="1".repeat(b-1)+"0".repeat(a-k)+"1"+"0".repeat(k); y="1".repeat(b-1)+"0".repeat(a)+"1"; System.out.println(x+"\n"+y); } else if(k>a && (k-a+2)<=b && a>=1) { String x="",y=""; x="1".repeat(b)+"0".repeat(a); y="1".repeat(a+b-k-1)+"0"+"1".repeat(k-a)+"0".repeat(a-1)+"1"; System.out.println("YES\n"+x+"\n"+y); } else System.out.println("NO"); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
55a9e6bf727de8ae4b331620e421538d
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class Sol{ // ************ n==1 ***************** important test case public static void main(String []args){ int times=1; while(times-->0){ int a=ni();int b=ni();int k=ni(); if(k!=0 && a==0){out.println("No");} else if(k!=0 && b==1)out.println("No"); else if(k>a+b-2 && k!=0 )out.println("No"); else{ StringBuilder s1=new StringBuilder(); StringBuilder s2=new StringBuilder(); s2.append(1);for(int i=1;i<=a;i++)s2.append(0); for(int i=1;i<b;i++)s2.append(1); int curr=1+a+1;s1.append(1);b--; while(curr>2 && k>0){k--;curr--;} for(int i=2;i<curr;i++){s1.append(0);a--;} if(b>0){s1.append(1);b--;} while(a>1){s1.append(0);a--;}while(k>0){s1.append(1);k--;b--;} while(a>0){s1.append(0);a--;} while(b>0){s1.append(1);b--;} //out.println(k); out.println("Yes");out.println(s1);out.println(s2); } }out.close();} //-----------------Utility-------------------------------------------- static int gcd(int a,int b){if(b==0)return a; return gcd(b,a%b);} static int Max=Integer.MAX_VALUE; static long mod=998244353; static int v(char c){return (int)(c-'a')+1;} static long factorial(long n){ long ans=1l; long i=1l; while(i<=n){ans*=i;ans%=mod;i++;} return ans; } static long inv(long n){ return power(n,mod-2); } public static long power(long x, long y ) { //0^0 = 1 long res = 1L; x = x%mod; while(y > 0) { if((y&1)==1) res = (res*x)%mod; y >>= 1; x = (x*x)%mod; } return res; } static class Pair implements Comparable<Pair>{ int id;int out; public Pair(int id,int out) { this.id=id;this.out=out; } @Override public int compareTo(Pair p){return Long.compare(out,p.out);} //public int compareTo(Pair p){return id-p.id;} } //----------------------I/O--------------------------------------------- static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static FastReader in=new FastReader(inputStream); static PrintWriter out=new PrintWriter(outputStream); static class FastReader { BufferedReader br; StringTokenizer st; FastReader(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int ni() { return in.nextInt(); } static long nl(){return in.nextLong();} static String ns(){return in.nextLine();} }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
ae03533e741e0d969d85a4886dc6ed7d
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); PrintWriter out=new PrintWriter(System.out); // BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=1; // t=sc.nextInt(); //int t=Integer.parseInt(br.readLine()); while(--t>=0){ int a=sc.nextInt(); int b=sc.nextInt(); int k=sc.nextInt(); int n=a+b; if(((n-2)<k&&k!=0)||(b<=1&&k!=0)||(a<=0&&k!=0)){ out.println("No"); out.flush(); continue; } if(b==1){ out.println("Yes"); out.print(1); for(int i=1;i<=a;i++) out.print(0); out.println(); out.flush(); out.print(1); for(int i=1;i<=a;i++) out.print(0); out.println(); out.flush(); continue; } if(k==0){ out.println("Yes"); // out.print(1); for(int i=1;i<=b;i++) out.print(1); for(int i=1;i<=a;i++) out.print(0); out.println(); out.flush(); // out.print(1); for(int i=1;i<=b;i++) out.print(1); for(int i=1;i<=a;i++) out.print(0); out.println(); out.flush(); continue; } out.println("Yes"); a--; b--; int c=a; int d=b; for(int i=1;i<=n;i++){ if(i==(n-k)){ out.print(1); continue; } if(i==(n)){ out.print(0); continue; } if(b>0) { out.print(1);b--; } else{ out.print(0);a--; } } out.println(); out.flush(); for(int i=1;i<=n;i++){ if(i==(n-k)){ out.print(0); continue; } if(i==(n)){ out.print(1); continue; } if(d>0) { out.print(1);d--; } else{ out.print(0);c--; } } out.println(); out.flush(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
95ee2f8e2e2b6ecb9f9019854a2e3ba9
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; /** * @author Mubtasim Shahriar */ public class GeniusGambity { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader sc = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); // int t = sc.nextInt(); int t = 1; while (t-- != 0) { solver.solve(sc, out); } out.close(); } static class Solver { public void solve(InputReader sc, PrintWriter out) { int zero = sc.nextInt(); int one = sc.nextInt(); int k = sc.nextInt(); int n = zero+one; int[] ansa = new int[n]; int[] ansb = new int[n]; for (int i = 0; i < one; i++) { ansa[i] = 1; ansb[i] = 1; } if(k==0) { out.println("YES"); printt(ansa,out); printt(ansb,out); return; } if(zero==0) { out.println("NO"); return; } int firstidx = one-1; if(k>0 && firstidx==0) { out.println("NO"); return; } int movelast = Math.min(k,zero); int lastidx = one-1+movelast; k -= movelast; ansb[firstidx] = 0; ansb[lastidx] = 1; int pull = one-1; while(k>0 && pull>=2) { ansb[pull] = 1; ansb[--pull] = 0; k--; } if(k>0) { out.println("NO"); return; } out.println("YES"); printt(ansa,out); printt(ansb,out); } private void printt(int[] a, PrintWriter out) { for (int i = 0; i < a.length; i++) { out.print(a[i]); } out.println(); } } static void sort(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sort(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); } static void sortDec(int[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static void sortDec(long[] arr) { Random rand = new Random(); int n = arr.length; for (int i = 0; i < n; i++) { int idx = rand.nextInt(n); if (idx == i) continue; arr[i] ^= arr[idx]; arr[idx] ^= arr[i]; arr[i] ^= arr[idx]; } Arrays.sort(arr); int l = 0; int r = n - 1; while (l < r) { arr[l] ^= arr[r]; arr[r] ^= arr[l]; arr[l] ^= arr[r]; l++; r--; } } static class InputReader { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public BigInteger readBigInteger() { try { return new BigInteger(nextString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char nextCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, nextInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return nextString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; ++i) array[i] = nextInt(); return array; } public int[] nextSortedIntArray(int n) { int array[] = nextIntArray(n); Arrays.sort(array); return array; } public int[] nextSumIntArray(int n) { int[] array = new int[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; ++i) array[i] = nextLong(); return array; } public long[] nextSumLongArray(int n) { long[] array = new long[n]; array[0] = nextInt(); for (int i = 1; i < n; ++i) array[i] = array[i - 1] + nextInt(); return array; } public long[] nextSortedLongArray(int n) { long array[] = nextLongArray(n); Arrays.sort(array); return array; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
c6000dcf57669529a280f1c1cbd9e90e
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
//package geniussgambit; import java.util.*; import java.io.*; public class geniussgambit { public static void main(String[] args) throws IOException { BufferedReader fin = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(fin.readLine()); int a = Integer.parseInt(st.nextToken()); int b = Integer.parseInt(st.nextToken()); int k = Integer.parseInt(st.nextToken()); if(k != 0 && ((a + b - 2) < k || (b == 0 && k != 0) || (b == 1 && k != 0) || (a == 0 && k != 0))) { System.out.println("NO"); } else { System.out.println("YES"); StringBuilder fout = new StringBuilder(); if(b == 0) { fout.append("1"); for(int i = 0; i < a; i++) { fout.append("0"); } fout.append("\n"); fout.append("1"); for(int i = 0; i < a; i++) { fout.append("0"); } fout.append("\n"); } else { int firstZeroes = a - k; for(int i = 0; i < b; i++) { fout.append("1"); } for(int i = 0; i < a; i++) { fout.append("0"); } fout.append("\n"); int count = 0; char[] ans = new char[a + b]; for(int i = 0; i < ans.length; i++) { if(i < b) { ans[i] = '1'; } else { ans[i] = '0'; } } for(int i = b - 1; i < ans.length - 1; i++) { if(count == k) { break; } ans[i + 1] = '1'; ans[i] = '0'; count ++; } for(int i = b - 2; i > 0; i--) { if(count == k) { break; } ans[i] = '0'; ans[i + 1] = '1'; count ++; } fout.append(String.valueOf(ans)).append("\n"); } System.out.print(fout); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
34f62458a6a04f8ebbe205fcad220955
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.StringTokenizer; public class Main { private static void run(Reader in, PrintWriter out) throws IOException { int a = in.nextInt(); int b = in.nextInt(); int k = in.nextInt(); int n = a + b; boolean[] done = new boolean[n]; int[] s = new int[n]; int[] t = new int[n]; s[0] = t[0] = 1; done[0] = true; b--; if (k != 0) { if (b > 0 && a > 0 && n - k - 1 > 0) { s[n - k - 1] = 1; t[n - k - 1] = 0; s[n - 1] = 0; t[n - 1] = 1; done[n - k - 1] = done[n - 1] = true; b--; a--; } else { out.println("No"); return; } } for (int i = 0; i < n; i++) { if (done[i]) continue; if (b != 0) { s[i] = t[i] = 1; b--; } else { s[i] = t[i] = 0; } } out.println("Yes"); for (int i = 0; i < n; i++) { out.print(s[i]); } out.println(); for (int i = 0; i < n; i++) { out.print(t[i]); } out.println(); } public static void main(String[] args) throws IOException { Reader in = new Reader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); run(in, out); out.flush(); in.close(); out.close(); } static class Reader { BufferedReader reader; StringTokenizer st; Reader(InputStreamReader stream) { reader = new BufferedReader(stream, 32768); st = null; } void close() throws IOException { reader.close(); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } String nextLine() throws IOException { return reader.readLine(); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
ba35101cd898b2a721def7b41544d0c3
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.Arrays; import java.util.Scanner; public class D { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int zeros = scn.nextInt(); int ones = scn.nextInt(); int k = scn.nextInt(); int len = zeros + ones; if ((k > 0) && (len < k + 2 || ones == 1)) { System.out.println("NO"); return; } char[] x = new char[len]; char[] y = new char[len]; Arrays.fill(x, '0'); Arrays.fill(y, '0'); x[0] = '1'; y[0] = '1'; ones--; if (k > 0) { x[len - k - 1] = '1'; y[len - 1] = '1'; ones--; } for (int i = 1; i < len && ones > 0; i++) { if (y[i] == '0' && x[i] == '0') { x[i] = y[i] = '1'; ones--; } } if (ones>0){ System.out.println("NO"); }else{ System.out.println("YES"); System.out.println(String.valueOf(x)); System.out.println(String.valueOf(y)); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
7d7e86f75bda2b833a9bc8a7fcfe3adf
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.lang.*; public final class CodeChef { public static void main (String[] args) { Scanner scan = new Scanner(System.in); int b = scan.nextInt(), a = scan.nextInt(), k = scan.nextInt(); if(k == 0) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("1".repeat(a)); stringBuilder.append("0".repeat(b)); System.out.println("Yes"); System.out.println(stringBuilder.toString()); System.out.println(stringBuilder.toString()); return; } if((k > b + a - 2 )|| a < 2 || b == 0) { System.out.println("No"); return; } String x = "", y = ""; if(k <= b) { StringBuilder sb = new StringBuilder(); sb.append("1"); sb.append("0".repeat(b - k)); sb.append("1".repeat(a - 1)); sb.append("0".repeat(k)); x = sb.toString(); sb.setLength(0); sb.append("1"); sb.append("0".repeat(b - k)); sb.append("1".repeat(a - 2)); sb.append("0".repeat(k)); sb.append("1"); y = sb.toString(); } else { StringBuilder sb = new StringBuilder(); sb.append("1".repeat(a)); sb.append("0".repeat(b)); k -= b; x = sb.toString(); sb.setLength(0); sb.append("1".repeat(a-k-1)); sb.append("0"); sb.append("1".repeat(k)); sb.append("0".repeat(b-1)); sb.append("1"); y = sb.toString(); } System.out.println("Yes"); System.out.println(x); System.out.println(y); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
5a64cd6bac9989650518479113de3b00
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class D { InputStream is; PrintWriter out; String INPUT = ""; void solve() throws IOException { int a= ni(), b= ni(), k= ni(); if(k> Math.abs(a+b-2) || (b==1 && k!=0) ||(a==0 && k!=0)) { out.println("No"); return; } char[] x= new char[a+b]; char[] y= new char[a+b]; Arrays.fill(x, '0'); Arrays.fill(y, '0'); if(k<=a) { int index= 0; while(b!=1) { x[index]= '1'; y[index]= '1'; index++; b--; } x[index]= '1'; y[index+k]= '1'; } else { int _b= b, index= 0; while(_b!=0) { x[index++]= '1'; _b--; } index= 0; int val= b-1-(k-a); while(val!=0) { y[index++]= '1'; val--; b--; } b--; index++; while(b!=0) { y[index++]= '1'; b--; } y[y.length-1]= '1'; } out.println("Yes"); out.println(new String(x)); out.println(new String(y)); } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); solve(); out.flush(); } public static void main(String[] args) throws Exception { new D().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private void tr(Object... o) { if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o)); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
49783b664b5631f4a155a9ae7869547b
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.util.*; public class D { static class pair implements Comparable<pair> { int f; int s; double th; int id; public pair() { } public pair(int a, int b, int c) { f = a; s = b; th = (f * 1.00000) / (s * 1.00000); id = c; } @Override public int compareTo(pair o) { // TODO Auto-generated method stub if (this.th > o.th) return -1; if (this.th == o.th) { return this.s - o.s; } else return 1; } } static int mod = (int) 1e9 + 7; static int ar[]; static Scanner sc = new Scanner(System.in); static StringBuilder out = new StringBuilder(); static ArrayList<Integer> grEven[]; static ArrayList<Integer> grOdd[]; static void sort(int a[], int n) { ArrayList<Integer> al = new ArrayList<>(); for (int i = 0; i < n; i++) { al.add(a[i]); } Collections.sort(al); for (int i = 0; i < n; i++) { a[i] = al.get(i); } } static void in(int a[], int n) throws IOException { for (int i = 0; i < n; i++) a[i] = sc.nextInt(); } public static void main(String[] args) throws IOException { int t = 1;// sc.nextInt(); while (t-- > 0) { int a = sc.nextInt(); int b = sc.nextInt(); int k = sc.nextInt(); StringBuilder x = new StringBuilder(); StringBuilder y = new StringBuilder(); if (k == 0) { out.append("Yes\n"); for (int i = 0; i < b; i++) { x.append(1); y.append(1); } for (int i = 0; i < a; i++) { x.append(0); y.append(0); } out.append(x+"\n"); out.append(y+"\n");continue; } if (a == 0 || b==1 || k>a+b-2) { out.append("No\n"); continue; } x.append(0); y.append(1); k--; a--; b--; while (k > 0 && a > 0) { x.append(0); y.append(0); k--; a--; } while (k > 0 && b > 1) { x.append(1); y.append(1); k--; b--; } x.append(1); y.append(0); while (a > 0) { x.append(0); y.append(0); a--; } while (b > 0) { x.append(1); y.append(1); b--; } x.reverse(); y.reverse(); out.append("Yes\n"); out.append(x + "\n"); out.append(y + "\n"); } System.out.println(out); } // static Reader sc=new Reader(); static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
e62d5adbdc6d476a05be52d32005be9b
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Jaynil */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); DGeniussGambit solver = new DGeniussGambit(); solver.solve(1, in, out); out.close(); } static class DGeniussGambit { public void solve(int testNumber, InputReader in, PrintWriter out) { int a = in.nextInt(); int b = in.nextInt(); int l = a + b; int k = in.nextInt(); int aa[] = new int[a + b]; int bb[] = new int[a + b]; if (a == 0) { if (k != 0) { out.println("No"); return; } out.println("Yes"); for (int i = 0; i < l; i++) { out.print(1); } out.println(); for (int i = 0; i < l; i++) { out.print(1); } out.println(); return; } if (b == 0) { out.println("No"); return; } b--; aa[0] = 1; bb[0] = 1; if (a + b - 1 < k) { out.println("No"); return; } if (k == 0) { for (int i = 1; i < l; i++) { if (a > 0) { aa[i] = 0; bb[i] = 0; a--; } else { aa[i] = 1; bb[i] = 1; b--; } } out.println("Yes"); for (int i = 0; i < l; i++) out.print(aa[i]); out.println(); for (int i = 0; i < l; i++) out.print(bb[i]); out.println(); return; } aa[1] = 1; bb[1] = 0; aa[k + 1] = 0; bb[k + 1] = 1; a -= 1; b -= 1; if (a < 0 || b < 0) { out.println("No"); return; } for (int i = 2; i < l; i++) { if (i == k + 1) continue; if (a > 0) { aa[i] = 0; bb[i] = 0; a--; } else { aa[i] = 1; bb[i] = 1; b--; } } out.println("Yes"); for (int i = 0; i < l; i++) out.print(aa[i]); out.println(); for (int i = 0; i < l; i++) out.print(bb[i]); out.println(); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
3bd3e808c3b36e45b0881e7606af9c57
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Solution { public static void main(String[] args) throws IOException { Reader input = new Reader(); int a = input.nextInt(); int b = input.nextInt(); int k = input.nextInt(); if(a == 0) { if(k > 0) { System.out.print("NO"); } else { StringBuilder x = new StringBuilder(); for(int i = 0; i < b; ++i) x.append(1); System.out.println("YES"); System.out.println(x); System.out.print(x); } } else if(b == 1) { if(k > 0) { System.out.print("NO"); } else { StringBuilder x = new StringBuilder(), y = new StringBuilder(); x.append(1); y.append(1); for(int i = 0; i < a; ++i) { x.append(0); y.append(0); } System.out.print("YES\n"); x.append("\n"); System.out.print(x); System.out.print(y); } } else if(k == 0) { StringBuilder x = new StringBuilder(); for(int i = 0; i < b; ++i) { x.append(1); } for(int i = 0; i < a; ++i) { x.append(0); } System.out.print("YES\n"); System.out.println(x); System.out.print(x); } else if(k < a) { StringBuilder x = new StringBuilder(), y = new StringBuilder(); x.append(1); y.append(1); --b; for(int i = 0; i < b; ++i) { x.append(1); } for(int i = 0; i < a; ++i) { x.append(0); } for(int i = 0; i < b-1; ++i) { y.append(1); } for(int i = 0; i < k; ++i) { y.append(0); --a; } y.append(1); for(int i = 0; i < a; ++i) { y.append(0); } System.out.print("YES\n"); x.append("\n"); System.out.print(x); System.out.print(y); } else if(a+b-2 < k) { System.out.print("NO"); } else { StringBuilder x = new StringBuilder(), y = new StringBuilder(); for(int i = 0; i < b; ++i) x.append(1); for(int i = 0; i < a; ++i) x.append(0); y.append(1); --b; while(a+b-k > a) { y.append(1); --b; } int temp = a+b-k; for(int i = 0; i < temp; ++i) { y.append(0); --a; } for(int i = 0; i < b-1; ++i) { y.append(1); } for(int i = 0; i < a; ++i) y.append(0); y.append(1); System.out.print("YES\n"); x.append("\n"); System.out.print(x); System.out.print(y); } } static class Reader { BufferedReader bufferedReader; StringTokenizer string; public Reader() { InputStreamReader inr = new InputStreamReader(System.in); bufferedReader = new BufferedReader(inr); } public String next() throws IOException { while(string == null || ! string.hasMoreElements()) { string = new StringTokenizer(bufferedReader.readLine()); } return string.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public String nextLine() throws IOException { return bufferedReader.readLine(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
5266f1a34d31862d685844467db3f712
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
// \(≧▽≦)/ // TODO : get good import java.io.*; import java.util.*; public class tank { static final FastScanner fs = new FastScanner(); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int t = 1; while(t-- > 0) run_case(); out.close(); } static void run_case() { int a = fs.nextInt(), b = fs.nextInt(), k = fs.nextInt(); int n = a + b; if((k > n - 2 && n > 1) || (b == 1 && k > 0) || (b == n && k > 0)) { System.out.println("No"); return; } char[] ka = new char[n]; char[] kb = new char[n]; Arrays.fill(ka, '1'); Arrays.fill(kb, '1'); if(k > 0) { kb[1] = '0'; ka[1 + k] = '0'; a--; } for (int i = 1; i < n && a > 0; i++) { if(ka[i] == kb[i] && ka[i] == '1') { a--; ka[i] = kb[i] = '0'; } } System.out.println("Yes"); System.out.println(new String(ka)); System.out.println(new String(kb)); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } String nextLine(){ try { return br.readLine(); } catch (IOException e) { e.printStackTrace(); } return ""; } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
f977937f6df154354d14d06702be731a
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 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.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); DGeniussGambit solver = new DGeniussGambit(); solver.solve(1, in, out); out.close(); } static class DGeniussGambit { public void solve(int testNumber, InputReader in, OutputWriter out) { int a = in.nextInt(), b = in.nextInt(), k = in.nextInt(); if (k == 0) { out.println("Yes"); for (int i = 0; i < b; i++) { out.print("1"); } for (int i = 0; i < a; i++) { out.print("0"); } out.println(); for (int i = 0; i < b; i++) { out.print("1"); } for (int i = 0; i < a; i++) { out.print("0"); } out.println(); return; } if (a == 0 && k > 0) { out.println("No"); return; } if (k > b - 1 + a - 1) { out.println("No"); return; } if (b == 1) { if (k > 0) { out.println("no"); return; } out.println("Yes"); out.print("1"); for (int i = 0; i < a; i++) out.print("0"); out.println(); out.print("1"); for (int i = 0; i < a; i++) out.print("0"); out.println(); return; } out.println("Yes"); for (int i = 0; i < b; i++) out.print("1"); for (int i = 0; i < a; i++) out.print("0"); out.println(); int[] ans = new int[a + b]; for (int i = 0; i < b; i++) { ans[i] = 1; } if (k <= b - 1) { ans[b - k] = 0; ans[b] = 1; } else { ans[1] = 0; int diff = k - (b - 1); ans[b + diff] = 1; } for (int i = 0; i < a + b; i++) out.print(ans[i]); } } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println() { writer.println(); } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void print(int i) { writer.print(i); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
7a1964b86db2aff9422f736f143d6f76
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
// package codeforce.cf704; import java.io.PrintWriter; import java.util.Scanner; public class D { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); // int t = sc.nextInt(); int t = 1; for (int i = 0; i < t; i++) { solve(sc, pw); } pw.close(); } static void solve(Scanner in, PrintWriter out){ int a = in.nextInt(), b = in.nextInt(), k = in.nextInt(); int len = a + b; int[] ans1 = new int[a + b]; int[] ans2 = new int[a + b]; if (b == 1){ if (k > 0){ out.println("No");return; } } if (a == 0){ if (k > 0){ out.println("No");return; } } if (k >= a + b - 1 && k > 0){ out.println("No");return; }else{ ans1[0] = 1; ans2[0] = 1; b--; if (b > 0){ ans1[1] = 1; ans2[1 + k] = 1; b--; for (int i = 2; i < 1 + k && b > 0; i++, b--) { ans1[i] = 1; ans2[i] = 1; } for (int i = 1 + k + 1; i < len && b > 0; i++, b--) { ans1[i] = 1; ans2[i] = 1; } } out.println("Yes"); for(int x : ans1) out.print(x); out.println(); for(int x : ans2) out.print(x); out.println(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
521bbedac3e1bef287a5e2bca5662e58
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; public class First { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); //int a = 1; int t; //t = in.nextInt(); t = 1; while (t > 0) { //out.print("Case #"+(a++)+": "); solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int a, b, k; a = in.nextInt(); b = in.nextInt(); k = in.nextInt(); if(a==0 || b==1){ if(k!=0){ out.println("No"); } else{ out.println("Yes"); if(a==0){ for (int i = 0; i < a+b; i++) { out.print("1"); } out.println(); for (int i = 0; i < a+b; i++) { out.print("1"); } } else{ out.print(1); for (int i = 1; i < a+b; i++) { out.print("0"); } out.println(); out.print(1); for (int i = 1; i < a+b; i++) { out.print("0"); } } out.println(); } return; } if(k>a+b-2){ out.println("No"); return; } if(k==0){ out.println("Yes"); for (int i = 0; i < b; i++) { out.print("1"); } for (int i = b; i < a+b; i++) { out.print("0"); } out.println(); for (int i = 0; i < b; i++) { out.print("1"); } for (int i = b; i < a+b; i++) { out.print("0"); } out.println(); return; } out.println("Yes"); StringBuilder s1 = new StringBuilder("1"); StringBuilder s2 = new StringBuilder("1"); b--; int n = a+b, c , d; c = n - 1 -k; for (int i = 0; i < c; i++) { if(b==1){ s1.append("0"); s2.append("0"); } else { s1.append("1"); s2.append("1"); b--; } } s1.append("1"); s2.append("0"); d = b; b--; for (int i = c+1; i < n; i++) { if(b!=0){ s1.append("1"); b--; } else { s1.append("0"); } } b = d; for (int i = c+1; i < n-1; i++) { if(b!=1){ s2.append("1"); b--; } else { s2.append("0"); } } s2.append("1"); out.println(s1); out.println(s2); } } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static class answer implements Comparable<answer>{ int a; int b; public answer(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(answer o) { return o.a - this.a; } @Override public boolean equals(Object o){ if(o instanceof answer){ answer c = (answer)o; return a == c.a && b == c.b; } return false; } } static class answer1 implements Comparable<answer1>{ int a, b, c; public answer1(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } @Override public int compareTo(answer1 o) { if(o.c==this.c){ return this.a - o.a; } return o.c - this.c; } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static final Random random=new Random(); static void shuffleSort(int[] a) { int n=a.length; for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
33d22bc84b57672cbd6b0e0f6c753aca
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.lang.*; import java.util.*; import java.io.*; public class Solution extends PrintWriter{ Scanner sc; Solution(){ super(System.out, true); sc=new Scanner(System.in); } public static void main(String[] args){ Solution sol=new Solution(); sol.solve(); sol.flush(); } //start here public void solve(){ int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt(); if(k>0 && (k>a+b-2 || b<2 || a==0)){ System.out.println("No"); return; } System.out.println("Yes"); StringBuilder a1=new StringBuilder(); for(int i=0;i<b;i++) a1.append("1"); for(int i=0;i<a;i++) a1.append("0"); System.out.println(a1); if(k!=0){ a1.setCharAt(b+Math.min(k,a)-1,'1'); k=Math.max(0,k-a); a1.setCharAt(b-1-k,'0'); } System.out.println(a1); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
8114e26df7fcde1261cd1b8eff57a3cc
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; public class testJava{ Scanner sc; testJava(){ sc=new Scanner(System.in); } public static void main(String args[]){ testJava tj=new testJava(); tj.problem(); } public void problem(){ int a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt(); if(k>0 && (k>a+b-2 || b<2 || a==0)){ System.out.println("No"); return; } System.out.println("Yes"); StringBuilder a1=new StringBuilder(); for(int i=0;i<b;i++) a1.append("1"); for(int i=0;i<a;i++) a1.append("0"); System.out.println(a1); if(k!=0){ a1.setCharAt(b+Math.min(k,a)-1,'1'); k=Math.max(0,k-a); a1.setCharAt(b-1-k,'0'); } System.out.println(a1); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
df8705b96e4f23d05e4e67ebcb5043a9
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static class Reader { BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] args) { Reader rd = new Reader(); int a = rd.nextInt(); int b = rd.nextInt(); int k = rd.nextInt(); if ((k > a && k > a + b - 2) || (b == 1 && k > 0) || (a == 0 && k > 0)) { System.out.println("No"); } else { System.out.println("Yes"); for (int i = 0; i < b; i++) { System.out.print(1); } for (int i = 0; i < a; i++) { System.out.print(0); } System.out.println(); if (k <= a) { for (int i = 0; i < b - 1; i++) { System.out.print(1); } for (int i = 0; i < k; i++) { System.out.print(0); } System.out.print(1); for (int i = 0; i < a - k; i++) { System.out.print(0); } } else { for (int i = 0; i < a + b - k - 1; i++) { System.out.print(1); } if (a > 0) System.out.print(0); for (int i = 0; i < k - a; i++) { System.out.print(1); } for (int i = 0; i < a - 1; i++) { System.out.print(0); } System.out.print(1); } System.out.println(); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
a0f3ebd0866863b664defca954e1ecc5
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Random; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class D{ public static void main(String[] args) throws IOException { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int tt = 1; while(tt-->0) { int a = fs.nextInt(), b = fs.nextInt(), k = fs.nextInt(); int n = a + b; if(k>=Math.max(n-1, 1) || (b==1 && k!=0) || (a==0 && k!=0)) { out.println("No"); out.flush(); return; } ArrayList<Character> ans1 = new ArrayList<>(); ArrayList<Character> ans2 = new ArrayList<>(); if(k==0) { out.println("Yes"); for(int j=0;j<2;j++) { for(int i=0;i<b;i++) out.print('1'); for(int i=0;i<a;i++) out.print('0'); out.println(); } out.flush(); return; } int cnt0 = a - 1, cnt1 = b - 2; ans1.add('1'); ans2.add('1'); int num = n - k - 2; while(num>0) { if(cnt0>0) { ans1.add('0'); ans2.add('0'); cnt0--; num--; } else { ans1.add('1'); ans2.add('1'); cnt1--; num--; } } ans1.add('1'); ans2.add('0'); for(int i=0;i<k-1;i++) { if(cnt1>0) { ans1.add('1'); ans2.add('1'); cnt1--; } else { ans1.add('0'); ans2.add('0'); cnt0--; } } ans1.add('0'); ans2.add('1'); out.println("Yes"); for(char ch: ans1) out.print(ch); out.println(); for(char ch: ans2) out.print(ch); out.println(); } out.close(); } static final Random random=new Random(); static <T> void shuffle(T[] arr) { int n = arr.length; for(int i=0;i<n;i++ ) { int k = random.nextInt(n); T temp = arr[k]; arr[k] = arr[i]; arr[i] = temp; } } static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n); int temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static void ruffleSort(long[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n); long temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static void reverse(int[] arr, int l, int r) { for(int i=l;i<l+(r-l)/2;i++){ int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp; } } static void reverse(long[] arr, int l, int r) { for(int i=l;i<l+(r-l)/2;i++){ long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp; } } static <T> void reverse(T[] arr, int l, int r) { for(int i=l;i<l+(r-l)/2;i++) { T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp; } } static class FastScanner{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String next(){ while(!st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } } return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt(){ return Integer.parseInt(next()); } public int[] readArray(int n){ int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } public long nextLong() { return Long.parseLong(next()); } public char nextChar() { return next().toCharArray()[0]; } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
ede5c3d80293b7421d55787149929981
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class Main { static ContestScanner sc = new ContestScanner(System.in); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(); static long mod = (long) 1e9 + 7; public static void main(String[] args) throws Exception { //int T = sc.nextInt(); //for(int i = 0; i < T; i++)solve(); solve(); pw.flush(); } public static void solve() { int a = sc.nextInt(); int b = sc.nextInt(); int k = sc.nextInt(); char[] s1 = new char[a+b]; char[] s2 = new char[a+b]; for(int i = 0; i < b; i++){ s1[i] = s2[i] = '1'; } for(int i = b; i < a+b; i++){ s1[i] = s2[i] = '0'; } if(b == 1 || a == 0){ if(k == 0){ pw.println("Yes"); pw.println(new String(s1)); pw.println(new String(s2)); }else{ pw.println("No"); } }else{ if(a+b-2 < k){ pw.println("No"); }else if(a > k){ pw.println("Yes"); s2[b-1] = '0'; s2[b-1+k] = '1'; pw.println(new String(s1)); pw.println(new String(s2)); }else{ pw.println("Yes"); s2[b-1] = '0'; s2[a+b-1] = '1'; k -= a; for(int i = b-2; i >= 0; i--){ if(k == 0) break; s2[i] = '0'; s2[i+1] = '1'; k--; } pw.println(new String(s1)); pw.println(new String(s2)); } } } static class GeekInteger { public static void save_sort(int[] array) { shuffle(array); Arrays.sort(array); } public static int[] shuffle(int[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); int randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } public static void save_sort(long[] array) { shuffle(array); Arrays.sort(array); } public static long[] shuffle(long[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); long randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } } } /** * refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java */ class ContestScanner { private final java.io.InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public ContestScanner(java.io.InputStream in){ this.in = in; } public ContestScanner(java.io.File file) throws java.io.FileNotFoundException { this(new java.io.BufferedInputStream(new java.io.FileInputStream(file))); } public ContestScanner(){ this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (java.io.IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new java.util.NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new java.util.NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b)) ); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b)) ); } } } } throw new ArithmeticException( String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit) ); } n = n * 10 + digit; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(int length){ long[] array = new long[length]; for(int i=0; i<length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map){ long[] array = new long[length]; for(int i=0; i<length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length){ int[] array = new int[length]; for(int i=0; i<length; i++) array[i] = this.nextInt(); return array; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map){ int[] array = new int[length]; for(int i=0; i<length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length){ double[] array = new double[length]; for(int i=0; i<length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map){ double[] array = new double[length]; for(int i=0; i<length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width){ long[][] mat = new long[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width){ int[][] mat = new int[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width){ double[][] mat = new double[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width){ char[][] mat = new char[height][width]; for(int h=0; h<height; h++){ String s = this.next(); for(int w=0; w<width; w++){ mat[h][w] = s.charAt(w); } } return mat; } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
34ef42bf09447690aab4200ac01d2fcc
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static int MOD = 1000000007; // After writing solution, quick scan for: // array out of bounds // special cases e.g. n=1? // npe, particularly in maps // // Big numbers arithmetic bugs: // int overflow // sorting, or taking max, after MOD void solve() throws IOException { int[] abk = ril(3); int a = abk[0]; int b = abk[1]; int k = abk[2]; // k = 0 is always possible, just use same numbers // what is the maximum k we can get? // gonna just guess int max = a + b - 2; if (k == 0) { pw.println("Yes"); for (int i = 0; i < b; i++) pw.print("1"); for (int i = 0; i < a; i++) pw.print("0"); pw.println(); for (int i = 0; i < b; i++) pw.print("1"); for (int i = 0; i < a; i++) pw.print("0"); pw.println(); } else if (k > max) pw.println("No"); else if (k > 0 && b == 1) pw.println("No"); else if (k <= a) { pw.println("Yes"); for (int i = 0; i < b; i++) pw.print("1"); for (int i = 0; i < a; i++) pw.print("0"); pw.println(); char[] y = new char[a + b]; Arrays.fill(y, '0'); for (int i = 0; i < b-1; i++) y[i] = '1'; y[y.length-1 - (a - k)] = '1'; pw.println(new String(y)); } else if (a > 0) { pw.println("Yes"); for (int i = 0; i < b; i++) pw.print("1"); for (int i = 0; i < a; i++) pw.print("0"); pw.println(); char[] y = new char[a + b]; Arrays.fill(y, '0'); y[y.length-1] = '1'; for (int i = 0; i < b; i++) y[i] = '1'; y[1 + (b-2 - (k-a))] = '0'; pw.println(new String(y)); } else { pw.println("No"); } } // IMPORTANT // DID YOU CHECK THE COMMON MISTAKES ABOVE? // Template code below BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); public static void main(String[] args) throws IOException { Main m = new Main(); m.solve(); m.close(); } void close() throws IOException { pw.flush(); pw.close(); br.close(); } int ri() throws IOException { return Integer.parseInt(br.readLine().trim()); } long rl() throws IOException { return Long.parseLong(br.readLine().trim()); } int[] ril(int n) throws IOException { int[] nums = new int[n]; int c = 0; for (int i = 0; i < n; i++) { int sign = 1; c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } nums[i] = x * sign; } while (c != '\n' && c != -1) c = br.read(); return nums; } long[] rll(int n) throws IOException { long[] nums = new long[n]; int c = 0; for (int i = 0; i < n; i++) { int sign = 1; c = br.read(); long x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } nums[i] = x * sign; } while (c != '\n' && c != -1) c = br.read(); return nums; } int[] rkil() throws IOException { int sign = 1; int c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } return ril(x); } long[] rkll() throws IOException { int sign = 1; int c = br.read(); int x = 0; if (c == '-') { sign = -1; c = br.read(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = br.read(); } return rll(x); } char[] rs() throws IOException { return br.readLine().toCharArray(); } void sort(int[] A) { Random r = new Random(); for (int i = A.length-1; i > 0; i--) { int j = r.nextInt(i+1); int temp = A[i]; A[i] = A[j]; A[j] = temp; } Arrays.sort(A); } void printDouble(double d) { pw.printf("%.16f", d); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
5a4498db9c3ae7188766412067b57ec9
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.util.concurrent.CompletableFuture; import javax.swing.event.TreeExpansionEvent; import javax.swing.text.Segment; import java.io.*; import java.math.*; import java.sql.Array; public class Main { static class Reader{ BufferedReader br; StringTokenizer st; public Reader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static long mod = (long)(1e9 + 7); static void sort(long[] arr ) { ArrayList<Long> al = new ArrayList<>(); for(long e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i); } static void sort(int[] arr ) { ArrayList<Integer> al = new ArrayList<>(); for(int e:arr) al.add(e); Collections.sort(al); for(int i = 0 ; i<al.size(); i++) arr[i] = al.get(i); } static void sort(char[] arr) { ArrayList<Character> al = new ArrayList<Character>(); for(char cc:arr) al.add(cc); Collections.sort(al); for(int i = 0 ;i<arr.length ;i++) arr[i] = al.get(i); } static void rvrs(int[] arr) { int i =0 , j = arr.length-1; while(i>=j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; j--; } } static long[] rvrs(long[] arr) { int i =0 , j = arr.length-1; int n = arr.length; long[] ans = new long[n]; for( i =0 ; i<n ; i++) ans[i] = arr[j--]; return ans; } static long mod_mul(long a , long b ,long mod) { return ((a%mod)*(b%mod))%mod; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] prime(int num) { boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false; } } } if(num >= 0) { bool[0] = false; bool[1] = false; } return bool; } static long modInverse(long a, long m) { long g = gcd(a, m); return power(a, m - 2, m); } static long power(long x, long y, long m){ if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (int)((p * (long)p) % m); if (y % 2 == 0) return p; else return (int)((x * (long)p) % m); } static class Combinations{ private long[] z; private long[] z1; private long[] z2; long MOD; public Combinations(long N , long mod) { MOD = mod; z = new long[(int)N+1]; z1 = new long[(int)N+1]; z[0] = 1; for(int i =1 ; i<=N ; i++) z[i] = (z[i-1]*i)%MOD; z2 = new long[(int)N+1]; z2[0] = z2[1] = 1; for (int i = 2; i <= N; i++) z2[i] = z2[(int)(MOD % i)] * (MOD - MOD / i) % MOD; z1[0] = z1[1] = 1; for (int i = 2; i <= N; i++) z1[i] = (z2[i] * z1[i - 1]) % MOD; } long fac(long n) { return z[(int)n]; } long invrsNum(long n) { return z2[(int)n]; } long invrsFac(long n) { return invrsFac((int)n); } long ncr(long N, long R) { if(R<0 || R>N ) return 0; long ans = ((z[(int)N] * z1[(int)R]) % MOD * z1[(int)(N - R)]) % MOD; return ans; } } static class DisjointUnionSets { int[] rank, parent; int n; public DisjointUnionSets(int n) { rank = new int[n]; parent = new int[n]; this.n = n; makeSet(); } void makeSet() { for (int i = 0; i < n; i++) { parent[i] = i; } } int find(int x) { if (parent[x] != x) { parent[x] = find(parent[x]); } return parent[x]; } void union(int x, int y) { int xRoot = find(x), yRoot = find(y); if (xRoot == yRoot) return; if (rank[xRoot] < rank[yRoot]) parent[xRoot] = yRoot; else if (rank[yRoot] < rank[xRoot]) parent[yRoot] = xRoot; else { parent[yRoot] = xRoot; rank[xRoot] = rank[xRoot] + 1; } } } static int[] KMP(String str) { int n = str.length(); int[] kmp = new int[n]; for(int i = 1 ; i<n ; i++) { int j = kmp[i-1]; while(j>0 && str.charAt(i) != str.charAt(j)) { j = kmp[j-1]; } if(str.charAt(i) == str.charAt(j)) j++; kmp[i] = j; } return kmp; } /************************************************ Query **************************************************************************************/ /***************************************** Sparse Table ********************************************************/ static class SparseTable{ private long[][] st; SparseTable(long[] arr){ int n = arr.length; st = new long[n][25]; log = new int[n+2]; build_log(n+1); build(arr); } private void build(long[] arr) { int n = arr.length; for(int i = n-1 ; i>=0 ; i--) { for(int j = 0 ; j<25 ; j++) { int r = i + (1<<j)-1; if(r>=n) break; if(j == 0 ) st[i][j] = arr[i]; else st[i][j] = Math.min(st[i][j-1] , st[ i + ( 1 << (j-1) ) ][ j-1 ] ); } } } public long gcd(long a ,long b) { if(a == 0) return b; return gcd(b%a , a); } public long query(int l ,int r) { int w = r-l+1; int power = log[w]; return Math.min(st[l][power],st[r - (1<<power) + 1][power]); } private int[] log; void build_log(int n) { log[1] = 0; for(int i = 2 ; i<=n ; i++) { log[i] = 1 + log[i/2]; } } } /******************************************************** Segement Tree *****************************************************/ /** static class SegmentTree{ long[] tree; long[] arr; int n; SegmentTree(long[] arr){ this.n = arr.length; tree = new long[4*n+1]; this.arr = arr; buildTree(0, n-1, 1); } void buildTree(int s ,int e ,int index ) { if(s == e) { tree[index] = arr[s]; return; } int mid = (s+e)/2; buildTree( s, mid, 2*index); buildTree( mid+1, e, 2*index+1); tree[index] = Math.min(tree[2*index] , tree[2*index+1]); } long query(int si ,int ei) { return query(0 ,n-1 , si ,ei , 1 ); } private long query( int ss ,int se ,int qs , int qe,int index) { if(ss>=qs && se<=qe) return tree[index]; if(qe<ss || se<qs) return (long)(1e17); int mid = (ss + se)/2; long left = query( ss , mid , qs ,qe , 2*index); long right= query(mid + 1 , se , qs ,qe , 2*index+1); return Math.min(left, right); } public void update(int index , int val) { arr[index] = val; for(long e:arr) System.out.print(e+" "); update(index , 0 , n-1 , 1); } private void update(int id ,int si , int ei , int index) { if(id < si || id>ei) return; if(si == ei ) { tree[index] = arr[id]; return; } if(si > ei) return; int mid = (ei + si)/2; update( id, si, mid , 2*index); update( id , mid+1, ei , 2*index+1); tree[index] = Math.min(tree[2*index] ,tree[2*index+1]); } } */ /* ***************************************************************************************************************************************************/ static Reader sc = new Reader(); static StringBuilder sb = new StringBuilder(); public static void main(String args[]) { int tc = 1; // tc = sc.nextInt(); for(int i = 1 ; i<=tc ; i++) { // sb.append("Case #" + i + ": " ); // During KickStart && HackerCup TEST_CASE(); } System.out.println(sb); } static void TEST_CASE() { int a = sc.nextInt() , b = sc.nextInt() , k = sc.nextInt(); if(k == 0) { LinkedList<Integer> ll = new LinkedList<>(); while(b-- > 0) ll.add(1); while(a-- > 0) ll.addLast(0); sb.append("YES\n"); for(int e:ll) sb.append(e); sb.append("\n"); for(int e:ll) sb.append(e ); sb.append("\n"); return; } LinkedList<Integer> one = new LinkedList<>(); LinkedList<Integer> sec = new LinkedList<>(); if(a+b-2<k) { sb.append("NO\n"); return; } one.add(1); one.add(1); sec.add(1); sec.add(0); k--; a--; b-=2; if(a<0 || b<0) { sb.append("NO\n"); return; } while(k-->0) { if(a>0) { one.add(0); sec.add(0); a--; }else if(b > 0) { one.add(1); sec.add(1); b--; } } one.add(0); sec.add(1); while(a-->0) { one.add(0); sec.add(0); } while(b-- > 0) { one.add(1); sec.add(1); } sb.append("YES\n"); for(int e:one) sb.append(e); sb.append("\n"); for(int e:sec) sb.append(e ); sb.append("\n"); } } /*******************************************************************************************************************************************************/ /** k == 0 simple a b c 1 0 0 1 1 0 0 -1 0 0 0 1 1 0 1 -1 -1 max a-1 + b-1 + 1 = a + b - 1 >=c */
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
fedfab06fd00658e149c33dbd45bcf90
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class D { public static class FastIO { BufferedReader br; BufferedWriter bw, be; StringTokenizer st; public FastIO() { br = new BufferedReader(new InputStreamReader(System.in)); bw = new BufferedWriter(new OutputStreamWriter(System.out)); be = new BufferedWriter(new OutputStreamWriter(System.err)); st = new StringTokenizer(""); } private void read() throws IOException { st = new StringTokenizer(br.readLine()); } public String ns() throws IOException { while(!st.hasMoreTokens()) read(); return st.nextToken(); } public int ni() throws IOException { return Integer.parseInt(ns()); } public long nl() throws IOException { return Long.parseLong(ns()); } public float nf() throws IOException { return Float.parseFloat(ns()); } public double nd() throws IOException { return Double.parseDouble(ns()); } public char nc() throws IOException { return ns().charAt(0); } public int[] nia(int n) throws IOException { int[] a = new int[n]; for(int i = 0; i < n; i++) a[i] = ni(); return a; } public long[] nla(int n) throws IOException { long[] a = new long[n]; for(int i = 0; i < n; i++) a[i] = nl(); return a; } public char[] nca() throws IOException { return ns().toCharArray(); } public void out(String s) throws IOException { bw.write(s); } public void flush() throws IOException { bw.flush(); be.flush(); } public void err(String s) throws IOException { be.write(s); } } static FastIO f; public static void main(String args[]) throws IOException { f = new FastIO(); int a = f.ni(), b = f.ni(), k = f.ni(), i, c; if(a == 0) { if(k > 0) f.out("No\n"); else { f.out("Yes\n"); for(i = 0; i < b; i++) f.out("1"); f.out("\n"); for(i = 0; i < b; i++) f.out("1"); f.out("\n"); } } else if(b == 1) { if(k > 0) f.out("No\n"); else { f.out("Yes\n1"); for(i = 0; i < a; i++) f.out("0"); f.out("\n1"); for(i = 0; i < a; i++) f.out("0"); f.out("\n"); } } else if(k >= a+b-1) f.out("No\n"); else { f.out("Yes\n"); int x[][] = new int[a+b][2]; b--; x[a+b] = new int[]{0, 1}; if(k == 0) x[a+b][0] = 1; else x[a+b-k] = new int[]{1, 0}; for(i = 0, c = 0; c < b; i++) { if(x[i][0] == 1) continue; x[i][0]++; x[i][1]++; c++; } for(i = 0; i <= a+b; i++) f.out("" + x[i][0]); f.out("\n"); for(i = 0; i <= a+b; i++) f.out("" + x[i][1]); f.out("\n"); } f.flush(); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
429e32171592e77937a80180002edc3b
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.io.*; public class four { public static void main(String[] args) throws IOException, FileNotFoundException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader in = new BufferedReader(new FileReader("four")); int t = 1; while (t-- > 0) { StringTokenizer st = new StringTokenizer(in.readLine()); int a = Integer.parseInt(st.nextToken()); int b = Integer.parseInt(st.nextToken()); int k = Integer.parseInt(st.nextToken()); if (k == 0) { System.out.println("Yes"); char[] first = new char[a+b]; int n = a+b; int i=0; for (; i<n && b>0; i++ ) { first[i] = '1'; b--; } for (; i<n; i++) { first[i] = '0'; } System.out.println(new String(first)); System.out.println(new String(first)); continue; } if (b < 2 || a < 1) { System.out.println("No"); continue; } char[] first = new char[a+b]; char[] second = new char[a+b]; int n = a+b; if (k+1 >= n) { System.out.println("No"); continue; } first[0] = second[0] = '1'; first[1] = '1'; second[1] = '0'; first[k+1] = '0'; second[k+1] = '1'; b-=2; a--; int i=2; for (; i<=k && b>0; i++) { first[i] = second[i] = '1'; b--; } for (; i<=k && a>0; i++) { first[i] = second[i] = '0'; a--; } if (i <= k) { System.out.println("No"); continue; } i = k+2; for (; i<n && b>0; i++) { first[i] = second[i] = '1'; b--; } for (; i<n && a>0; i++) { first[i] = second[i] = '0'; a--; } System.out.println("Yes"); System.out.println(new String(first)); System.out.println(new String(second)); } } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
5b91142479b6890b21121bf147f72a11
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 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(); String s[]=bu.readLine().split(" "); int i,a=Integer.parseInt(s[0]),b=Integer.parseInt(s[1]),k=Integer.parseInt(s[2]); if(a==0) { if(k>0) {System.out.println("No"); return;} sb.append("Yes\n"); for(i=0;i<b;i++) sb.append(1); sb.append("\n"); for(i=0;i<b;i++) sb.append(1); sb.append("\n"); System.out.print(sb); return; } if(b==1) { if(k>0) {System.out.println("No"); return;} sb.append("Yes\n1"); for(i=0;i<a;i++) sb.append(0); sb.append("\n1"); for(i=0;i<a;i++) sb.append(0); sb.append("\n"); System.out.print(sb); return; } if(k>(a+b-2)) {System.out.println("No"); return;} if(k<=a) { sb.append("Yes\n"); int n=a+b,x[]=new int[n],y[]=new int[n]; for(i=0;i<b-1;i++) { x[i]=y[i]=1; } y[n-1]=1; x[n-1-k]=1; for(i=0;i<n;i++) sb.append(x[i]); sb.append("\n"); for(i=0;i<n;i++) sb.append(y[i]); sb.append("\n"); } else { sb.append("Yes\n"); int n=a+b,x[]=new int[n],y[]=new int[n]; y[n-1]=1; x[n-1-k]=1; x[0]=y[0]=1; int rb=b-2; for(i=n-1-k+1;i<n-1 && rb>0;i++,rb--) x[i]=y[i]=1; i=1; while(rb>0) { x[i]=y[i]=1; i++; rb--; } for(i=0;i<n;i++) sb.append(x[i]); sb.append("\n"); for(i=0;i<n;i++) sb.append(y[i]); sb.append("\n"); } System.out.print(sb); } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output
PASSED
2473dc3847cb1c4e608b7622ec0a8528
train_109.jsonl
1614071100
You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones; $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones. You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.
512 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.awt.*; // U KNOW THAT IF THIS DAY WILL BE URS THEN NO ONE CAN DEFEAT U HERE................ //JUst keep faith in ur strengths .................................................. // ASCII = 48 + i ;// 2^28 = 268,435,456 > 2* 10^8 // log 10 base 2 = 3.3219 // odd:: (x^2+1)/2 , (x^2-1)/2 ; x>=3// even:: (x^2/4)+1 ,(x^2/4)-1 x >=4 // FOR ANY ODD NO N : N,N-1,N-2 //ALL ARE PAIRWISE COPRIME //THEIR COMBINED LCM IS PRODUCT OF ALL THESE NOS // two consecutive odds are always coprime to each other // two consecutive even have always gcd = 2 ; // Rectangle r = new Rectangle(int x , int y,int widht,int height) //Creates a rect. with bottom left cordinates as (x, y) and top right as ((x+width),(y+height)) //BY DEFAULT Priority Queue is MIN in nature in java //to use as max , just push with negative sign and change sign after removal // We can make a sieve of max size 1e7 .(no time or space issue) // In 1e7 starting nos we have about 66*1e4 prime nos // In 1e6 starting nos we have about 78,498 prime nos public class Main { // static int[] arr = new int[100002] ; // static int[] dp = new int[100002] ; static PrintWriter out; static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); } String next(){ while(st==null || !st.hasMoreElements()){ try{ st= new StringTokenizer(br.readLine()); } catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str = ""; try{ str=br.readLine(); } catch(IOException e){ e.printStackTrace(); } return str; } } //////////////////////////////////////////////////////////////////////////////////// public static int countDigit(long n) { return (int)Math.floor(Math.log10(n) + 1); } ///////////////////////////////////////////////////////////////////////////////////////// public static int sumOfDigits(long n) { if( n< 0)return -1 ; int sum = 0; while( n > 0) { sum = sum + (int)( n %10) ; n /= 10 ; } return sum ; } ////////////////////////////////////////////////////////////////////////////////////////////////// public static long arraySum(int[] arr , int start , int end) { long ans = 0 ; for(int i = start ; i <= end ; i++)ans += arr[i] ; return ans ; } ///////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// public static void swapArray(int[] arr , int start , int end) { while(start < end) { int temp = arr[start] ; arr[start] = arr[end]; arr[end] = temp; start++ ;end-- ; } } ////////////////////////////////////////////////////////////////////////////////// static long factorial(long a) { if(a== 0L || a==1L)return 1L ; return a*factorial(a-1L) ; } /////////////////////////////////////////////////////////////////////////////// public static int[][] rotate(int[][] input){ int n =input.length; int m = input[0].length ; int[][] output = new int [m][n]; for (int i=0; i<n; i++) for (int j=0;j<m; j++) output [j][n-1-i] = input[i][j]; return output; } /////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////// //////////////////////////////////////////////// public static boolean isPowerOfTwo(long n) { if(n==0) return false; if(((n ) & (n-1)) == 0 ) return true ; else return false ; } ///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// public static String reverse(String input) { StringBuilder str = new StringBuilder("") ; for(int i =input.length()-1 ; i >= 0 ; i-- ) { str.append(input.charAt(i)); } return str.toString() ; } /////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// public static boolean isPossibleTriangle(int a ,int b , int c) { if( a + b > c && c+b > a && a +c > b)return true ; else return false ; } //////////////////////////////////////////////////////////////////////////////////////////// static long xnor(long num1, long num2) { if (num1 < num2) { long temp = num1; num1 = num2; num2 = temp; } num1 = togglebit(num1); return num1 ^ num2; } static long togglebit(long n) { if (n == 0) return 1; long i = n; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; return i ^ n; } /////////////////////////////////////////////////////////////////////////////////////////////// public static int xorOfFirstN(int n) { if( n % 4 ==0)return n ; else if( n % 4 == 1)return 1 ; else if( n % 4 == 2)return n+1 ; else return 0 ; } ////////////////////////////////////////////////////////////////////////////////////////////// public static int gcd(int a, int b ) { if(b==0)return a ; else return gcd(b,a%b) ; } public static long gcd(long a, long b ) { if(b==0)return a ; else return gcd(b,a%b) ; } //////////////////////////////////////////////////////////////////////////////////// public static int lcm(int a, int b ,int c , int d ) { int temp = lcm(a,b , c) ; int ans = lcm(temp ,d ) ; return ans ; } /////////////////////////////////////////////////////////////////////////////////////////// public static int lcm(int a, int b ,int c ) { int temp = lcm(a,b) ; int ans = lcm(temp ,c) ; return ans ; } //////////////////////////////////////////////////////////////////////////////////////// public static int lcm(int a , int b ) { int gc = gcd(a,b); return (a/gc)*b ; } public static long lcm(long a , long b ) { long gc = gcd(a,b); return (a/gc)*b; } /////////////////////////////////////////////////////////////////////////////////////////// static boolean isPrime(long n) { if(n==1) { return false ; } boolean ans = true ; for(long i = 2L; i*i <= n ;i++) { if(n% i ==0) { ans = false ;break ; } } return ans ; } static boolean isPrime(int n) { if(n==1) { return false ; } boolean ans = true ; for(int i = 2; i*i <= n ;i++) { if(n% i ==0) { ans = false ;break ; } } return ans ; } /////////////////////////////////////////////////////////////////////////// static int sieve = 1000000 ; static boolean[] prime = new boolean[sieve + 1] ; public static void sieveOfEratosthenes() { // FALSE == prime // TRUE == COMPOSITE // FALSE== 1 // time complexity = 0(NlogLogN)== o(N) // gives prime nos bw 1 to N for(int i = 4; i<= sieve ; i++) { prime[i] = true ; i++ ; } for(int p = 3; p*p <= sieve; p++) { if(prime[p] == false) { for(int i = p*p; i <= sieve; i += p) prime[i] = true; } p++ ; } } /////////////////////////////////////////////////////////////////////////////////// public static void sortD(int[] arr , int s , int e) { sort(arr ,s , e) ; int i =s ; int j = e ; while( i < j) { int temp = arr[i] ; arr[i] =arr[j] ; arr[j] = temp ; i++ ; j-- ; } return ; } ///////////////////////////////////////////////////////////////////////////////////////// public static long countSubarraysSumToK(long[] arr ,long sum ) { HashMap<Long,Long> map = new HashMap<>() ; int n = arr.length ; long prefixsum = 0 ; long count = 0L ; for(int i = 0; i < n ; i++) { prefixsum = prefixsum + arr[i] ; if(sum == prefixsum)count = count+1 ; if(map.containsKey(prefixsum -sum)) { count = count + map.get(prefixsum -sum) ; } if(map.containsKey(prefixsum )) { map.put(prefixsum , map.get(prefixsum) +1 ); } else{ map.put(prefixsum , 1L ); } } return count ; } /////////////////////////////////////////////////////////////////////////////////////////////// // KMP ALGORITHM : TIME COMPL:O(N+M) // FINDS THE OCCURENCES OF PATTERN AS A SUBSTRING IN STRING //RETURN THE ARRAYLIST OF INDEXES // IF SIZE OF LIST IS ZERO MEANS PATTERN IS NOT PRESENT IN STRING public static ArrayList<Integer> kmpAlgorithm(String str , String pat) { ArrayList<Integer> list =new ArrayList<>(); int n = str.length() ; int m = pat.length() ; String q = pat + "#" + str ; int[] lps =new int[n+m+1] ; longestPefixSuffix(lps, q,(n+m+1)) ; for(int i =m+1 ; i < (n+m+1) ; i++ ) { if(lps[i] == m) { list.add(i-2*m) ; } } return list ; } public static void longestPefixSuffix(int[] lps ,String str , int n) { lps[0] = 0 ; for(int i = 1 ; i<= n-1; i++) { int l = lps[i-1] ; while( l > 0 && str.charAt(i) != str.charAt(l)) { l = lps[l-1] ; } if(str.charAt(i) == str.charAt(l)) { l++ ; } lps[i] = l ; } } /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// // CALCULATE TOTIENT Fn FOR ALL VALUES FROM 1 TO n // TOTIENT(N) = count of nos less than n and grater than 1 whose gcd with n is 1 // or n and the no will be coprime in nature //time : O(n*(log(logn))) public static void eulerTotientFunction(int[] arr ,int n ) { for(int i = 1; i <= n ;i++)arr[i] =i ; for(int i= 2 ; i<= n ;i++) { if(arr[i] == i) { arr[i] =i-1 ; for(int j =2*i ; j<= n ; j+= i ) { arr[j] = (arr[j]*(i-1))/i ; } } } return ; } ///////////////////////////////////////////////////////////////////////////////////////////// public static long nCr(int n,int k) { long ans=1L; k=k>n-k?n-k:k; int j=1; for(;j<=k;j++,n--) { if(n%j==0) { ans*=n/j; }else if(ans%j==0) { ans=ans/j*n; }else { ans=(ans*n)/j; } } return ans; } /////////////////////////////////////////////////////////////////////////////////////////// public static ArrayList<Integer> allFactors(int n) { ArrayList<Integer> list = new ArrayList<>() ; for(int i = 1; i*i <= n ;i++) { if( n % i == 0) { if(i*i == n) { list.add(i) ; } else{ list.add(i) ; list.add(n/i) ; } } } return list ; } public static ArrayList<Long> allFactors(long n) { ArrayList<Long> list = new ArrayList<>() ; for(long i = 1L; i*i <= n ;i++) { if( n % i == 0) { if(i*i == n) { list.add(i) ; } else{ list.add(i) ; list.add(n/i) ; } } } return list ; } //////////////////////////////////////////////////////////////////////////////////////////////////// static final int MAXN = 1000001; static int spf[] = new int[MAXN]; static void sieve() { spf[1] = 1; for (int i=2; i<MAXN; i++) spf[i] = i; for (int i=4; i<MAXN; i+=2) spf[i] = 2; for (int i=3; i*i<MAXN; i++) { if (spf[i] == i) { for (int j=i*i; j<MAXN; j+=i) if (spf[j]==j) spf[j] = i; } } } static ArrayList<Integer> getPrimeFactorization(int x) { ArrayList<Integer> ret = new ArrayList<Integer>(); while (x != 1) { ret.add(spf[x]); x = x / spf[x]; } return ret; } ////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// public static void merge(int arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ int L[] = new int[n1]; int R[] = new int[n2]; //Copy data to temp arrays for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } // Main function that sorts arr[l..r] using // merge() public static void sort(int arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l+r)/2; // Sort first and second halves sort(arr, l, m); sort(arr , m+1, r); // Merge the sorted halves merge(arr, l, m, r); } } public static void sort(long arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l+r)/2; // Sort first and second halves sort(arr, l, m); sort(arr , m+1, r); // Merge the sorted halves merge(arr, l, m, r); } } public static void merge(long arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ long L[] = new long[n1]; long R[] = new long[n2]; //Copy data to temp arrays for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } ///////////////////////////////////////////////////////////////////////////////////////// public static long knapsack(int[] weight,long value[],int maxWeight){ int n= value.length ; //dp[i] stores the profit with KnapSack capacity "i" long []dp = new long[maxWeight+1]; //initially profit with 0 to W KnapSack capacity is 0 Arrays.fill(dp, 0); // iterate through all items for(int i=0; i < n; i++) //traverse dp array from right to left for(int j = maxWeight; j >= weight[i]; j--) dp[j] = Math.max(dp[j] , value[i] + dp[j - weight[i]]); /*above line finds out maximum of dp[j](excluding ith element value) and val[i] + dp[j-wt[i]] (including ith element value and the profit with "KnapSack capacity - ith element weight") */ return dp[maxWeight]; } /////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// // to return max sum of any subarray in given array public static long kadanesAlgorithm(long[] arr) { if(arr.length == 0)return 0 ; long[] dp = new long[arr.length] ; dp[0] = arr[0] ; long max = dp[0] ; for(int i = 1; i < arr.length ; i++) { if(dp[i-1] > 0) { dp[i] = dp[i-1] + arr[i] ; } else{ dp[i] = arr[i] ; } if(dp[i] > max)max = dp[i] ; } return max ; } ///////////////////////////////////////////////////////////////////////////////////////////// public static long kadanesAlgorithm(int[] arr) { if(arr.length == 0)return 0 ; long[] dp = new long[arr.length] ; dp[0] = arr[0] ; long max = dp[0] ; for(int i = 1; i < arr.length ; i++) { if(dp[i-1] > 0) { dp[i] = dp[i-1] + arr[i] ; } else{ dp[i] = arr[i] ; } if(dp[i] > max)max = dp[i] ; } return max ; } /////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// //TO GENERATE ALL(DUPLICATE ALSO EXIST) PERMUTATIONS OF A STRING // JUST CALL generatePermutation( str, start, end) start :inclusive ,end : exclusive //Function for swapping the characters at position I with character at position j public static String swapString(String a, int i, int j) { char[] b =a.toCharArray(); char ch; ch = b[i]; b[i] = b[j]; b[j] = ch; return String.valueOf(b); } //Function for generating different permutations of the string public static void generatePermutation(String str, int start, int end) { //Prints the permutations if (start == end-1) System.out.println(str); else { for (int i = start; i < end; i++) { //Swapping the string by fixing a character str = swapString(str,start,i); //Recursively calling function generatePermutation() for rest of the characters generatePermutation(str,start+1,end); //Backtracking and swapping the characters again. str = swapString(str,start,i); } } } //////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////// public static long factMod(long n, long mod) { if (n <= 1) return 1; long ans = 1; for (int i = 1; i <= n; i++) { ans = (ans * i) % mod; } return ans; } ///////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// public static long power(int a ,int b) { //time comp : o(logn) long x = (long)(a) ; long n = (long)(b) ; if(n==0)return 1 ; if(n==1)return x; long ans =1L ; while(n>0) { if(n % 2 ==1) { ans = ans *x ; } n = n/2L ; x = x*x ; } return ans ; } public static long power(long a ,long b) { //time comp : o(logn) long x = (a) ; long n = (b) ; if(n==0)return 1L ; if(n==1)return x; long ans =1L ; while(n>0) { if(n % 2 ==1) { ans = ans *x ; } n = n/2L ; x = x*x ; } return ans ; } //////////////////////////////////////////////////////////////////////////////////////////////////// public static long powerMod(long x, long n, long mod) { //time comp : o(logn) if(n==0)return 1L ; if(n==1)return x; long ans = 1; while (n > 0) { if (n % 2 == 1) ans = (ans * x) % mod; x = (x * x) % mod; n /= 2; } return ans; } ////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// /* lowerBound - finds largest element equal or less than value paased upperBound - finds smallest element equal or more than value passed if not present return -1; */ public static long lowerBound(long[] arr,long k) { long ans=-1; int start=0; int end=arr.length-1; while(start<=end) { int mid=(start+end)/2; if(arr[mid]<=k) { ans=arr[mid]; start=mid+1; } else { end=mid-1; } } return ans; } public static int lowerBound(int[] arr,int k) { int ans=-1; int start=0; int end=arr.length-1; while(start<=end) { int mid=(start+end)/2; if(arr[mid]<=k) { ans=arr[mid]; start=mid+1; } else { end=mid-1; } } return ans; } public static long upperBound(long[] arr,long k) { long ans=-1; int start=0; int end=arr.length-1; while(start<=end) { int mid=(start+end)/2; if(arr[mid]>=k) { ans=arr[mid]; end=mid-1; } else { start=mid+1; } } return ans; } public static int upperBound(int[] arr,int k) { int ans=-1; int start=0; int end=arr.length-1; while(start<=end) { int mid=(start+end)/2; if(arr[mid]>=k) { ans=arr[mid]; end=mid-1; } else { start=mid+1; } } return ans; } ////////////////////////////////////////////////////////////////////////////////////////// public static void printArray(int[] arr , int si ,int ei) { for(int i = si ; i <= ei ; i++) { out.print(arr[i] +" ") ; } } public static void printArrayln(int[] arr , int si ,int ei) { for(int i = si ; i <= ei ; i++) { out.print(arr[i] +" ") ; } out.println() ; } public static void printLArray(long[] arr , int si , int ei) { for(int i = si ; i <= ei ; i++) { out.print(arr[i] +" ") ; } } public static void printLArrayln(long[] arr , int si , int ei) { for(int i = si ; i <= ei ; i++) { out.print(arr[i] +" ") ; } out.println() ; } public static void printtwodArray(int[][] ans) { for(int i = 0; i< ans.length ; i++) { for(int j = 0 ; j < ans[0].length ; j++)out.print(ans[i][j] +" "); out.println() ; } out.println() ; } static long modPow(long a, long x, long p) { //calculates a^x mod p in logarithmic time. a = a % p ; if(a == 0)return 0L ; long res = 1L; while(x > 0) { if( x % 2 != 0) { res = (res * a) % p; } a = (a * a) % p; x =x/2; } return res; } static long modInverse(long a, long p) { //calculates the modular multiplicative of a mod p. //(assuming p is prime). return modPow(a, p-2, p); } static long[] factorial = new long[1000001] ; static void modfac(long mod) { factorial[0]=1L ; factorial[1]=1L ; for(int i = 2; i<= 1000000 ;i++) { factorial[i] = factorial[i-1] *(long)(i) ; factorial[i] = factorial[i] % mod ; } } static long modBinomial(long n, long r, long p) { // calculates C(n,r) mod p (assuming p is prime). if(n < r) return 0L ; long num = factorial[(int)(n)] ; long den = (factorial[(int)(r)]*factorial[(int)(n-r)]) % p ; long ans = num*(modInverse(den,p)) ; ans = ans % p ; return ans ; } static void update(int val , long[] bit ,int n) { for( ; val <= n ; val += (val &(-val)) ) { bit[val]++ ; } } static long query(int val , long[] bit , int n) { long ans = 0L; for( ; val >=1 ; val-=(val&(-val)) )ans += bit[val]; return ans ; } static int countSetBits(long n) { int count = 0; while (n > 0) { n = (n) & (n - 1L); count++; } return count; } static int abs(int x) { if(x < 0)x = -1*x ; return x ; } static long abs(long x) { if(x < 0)x = -1L*x ; return x ; } //////////////////////////////////////////////////////////////////////////////////////////////// static void p(int val) { out.print(val) ; } static void p() { out.print(" ") ; } static void pln(int val) { out.println(val) ; } static void pln() { out.println() ; } static void p(long val) { out.print(val) ; } static void pln(long val) { out.println(val) ; } static void yes() { out.println("YES") ; } static void no() { out.println("NO") ; } //////////////////////////////////////////////////////////////////////////////////////////// // calculate total no of nos greater than or equal to key in sorted array arr static int bs(int[] arr, int s ,int e ,int key) { if( s> e)return 0 ; int mid = (s+e)/2 ; if(arr[mid] <key) { return bs(arr ,mid+1,e , key) ; } else{ return bs(arr ,s ,mid-1, key) + e-mid+1; } } // static ArrayList<Integer>[] adj ; // static int mod= 1000000007 ; ////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// public static void solve() { FastReader scn = new FastReader() ; //Scanner scn = new Scanner(System.in); //int[] store = {2 ,3, 5 , 7 ,11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 } ; // product of first 11 prime nos is greater than 10 ^ 12; //sieve() ; //ArrayList<Integer> arr[] = new ArrayList[n] ; ArrayList<Integer> list = new ArrayList<>() ; ArrayList<Integer> lx = new ArrayList<>() ; ArrayList<Integer> ly = new ArrayList<>() ; //ArrayList<String> lists = new ArrayList<>() ; HashMap<Integer,Integer> map = new HashMap<>() ; //HashMap<Long,Long> map = new HashMap<>() ; HashMap<Integer,Integer> mapx = new HashMap<>() ; HashMap<Integer,Integer> mapy = new HashMap<>() ; //HashMap<String,Integer> maps = new HashMap<>() ; //HashMap<Integer,Boolean> mapb = new HashMap<>() ; //HashMap<Point,Integer> point = new HashMap<>() ; Set<Integer> set = new HashSet<>() ; Set<Integer> setx = new HashSet<>() ; Set<Integer> sety = new HashSet<>() ; StringBuilder sb =new StringBuilder("") ; //Collections.sort(list); //if(map.containsKey(arr[i]))map.put(arr[i] , map.get(arr[i]) +1 ) ; //else map.put(arr[i],1) ; // if(map.containsKey(temp))map.put(temp , map.get(temp) +1 ) ; // else map.put(temp,1) ; //int bit =Integer.bitCount(n); // gives total no of set bits in n; // Arrays.sort(arr, new Comparator<Pair>() { // @Override // public int compare(Pair a, Pair b) { // if (a.first != b.first) { // return a.first - b.first; // for increasing order of first // } // return a.second - b.second ; //if first is same then sort on second basis // } // }); int testcase = 1; //testcase = scn.nextInt() ; for(int testcases =1 ; testcases <= testcase ;testcases++) { //if(map.containsKey(arr[i]))map.put(arr[i],map.get(arr[i])+1) ;else map.put(arr[i],1) ; //if(map.containsKey(temp))map.put(temp,map.get(temp)+1) ;else map.put(temp,1) ; //adj = new ArrayList[n] ; // for(int i = 0; i< n; i++) // { // adj[i] = new ArrayList<Integer>(); // } // long n = scn.nextLong() ; //String s = scn.next() ; int a = scn.nextInt() ;int b = scn.nextInt() ;int k = scn.nextInt() ; // a-zeros and b -ones if(k == 0) { out.println("Yes") ; int g =a ;int h =b ; while(b--> 0)out.print(1) ;while(a--> 0) out.print(0) ; out.println() ; while(h--> 0)out.print(1) ;while(g--> 0) out.print(0) ; } else if(a== 0 || b==1)out.println("No") ; else { // a>0 && b >1 && k> 0 if(k == a+b || k== a+b-1)out.println("No") ; else{ out.println("Yes") ; lx.add(1) ;ly.add(0) ; int tempz =a ;int tempo =b ; tempz-- ;tempo-- ; int c = 0 ; while(c< k-1) { if(tempz>0) { lx.add(0) ; ly.add(0) ; tempz-- ; } else{ lx.add(1) ; ly.add(1) ; tempo-- ; } c++ ; } lx.add(0) ;ly.add(1) ; ArrayList<Integer> la = new ArrayList<>() ; ArrayList<Integer> lb = new ArrayList<>() ; la.add(1) ;lb.add(1) ;tempo-- ; while(true) { if(tempz+tempo == 0)break ; if(tempz>0) { la.add(0) ; lb.add(0) ; tempz-- ; } else { la.add(1) ; lb.add(1) ; tempo-- ; } } for(int x: la)out.print(x) ; for(int x: lx)out.print(x) ; out.println() ; for(int x: lb)out.print(x) ; for(int x: ly)out.print(x) ; } } //out.println(ans) ; //out.println(ans+" "+in) ; //out.println("Case #" + testcases + ": " + ans ) ; //out.println("@") ; set.clear() ; sb.delete(0 , sb.length()) ; //list.clear() ;lista.clear() ;listb.clear() ; map.clear() ; mapx.clear() ; mapy.clear() ; setx.clear() ;sety.clear() ; } // test case end loop out.flush() ; } // solve fn ends public static void main (String[] args) throws java.lang.Exception { solve() ; } } class Pair { int first ; int second ; public Pair(int x, int y) { this.first = x ;this.second = y ; } @Override public boolean equals(Object obj) { if(obj == this)return true ; if(obj == null)return false ; if(this.getClass() != obj.getClass()) { return false ; } Pair other = (Pair)(obj) ; if(this.first != other.first)return false ; if(this.second != other.second)return false ; return true ; } @Override public int hashCode() { return this.first^this.second ; } @Override public String toString() { String ans = "" ; ans += this.first ; ans += " "; ans += this.second ; return ans ; } }
Java
["4 2 3", "3 2 1", "3 2 5"]
2 seconds
["Yes\n101000\n100001", "Yes\n10100\n10010", "No"]
NoteIn the first example, $$$x = 101000_2 = 2^5 + 2^3 = 40_{10}$$$, $$$y = 100001_2 = 2^5 + 2^0 = 33_{10}$$$, $$$40_{10} - 33_{10} = 7_{10} = 2^2 + 2^1 + 2^0 = 111_{2}$$$. Hence $$$x-y$$$ has $$$3$$$ ones in base-2.In the second example, $$$x = 10100_2 = 2^4 + 2^2 = 20_{10}$$$, $$$y = 10010_2 = 2^4 + 2^1 = 18$$$, $$$x - y = 20 - 18 = 2_{10} = 10_{2}$$$. This is precisely one 1.In the third example, one may show, that it's impossible to find an answer.
Java 11
standard input
[ "bitmasks", "constructive algorithms", "greedy", "math" ]
ea620a8dbef506567464dcaddcc2b34f
The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.
1,900
If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.
standard output