CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:ToukoP
Submission time:2021-10-06 23:50:16 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1, 2, 3details
#20.01 s1, 2, 3details
#30.01 s1, 2, 3details
#40.01 s1, 2, 3details
#50.01 s2, 3details
#60.03 s3details
#70.00 s3details

Code

#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

const int charCount = 26;
int toInt(char c) {
    return (int) c - 97;
}

unsigned long long all(unsigned long long len) {
    if (len < 0) len = 0;
    unsigned long long res = 1;
    for (unsigned long long i = 0; i < len; i++) {
        res *= 2;
    }
    return res;
}

unsigned long long solve(string value) {
    unsigned long long res = 1;
    unsigned long long history[value.length()];

    int chars [charCount];
    fill_n(chars, charCount, -1);

    for (unsigned long long i = 0; i < value.length(); i++) {

        int c = toInt(value[i]);
        if (chars[c] != -1) {
            unsigned long long start = history[chars[c]];
            unsigned long long end = all(i - chars[c]) - 1;
            cout <<"|  "<< value[i]  <<" res: "<< res <<" i: "<< i <<", last: "<< chars[c] <<", start: "<< start <<", end: "<< end <<endl;
            res += start * end;
        } else if (i != 0) {
            res *= 2;
        }
        cout << value.substr(0, i + 1) <<" = "<< res << endl;

        history[i] = res;
        chars[c] = i;
    }

    return res;
}

int main() {
    string str;
    cin >> str;
    cout << solve(str) % (1000000000 + 7);
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
a

correct output
1

user output
a = 1
1

Test 2

Group: 1, 2, 3

Verdict:

input
abcdefghij

correct output
512

user output
a = 1
ab = 2
abc = 4
abcd = 8
abcde = 16
...
Truncated

Test 3

Group: 1, 2, 3

Verdict:

input
abcabaacbc

correct output
120

user output
a = 1
ab = 2
abc = 4
|  a res: 4 i: 3, last: 0, sta...
Truncated

Test 4

Group: 1, 2, 3

Verdict:

input
aaxxxxxxaa

correct output
4

user output
a = 1
|  a res: 1 i: 1, last: 0, sta...
Truncated

Test 5

Group: 2, 3

Verdict:

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
m = 1
mf = 2
mfy = 4
mfyz = 8
mfyzv = 16
...
Truncated

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
w = 1
we = 2
wei = 4
wein = 8
weins = 16
...
Truncated

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
(empty)