| Task: | Bittilista |
| Sender: | |
| Submission time: | 2015-12-04 20:52:57 +0200 |
| Language: | Java |
| Status: | READY |
| Result: | 45 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 17 |
| #2 | ACCEPTED | 28 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.23 s | 1 | details |
| #2 | ACCEPTED | 0.20 s | 1 | details |
| #3 | ACCEPTED | 0.20 s | 1 | details |
| #4 | ACCEPTED | 0.21 s | 1 | details |
| #5 | ACCEPTED | 0.20 s | 1 | details |
| #6 | ACCEPTED | 0.40 s | 2 | details |
| #7 | ACCEPTED | 0.75 s | 2 | details |
| #8 | ACCEPTED | 0.41 s | 2 | details |
| #9 | ACCEPTED | 0.62 s | 2 | details |
| #10 | ACCEPTED | 0.58 s | 2 | details |
| #11 | RUNTIME ERROR | 0.19 s | 3 | details |
| #12 | RUNTIME ERROR | 0.20 s | 3 | details |
| #13 | RUNTIME ERROR | 0.19 s | 3 | details |
| #14 | RUNTIME ERROR | 0.20 s | 3 | details |
| #15 | RUNTIME ERROR | 0.19 s | 3 | details |
Code
import java.util.*;
public class bitti {
private static int lkm01(String sana1) {
char[] chars1 = sana1.toCharArray();
int xcount = 0;
int ind = 0;
char ex = 'x';
for (char c : chars1) {
if (ind == 0) ex = c;
else {
if ((ex == '0') && (c == '1')) xcount++;
}
ind++;
ex = c;
}
return xcount;
}
private static int lkm10(String sana1) {
char[] chars1 = sana1.toCharArray();
int xcount = 0;
int ind = 0;
char ex = 'x';
for (char c : chars1) {
if (ind == 0) ex = c;
else {
if ((ex == '1') && (c == '0')) xcount++;
}
ind++;
ex = c;
}
return xcount;
}
private static String seuraava(String sana1) {
String reverse = new StringBuffer(sana1).reverse().toString();
char[] chars1 = reverse.toCharArray();
String xans = "";
boolean loppu = false;
for (char c : chars1) {
if ((!loppu) && (c == '0')) {
xans = "1" + xans;
loppu = true;
}
else if (!loppu) {
xans = "0" + xans;
}
else {
xans = "" + c + xans;
}
}
return xans;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String ans = "";
int bitit = input.nextInt();
int nro = input.nextInt();
boolean end = false;
int laskin = 0;
for (int i = 0; i < bitit; i++) ans += "0";
while (!end) {
if (lkm01(ans) == lkm10(ans)) laskin++;
if (laskin == nro) end = true;
if (!end) ans = seuraava(ans);
}
System.out.println(ans);
}
}Test details
Test 1
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 10 54 |
| correct output |
|---|
| 0001101010 |
| user output |
|---|
| 0001101010 |
Test 2
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 10 302 |
| correct output |
|---|
| 1001011011 |
| user output |
|---|
| 1001011011 |
Test 3
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 10 241 |
| correct output |
|---|
| 0111100000 |
| user output |
|---|
| 0111100000 |
Test 4
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 10 382 |
| correct output |
|---|
| 1011111011 |
| user output |
|---|
| 1011111011 |
Test 5
Group: 1
Verdict: ACCEPTED
| input |
|---|
| 10 138 |
| correct output |
|---|
| 0100010010 |
| user output |
|---|
| 0100010010 |
Test 6
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 20 131002 |
| correct output |
|---|
| 00111111111101110010 |
| user output |
|---|
| 00111111111101110010 |
Test 7
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 20 441567 |
| correct output |
|---|
| 11010111100110111101 |
| user output |
|---|
| 11010111100110111101 |
Test 8
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 20 109770 |
| correct output |
|---|
| 00110101100110010010 |
| user output |
|---|
| 00110101100110010010 |
Test 9
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 20 327308 |
| correct output |
|---|
| 10011111110100010111 |
| user output |
|---|
| 10011111110100010111 |
Test 10
Group: 2
Verdict: ACCEPTED
| input |
|---|
| 20 302918 |
| correct output |
|---|
| 10010011111010001011 |
| user output |
|---|
| 10010011111010001011 |
Test 11
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 50 216967103451763 |
| correct output |
|---|
| 011000101010101001001011100100... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "216967103451763" at java.util.Scanner.nextInt(Scanner.java:2123) at java.util.Scanner.nextInt(Scanner.java:2076) at bitti.main(bitti.java:81)
Test 12
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 50 236618662270629 |
| correct output |
|---|
| 011010111001101000001001101001... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "236618662270629" at java.util.Scanner.nextInt(Scanner.java:2123) at java.util.Scanner.nextInt(Scanner.java:2076) at bitti.main(bitti.java:81)
Test 13
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 50 426560943304480 |
| correct output |
|---|
| 110000011111101000111010110000... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "426560943304480" at java.util.Scanner.nextInt(Scanner.java:2123) at java.util.Scanner.nextInt(Scanner.java:2076) at bitti.main(bitti.java:81)
Test 14
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 50 294553802415801 |
| correct output |
|---|
| 100001011111001010010011011000... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "294553802415801" at java.util.Scanner.nextInt(Scanner.java:2123) at java.util.Scanner.nextInt(Scanner.java:2076) at bitti.main(bitti.java:81)
Test 15
Group: 3
Verdict: RUNTIME ERROR
| input |
|---|
| 50 502225394100883 |
| correct output |
|---|
| 111001000110001010111011000110... |
| user output |
|---|
| (empty) |
Error:
Exception in thread "main" java.util.InputMismatchException: For input string: "502225394100883" at java.util.Scanner.nextInt(Scanner.java:2123) at java.util.Scanner.nextInt(Scanner.java:2076) at bitti.main(bitti.java:81)
