CSES - Putka Open 2015 – 6/6 - Results
Submission details
Task:Bittilista
Sender:
Submission time:2015-12-07 00:22:47 +0200
Language:Java
Status:READY
Result:45
Feedback
groupverdictscore
#1ACCEPTED17
#2ACCEPTED28
#30
Test results
testverdicttimegroup
#1ACCEPTED0.20 s1details
#2ACCEPTED0.19 s1details
#3ACCEPTED0.20 s1details
#4ACCEPTED0.20 s1details
#5ACCEPTED0.19 s1details
#6ACCEPTED0.19 s2details
#7ACCEPTED0.19 s2details
#8ACCEPTED0.20 s2details
#9ACCEPTED0.20 s2details
#10ACCEPTED0.20 s2details
#110.20 s3details
#120.20 s3details
#130.19 s3details
#140.20 s3details
#150.20 s3details

Code

//package bittilista;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author Adreno
 */
public class Bittilista {

    public static boolean[] t;
    public static ArrayList<String> lista;
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt()-1;
        t = new boolean[n];
        
        //lista = new ArrayList<>();
        //StringBuilder sb = new StringBuilder();
        //rek(sb, 0, n-2);
        //Collections.sort(lista);
        //System.out.println(lista.get(k));
        
        int count = 0;
        String vastaus = "";
        long left = (long) Math.pow(2,n-1);
        while (count != k) {
            //System.out.println("string=" + vastaus + ", count="+count + ", k=" + k + ", left=" + left);
            left /= 2;
            if (count+left <= k) {
                vastaus += "1";
                count += left;
            }
            else {
                vastaus += "0";
            }
        }
        while (vastaus.length() < n-1) vastaus += "0";
        vastaus += vastaus.charAt(0);
        System.out.println(vastaus);
    }
    
    public static void rek(StringBuilder sb, int i, int n) {
        if (i==n) {
            lista.add("1" + sb.toString() + "1");
            lista.add("0" + sb.toString() + "0");
            return;
        }
        rek(sb.append("1"), i+1, n);
        sb.deleteCharAt(sb.length()-1);
        rek(sb.append("0"), i+1, n);
        sb.deleteCharAt(sb.length()-1);
    }
    
}

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:

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 Bittilista.main(Bittilista.java:20)

Test 12

Group: 3

Verdict:

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 Bittilista.main(Bittilista.java:20)

Test 13

Group: 3

Verdict:

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 Bittilista.main(Bittilista.java:20)

Test 14

Group: 3

Verdict:

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 Bittilista.main(Bittilista.java:20)

Test 15

Group: 3

Verdict:

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 Bittilista.main(Bittilista.java:20)