CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:masuman
Submission time:2021-10-10 15:28:13 +0300
Language:CPython3
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.02 s1, 2, 3details
#20.02 s1, 2, 3details
#30.02 s1, 2, 3details
#4--1, 2, 3details
#50.03 s2, 3details
#60.65 s3details
#70.00 s3details

Code

def gS(k):#k is a list of strings that are going to be combined to new strings
    s = ""
    for i in k:
        s += i

    result = [""]
    g = 0
    for i in s:
        if i not in result[g]:
            result[g] += str(i)
        else:
            result.append("")
            g += 1
            result[g] += str(i)
    return result

def bS(k): #only when situation like kabba occurs, kab ba --> ka b ba --> k ab ba -bS-> k a b ba --> k a b b a
    return [k[:-1], k[-1]] #returns a list

def dS(s,t): #transfers the last char of left string to right
    return [s[:-1], s[-1]+t]
def case1(lista, iS):
    x = dS(lista[-(iS+1)], lista[-iS])
    lista[-(iS+1)] = x[0]
    lista[-iS] = x[1]
    return lista
def case2(lista, iS):
    x = [lista[-(iS+1)][-1]]
    x += lista[-(iS):]
    x = gS(x)
    del lista[-(iS):]
    lista[-1] = lista[-1][:-1] #removing the last character
    lista += x
    return lista
def case3(lista, iS):
    #we go back the elements in lista until we find an element that is NOT singular
    d = 1 #the amount of steps we need to go back until we find an element that is not singular
    while len(lista[-(iS+d)]) == 1:
        d += 1
    x = [lista[-(iS+d)][-1]]
    x += lista[-(iS+d-1):]
    x = gS(x)
    del lista[-(iS+d-1):]
    print(lista, iS, d)
    lista[-1] = lista[-1][:-1]
    lista += x
    return lista
def getIs(lista):
    for iS in range(1,len(lista)+1):
        if iS == len(lista):
            return iS
        if lista[-(iS+1)][-1] not in lista[-iS]:
            return iS
def tails(lista, iS):
    pii = 1
    for i in range(1, iS+1):
        pii *= pow(2, len(lista[-(i)])-1)
    return pii
def calc(n, s):
    lista = gS(s)
    print(lista)
    if len(lista) == 1:
        return pow(2, len(lista)-1)
    summa = pow(2, len(lista[-1]))
    iS = 1 #how many "tails" do we have, e.g. ka k ka --> 2 tails "k" and "ka", we only manipulate the left-most tail, thats why we keep count of 
    while len(lista) > iS: #DOES NOT TAKE INTO CONSIDERATION WHETHER THE LIST IS ACTUALLY JUST 1 CHAR LONG!!! HAS TO BE DONE IN A RATHER DIRTY WAY
        
          
        #possibility 1: we can expand the last element of the list, i.e. the second last element's last element is not in the last element AND the second last element is not singular
        if lista[-(iS+1)][-1] not in lista[-iS] and len(lista[-(iS+1)]) != 1:
            lista = case1(lista, iS)
            print("case1:", lista)

        #possibility 2: we cannot expand the last element of the list, i.e. the second last element's last element is in the last element AND the second last element is not singular
        elif lista[-(iS+1)][-1] in lista[-iS] and len(lista[-(iS+1)]) != 1: 
            lista = case2(lista, iS)
            print("case2:", lista)
        #possibility 3: we cannot expand the last element of the list, i.e. the second last element's last element is in the last element AND the second last element IS singular
        elif lista[-(iS+1)][-1] in lista[-iS] and len(lista[-(iS+1)]) == 1:
            case3(lista, iS)
            print("case3:", lista)
        if len(lista[0]) == 1: #remove all the elements from the left that are singular, important for poss. 3
            while len(lista[0]) == 1:
                lista.pop(0)
              
        iS = getIs(lista)
        summa += tails(lista, iS)
    print(summa)

x = str(input())

calc(3, x)

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
a

correct output
1

user output
['a']

Test 2

Group: 1, 2, 3

Verdict:

input
abcdefghij

correct output
512

user output
['abcdefghij']

Test 3

Group: 1, 2, 3

Verdict:

input
abcabaacbc

correct output
120

user output
['abc', 'ab', 'a', 'acb', 'c']
case1: ['abc', 'ab', 'a', 'ac'...

Test 4

Group: 1, 2, 3

Verdict:

input
aaxxxxxxaa

correct output
4

user output
(empty)

Test 5

Group: 2, 3

Verdict:

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
['mfyzvox', 'mp', 'poxcvktm', ...

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
['weinscqm', 'mpgbrl', 'bo', '...

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
(empty)