CSES - Datatähti 2017 alku - Results
Submission details
Task:Bittijono
Sender:lumieer
Submission time:2016-10-09 17:58:07 +0300
Language:Java
Status:READY
Result:10
Feedback
groupverdictscore
#1ACCEPTED10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.17 s1details
#2--2details
#30.66 s3details

Code

//package bittijono;

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

public class Bittijono {

    public static void main(String[] args) {
        final Scanner lukija = new Scanner(System.in);
        
        int syotteidenMaara = lukija.nextInt();
        
        //StringBuilder syotteet = new StringBuilder();
        
        //Otetaan ne pari pistetta, korvaa ylemmalla kun jaksat
        ArrayList<Long> syotteet = new ArrayList<>();
        
        for (int o = 0; o < syotteidenMaara; o++) { 
            long syote = lukija.nextLong();
            syotteet.add(syote);
        }
        
        for (long syote : syotteet) {
                       
            long luku = syote;

            int pot = 0;
            /*
            for (int i = 0; i < 100; i++) {
                pot = potenssi(luku);
                //System.out.println("pot " + pot);
                //System.out.println("Laskettavien maara: " + (luku - Math.pow(2, pot)));
                luku = (long) (luku - Math.pow(2, pot));
                System.out.println("LUKU " + luku);
                if (luku <= 10) {
                    if (syote > 9) {
                        pot = pot + (i % 2);
                    }
                    System.out.println("Valmis! " + pot);
                    break;
                }                             
            }
           

            if (luku ==  0) {
                if (pot % 2 == 0) {
                    System.out.println("0");
                    return;
                } else {
                    System.out.println("1");
                    return;            
                }
            }
            
            
            System.out.println("JONOSTA");
            */
            
            StringBuilder jono = laskeBitteja(pot % 2, luku);

            System.out.println(jono.charAt((int) (luku - 1)));        
        }
    }
    
    public static StringBuilder laskeBitteja(int alku, long maara) {
        StringBuilder jono = new StringBuilder();
        //Luodaan nelinumeroinen jonon alku
        if (alku == 0) {
            jono.append("0110");
        } else {
            jono.append("1001");
        }
        //System.out.println(jono);   

        StringBuilder osa1 = new StringBuilder();
        StringBuilder osa2 = new StringBuilder();
        
        for (int i = 0; i < potenssi(maara) - 1; i++) {
            //Jaetaan jono kahteen osaan, ja lisataan ne jonoon
            osa1.append(jono.subSequence(jono.length() / 2, jono.length()));
            osa2.append(jono.subSequence(0, jono.length() / 2));
            
            //System.out.println("Jono " + jono);
            
            //System.out.println("OSA1 " + osa1);
            jono.append(osa1);
            
            //System.out.println("OSA2 " + osa2);
            jono.append(osa2);
            
            osa1.delete(0, osa1.length());
            osa2.delete(0, osa2.length());
        }
        
        return jono;
    }
    
    public static int potenssi(long syote) {
        
        double aiempi = syote * 1.0;
        int potenssi = 1;
        
        for (int i = 1; i <= 54; i++) {
            if (Math.pow(syote, 1.0 / i) - 2 >= 0 && Math.pow(syote, 1.0 / i) - 2 <= aiempi - 2) {
                aiempi = Math.pow(syote, 1.0 / i);
            } else {
                potenssi = i - 1;
                break;
            }
        }    
        return potenssi;
    }
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
100
62
9
12
73
...

correct output
1
1
1
0
1
...

user output
1
1
1
0
1
...

Test 2

Group: 2

Verdict:

input
100000
565433
141881
120108
825392
...

correct output
1
1
0
0
1
...

user output
(empty)

Test 3

Group: 3

Verdict:

input
100000
374768524402011755
937067109466254318
389256426086302899
932585725667010169
...

correct output
0
1
1
1
1
...

user output
(empty)

Error:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1040535958
	at java.lang.AbstractStringBuilder.charAt(AbstractStringBuilder.java:210)
	at java.lang.StringBuilder.charAt(StringBuilder.java:76)
	at Bittijono.main(Bittijono.java:62)