CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:Totska
Submission time:2021-10-17 19:09:52 +0300
Language:C++ (C++17)
Status:READY
Result:40
Feedback
groupverdictscore
#1ACCEPTED40
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#50.01 s2, 3details
#60.01 s3details
#70.98 s3details

Code

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

vector<ll> sumtable = {0, 1};

ll getsum(ll a, ll b){

    return sumtable[b] - sumtable[a-1];
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;


    cin >> s;

    s.insert(0, "-");
    s.append("x");

    // cout << s;

    ll end, minimum, prevdist, start, mindist, MODULO;

    string ascii_lowercase = "abcdefghijklmnopqrstuvwxyz";
    end = s.length() - 1;
    
    vector<ll> maxnb(end, end+1);
    maxnb.push_back(-1);

    minimum = end + 1;

    map<char, ll> seen;

    for (ll i = 0; i < 26; i++)
    {
        seen[ascii_lowercase[i]] = end + 1;
    }


    map<ll, ll> last;

    for (ll i = 0; i < end+2; i++)
    {
        last[i] = -1;
    }
    
    deque<ll> distances;

    prevdist = 9999999;

    for (ll i = end; i > 0; i--)
    {
        minimum = min(minimum, seen[s[i]]);

        if(minimum < prevdist){
            distances.push_front(minimum);
            prevdist = minimum;
        }

        maxnb[i] = minimum;
        seen[s[i]] = i;

        last[maxnb[i]] = max(last[maxnb[i]], i);
    }
    
    start = 1;
    mindist = distances[0];
    distances.pop_front();

    for (ll i = 2; i < end + 1; i++)
    {
        if(i > mindist){
            start = last[mindist] + 1;

            mindist = distances[0];
            distances.pop_front();
        }

        sumtable.push_back(sumtable[i-1] + getsum(start, i-1));
    }

    MODULO = pow(10, 9) + 7;

    cout << getsum(end, end) % MODULO << endl;
    
}

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:

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
410550506

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
0

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
0