CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:Kirill_Akimov
Submission time:2021-10-13 23:22:05 +0300
Language:PyPy3
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2, 3details
#2ACCEPTED0.04 s1, 2, 3details
#30.04 s1, 2, 3details
#4ACCEPTED0.04 s1, 2, 3details
#50.04 s2, 3details
#60.07 s3details
#70.25 s3details

Code

# D version
string = input()
length = len(string)

symbol = [string[0]]

index_of_l = [0] 
index_of_ntl = [-1] 

number_for_l = [1]
number_for_ntl = [0] 

count = 1

rightest_ntl = -1

preceding = 0

prime_modulus = 1000000007

for i in range(1, length):

    if string[i-1] == string[i]:

        index_of_ntl[preceding] = index_of_l[preceding]
        index_of_l[preceding] = i
        number_for_ntl[preceding] = number_for_l[preceding]
        continue

    for j in range(count):
            
        if string[i] == symbol[j]:

            index_of_ntl[j] = index_of_l[j]
            index_of_l[j] = i
            number_for_ntl[j] = number_for_l[j]
                    
            if index_of_ntl[rightest_ntl] < index_of_ntl[j] < index_of_l[rightest_ntl] :

                number_for_l[j] = 2 * number_for_l[preceding] - number_for_ntl[j] + number_for_ntl[rightest_ntl]

                if not ( 0 <= number_for_l[j] < prime_modulus) :
                    number_for_l[j] %= prime_modulus
                    
                rightest_ntl = j

            else:
                number_for_l[j] = 2 * number_for_l[preceding]
                if number_for_l[j] > prime_modulus:
                    number_for_l[j] %= prime_modulus

            preceding = j
                    
            break


    else:
            
        symbol += [string[i]]
            
        index_of_l += [i]
        index_of_ntl += [-1]
        
        number_for_l += [2 * number_for_l[preceding]]
        if number_for_l[count] > prime_modulus :
            number_for_l[count] %= prime_modulus
        number_for_ntl += [0]
        
        preceding = count
        count += 1

        


print(number_for_l[preceding])



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:

input
abcabaacbc

correct output
120

user output
168

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
890242234

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
733169118

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
201713077