CSES - Datatähti 2019 alku - Results
Submission details
Task:Leimasin
Sender:ELlAS
Submission time:2018-10-14 14:19:15 +0300
Language:Java
Status:COMPILE ERROR

Compiler report

input/Main.java:1: error: package com.sun.org.apache.xpath.internal is not visible
import com.sun.org.apache.xpath.internal.SourceTree;
                               ^
  (package com.sun.org.apache.xpath.internal is declared in module java.xml, which does not export it to the unnamed module)
1 error

Code

import com.sun.org.apache.xpath.internal.SourceTree;

import java.util.Scanner;


public class Main {

    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);

        //  Syöte
        String text = scanner.nextLine();
        String stamp = scanner.nextLine();

        //  Sizes of strings
        int size = text.length();
        int length = stamp.length();


        //  Output lists
        int[][] indexList = new int[500][size - length + 1];

        //  Counters of stamps
        int counterOfStamps = 0;

        //  Tells, which index list stamp belongs
        int indexOfStamp = 0;

        //  Which character of text last stamp started
        int lastIndex = 0;
        //  If we delete too much indexes, no solutions
        int lastLastIndex = 0;

        //  Tells if last stamp ended
        boolean lastIndexWasLength = true;

        //  Tells in which index stamp checking starts
        int startIndex;

        //  Index of character of stamp
        int index = -1;
        for (int i = 0; i < size; i++) {
            ++index;
            //  If index is more than size of stamp: new stamp is needed
            if (index == length) {
                lastIndexWasLength = true;
                ++indexOfStamp;
                index = 0;
            }

            //  If not needed new stamp
            if (text.charAt(i) == stamp.charAt(index) && index != 0) {
                continue;
            }

            //  Needed new stamp
            for (index = 0; index < length; ++index) {

                //  Check if stamp index match text
                if (text.charAt(i) == stamp.charAt(index) && i - index > -1) {

                    //  If character is not frist index of stamp, have to be stamped before last stamp
                    if (index != 0){
                        //  If last stamp didn't end last stamp was miss
                        if (!lastIndexWasLength) {
                            indexList[indexOfStamp][lastIndex] = 0;
                            --counterOfStamps;

                            --index;
                            --index;
                            --i;

                            //  No solutions
                            if(index == -1){
                                System.out.println(-1);
                                System.exit(0);
                            }

                            if (lastLastIndex + length == i){
                                lastIndexWasLength = true;
                            }

                            continue;

                        }
                        ++indexOfStamp;
                    } else{
                        lastLastIndex = lastIndex;
                    }


                    //  Put index of stamp in the list
                    lastIndex = i - index;
                    indexList[indexOfStamp][lastIndex] = 1;
                    ++counterOfStamps;
                    lastIndexWasLength = false;

                    break;
                }
            }


            //  If not possible to stamp: print -1
            if (index == length) {
                System.out.println(-1);
                System.exit(0);
            }
        }



        //  Output
        System.out.println(counterOfStamps);
        System.out.println();

        for (; indexOfStamp > -1; --indexOfStamp) {
            int[] list = indexList[indexOfStamp];


            for (int i = 0; i < size - length + 1; ++i) {
                if (list[i] == 1) {
                    System.out.print((i + 1) + " ");
                }
            }
        }
    }

}