CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus (Partitioning)
Sender:ToukoP
Submission time:2021-10-16 13:39:23
Language:C++11
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.03 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;
}

vector<bool> toBinary(long n) {
    vector<bool> r;
    while(n != 0) {
        r.push_back(n % 2 != 0);
        n /= 2;
    }
    return r;
}

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

unsigned long isValid(string value, unsigned long parts) {
    vector<bool> binary = toBinary(parts);

    bool chars [charCount];
    fill_n(chars, charCount, false);
    
    chars[toInt(value[0])] = true;
    for (unsigned long i = 1; i < value.length(); i++) {

        if (i - 1 < binary.size() && binary[i - 1]) {
            fill_n(chars, charCount, false);
        }

        int c = toInt(value[i]);

        if (chars[c]) {
            return false;
        }

        chars[c] = true;
    }

    return true;
}

unsigned long mod = pow(10, 9) + 7;

unsigned long solve(string value) {
    unsigned long res = 0, n = pow((long) 2, value.length() -1);
    //cout << "Length " << n << endl;

    for (unsigned long i = 0; i < n; i++) {
        bool valid = isValid(value, i);
        if (valid) {
            res++;
            if (res == mod) res = 0;
        }
        //cout << value << (valid ? " Valid":"") << endl;
        vector<bool> bin = toBinary(i);
        for (unsigned long j = 0; j + 1 < value.length(); j++) {
            if (j >= bin.size()) {
                //cout << ",";
                continue;
            }
            //cout << (bin.at(j) ? "|" : ".");
        }
        //cout << endl;
    }
    return res;
}

int main() {
    string str;
    cin >> str;
    cout << solve(str);
}

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
0

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