CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:kpop
Submission time:2021-10-07 16:53:05 +0300
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#20.01 s1, 2, 3details
#30.01 s1, 2, 3details
#40.01 s1, 2, 3details
#50.01 s2, 3details
#60.01 s3details
#70.88 s3details

Code

#include <bits/stdc++.h>

using namespace std;

int main() {
    string str; cin >> str;
    vector<int> pointsRight(str.length(), 0);
    unordered_set<char> seen;

    auto ita = str.rbegin();
    auto itb = ita+1;

    while (ita < str.rend()) {
        int bi = str.rend()-itb-1;

        if (seen.find(*itb) == seen.end() && itb != str.rend()) {
            if (seen.size() == 0) seen.insert(*ita);

            seen.insert(*itb);
            pointsRight[bi] += 1;
            ++itb;
        } else {
            ++ita;
            itb = ita+1;
            seen.clear();
        }
    }

    // cumulative sum
    for (int i = pointsRight.size()-1; i >= 0; --i) pointsRight[i] += pointsRight[i+1];

    int result = 0;
    auto itc = str.begin();
    auto itd = itc+1;

    seen.clear();

    while (itc < str.end()) {
        int di = distance(str.begin(), itd);

        if (seen.find(*itd) == seen.end() && itd < str.end()) {
            if (seen.size() == 0) {
                seen.insert(*itc);
                ++result;
            }

            seen.insert(*itd);
            result += pointsRight[di+1]+1;
            ++itd;
        } else {
            ++itc;
            itd = itc+1;
            seen.clear();
        }
    }

    ++result;

    cout << result%1000000007 << 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:

input
abcdefghij

correct output
512

user output
1750

Test 3

Group: 1, 2, 3

Verdict:

input
abcabaacbc

correct output
120

user output
578

Test 4

Group: 1, 2, 3

Verdict:

input
aaxxxxxxaa

correct output
4

user output
425

Test 5

Group: 2, 3

Verdict:

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
136618

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
354017435

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
203561726