CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus (Partitioning)
Sender:Kirill_Akimov
Submission time:2021-10-16 23:36:29
Language:PyPy3
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED40
#2ACCEPTED25
#3ACCEPTED35
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2, 3details
#2ACCEPTED0.04 s1, 2, 3details
#3ACCEPTED0.04 s1, 2, 3details
#4ACCEPTED0.04 s1, 2, 3details
#5ACCEPTED0.04 s2, 3details
#6ACCEPTED0.07 s3details
#7ACCEPTED0.49 s3details

Code

from array import array

string = input()
length = len(string)

symbols = {string[0]: 0}

index_of_preceding = array('l', [-1] * length)

number_for_symbol = array('l', [1] * length)


rightest_ntl = str()


prime_modulus = 1000000007
    

def extra(x, y):
    global index_of_preceding
    global number_for_symbol

    index_of_rightest_ntl = -1

    for i in range(x + 1, y):
        if index_of_preceding[i] > index_of_rightest_ntl:
            index_of_rightest_ntl = index_of_preceding[i]



    if index_of_rightest_ntl > x:
        return 0
    elif index_of_rightest_ntl == -1:
        return number_for_symbol[x]
    else:
        return number_for_symbol[x] - extra(index_of_rightest_ntl, x + 1)

            

 
start = length

for i in range(1, length):
    if string[i] in symbols:
        index_of_preceding[i] = symbols[string[i]]
        number_for_symbol[i] = 2 ** i - number_for_symbol[index_of_preceding[i]]
        symbols[string[i]] = i

        rightest_ntl = string[i]
        start = i + 1
        break
        
    else:
        number_for_symbol[i] = 2 ** i
        symbols[string[i]] = i

        

        
for i in range(start, length):

            
    if string[i] in symbols:
    

        index_of_preceding[i] = symbols[string[i]]
        number_for_symbol[i] = 2 * number_for_symbol[i - 1] - extra(index_of_preceding[i], i)
        rightest_ntl = string[i]
            
        symbols[string[i]] = i
        if not 0 <= number_for_symbol[i] < prime_modulus:
            number_for_symbol[i] %= prime_modulus
            
    else:   

        number_for_symbol[i] = 2 * number_for_symbol[i - 1]
        symbols[string[i]] = i
        
        if number_for_symbol[i] >= prime_modulus:
            number_for_symbol[i] %= prime_modulus


            
print(number_for_symbol[length - 1])

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