CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:andreibe
Submission time:2021-10-11 21:41:03 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED40
#2ACCEPTED25
#3ACCEPTED35
Test results
testverdicttimegroup
#1ACCEPTED0.12 s1, 2, 3details
#2ACCEPTED0.12 s1, 2, 3details
#3ACCEPTED0.12 s1, 2, 3details
#4ACCEPTED0.12 s1, 2, 3details
#5ACCEPTED0.12 s2, 3details
#6ACCEPTED0.13 s3details
#7ACCEPTED0.31 s3details

Code


import java.io.IOException;
import java.nio.file.Paths;
import java.util.Scanner;

public class Merkkijono {
    static int MODULO = 1_000_000_007;
    public static void main(String[] args) throws IOException {
        //Scanner scanner = new Scanner(System.in);
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();

        char[] ar = s.toCharArray();
        long total = 1;
        int last = -1;
        int[] chars = new int[123];
        for (int i = 97; i < chars.length; i++) {
            chars[i] = -1;
        }

        long[] totals = new long[s.length()];
        long[] removed = new long[s.length()];
        long rem=0;
        totals[0] = 1;
        chars[s.charAt(0)] = 0;

        for (int j = 1; j < ar.length; j++) {
            char c = ar[j];
            int i;
            total *= 2;
            if ((i = chars[c]) != -1 && i > last) { //sama kirjain
                last = i;
                long start = removed[i];
                if (start >= rem) {
                    rem += MODULO;
                }
                long extra = rem - start;
                long min = totals[i];
                if (min >= total) {
                    total += MODULO;
                }
                total -= (min-extra);
                rem += (min-extra);
                rem = rem % MODULO;
            }
            totals[j] = total;
            removed[j] = rem;
            total = total % MODULO;
            chars[c] = j;
        }
        System.out.println(total);
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
a

correct output
1

user output
1

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
abcdefghij

correct output
512

user output
512

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
abcabaacbc

correct output
120

user output
120

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
aaxxxxxxaa

correct output
4

user output
4

Test 5

Group: 2, 3

Verdict: ACCEPTED

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
643221148

Test 6

Group: 3

Verdict: ACCEPTED

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
831644159

Test 7

Group: 3

Verdict: ACCEPTED

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
816016015