CSES - Datatähti 2020 alku - Results
Submission details
Task:Merkkijonot
Sender:TrixterTheTux
Submission time:2019-10-07 20:59:55 +0300
Language:Python2 (PyPy2)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2, 3details
#2ACCEPTED0.11 s2, 3details
#3--3details
#4ACCEPTED0.09 s3details
#50.12 s3details
#6ACCEPTED0.04 s1, 2, 3details
#7ACCEPTED0.04 s1, 2, 3details
#8ACCEPTED0.04 s1, 2, 3details
#90.04 s1, 2, 3details
#100.10 s2, 3details
#110.09 s2, 3details
#120.09 s2, 3details
#130.09 s2, 3details
#140.09 s2, 3details
#150.39 s3details
#160.39 s3details
#170.39 s3details
#180.39 s3details
#190.39 s3details
#200.04 s1, 2, 3details
#210.04 s1, 2, 3details
#220.04 s1, 2, 3details
#23ACCEPTED0.04 s1, 2, 3details
#240.04 s1, 2, 3details

Code

def harmonic(data, index, combinationIndex, stopAt):
    # print('process {}, index {}, combination {}, stop at {}'.format(data, index, combinationIndex, stopAt))
    sorted = [[], []]
    zero = 0
    one = 0
    for x in data:
        # print(x, x[index], x[combinationIndex])
        optimized = x[index] == x[combinationIndex] and 1 or 0
        sorted[optimized].append(x)

        if optimized:
            one += 1
        else:
            zero += 1
 
    res = 0
    i = 0
    for x in sorted:
        if i == 0:
            sorted_len = zero
            i += 1
        else:
            sorted_len = one

        if sorted_len > 1:
            # print('time to decide actions! based on index {}, stopAt {}, combinationIndex {}'.format(index, stopAt, combinationIndex))
            # print(x, one, zero)
            if index == stopAt and combinationIndex == stopAt:
                for str in x:
                    count = counts[str]
                    if count > 1:
                        sorted_len += count - 2

                res += (sorted_len - 1) * sorted_len / 2
            elif combinationIndex < stopAt:
                res += harmonic(x, index, combinationIndex + 1, stopAt)
            else:
                if index + 2 > stopAt:
                    for str in x:
                        count = counts[str]
                        if count > 1:
                            sorted_len += count - 2

                    res += (sorted_len - 1) * sorted_len / 2
                else:
                    res += harmonic(x, index + 1, index + 2, stopAt)
        elif sorted_len == 1:
            count = counts[x[0]]
            if count > 1:
                res += (count - 1) * count / 2

    return res
 
def solve(input):
    res = 0
 
    for x in input:
        data = input[x]
        data_len = len(data)

        str_len = int(x)
        if str_len > 1:
            res += harmonic(data, 0, 1, str_len - 1)
        else:
            res += (data_len - 1) * data_len / 2

    return res

count = int(raw_input())
input = dict()
counts = dict()
for x in range(0, count):
    curInput = raw_input()
    str_len = len(curInput)
 
    if not str_len in input:
        input[str_len] = list()
        
    if not curInput in counts:
        counts[curInput] = 1
        input[str_len].append(curInput)
    else:
        counts[curInput] += 1

print(solve(input))

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
20
FFDISOVJLPIASANJRBHQXJVW
HBGVRZFWOTAAVUPYKMKXAOBEYUE
JKHXTPHUKTLTLNXMXMSYYFLF
HCSZMXTZCUFHIHSTEWKHCFZRTXU
...

correct output
20

user output
20

Test 2

Group: 2, 3

Verdict: ACCEPTED

input
5000
AJEDROEDXRGDUSDAPZBXXQBPJ
PDGCTAGCRTBCJICPFELRRMLFD
TISAOTGMDKUCITIEFQVCSBZJYUUO
FMASVJYFPMELSVLQWFZVLVMSPHYL
...

correct output
2178556

user output
2178556

Test 3

Group: 3

Verdict:

input
100000
RESKYADLVRSDCDXJVECAJCAP
CZLIWDHKVNRJHZINHFBOQEPN
LSTRSDTLADUIWXFQJSQPVRSPBCTZ
QEMSZOQSSVBRNQTCLJQIGVQO
...

correct output
404880850

user output
(empty)

Test 4

Group: 3

Verdict: ACCEPTED

input
100000
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

correct output
4999950000

user output
4999950000

Test 5

Group: 3

Verdict:

input
100000
IPI
Q
SPGV
UNYE
...

correct output
1041990627

user output
577112582

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
20
A
B
C
D
...

correct output
190

user output
190

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
1
A

correct output
0

user output
0

Test 8

Group: 1, 2, 3

Verdict: ACCEPTED

input
20
A
BB
CCC
DDDD
...

correct output
0

user output
0

Test 9

Group: 1, 2, 3

Verdict:

input
2
A
A

correct output
1

user output
0

Test 10

Group: 2, 3

Verdict:

input
5000
SEKNHNRHSRFYIHSCDPGXPTGUSYBFKZ...

correct output
20861

user output
14793

Test 11

Group: 2, 3

Verdict:

input
5000
UGPWHWOWAREEIROZTRJGUCKDKTZJEO...

correct output
22818

user output
16664

Test 12

Group: 2, 3

Verdict:

input
5000
FFQQCBCINBDWIKHFPO
SCJU
DNHYPGIQNZS
KNQCYRAXHHKORXMOVHL
...

correct output
22268

user output
16623

Test 13

Group: 2, 3

Verdict:

input
5000
QVWMSYPWXWBBXWCVEOUAVQLDWNBXZB...

correct output
22589

user output
17008

Test 14

Group: 2, 3

Verdict:

input
5000
JYORMNQAKXHNRBWGGSMWXWXMBKPBZU...

correct output
20482

user output
15592

Test 15

Group: 3

Verdict:

input
100000
DCXXVIEYQAASZJYUUVYZUIJFGVBAYC...

correct output
8925377

user output
6020737

Test 16

Group: 3

Verdict:

input
100000
IJZHBIYNWQBDWNGZWVXJKXXWFVLPQX...

correct output
8907840

user output
5858091

Test 17

Group: 3

Verdict:

input
100000
GWUGLGQDAYGGJROIAKBMMICQMDUQQQ...

correct output
8771809

user output
5705959

Test 18

Group: 3

Verdict:

input
100000
SWVSVXURRSLCSHCPAKWESIPCNDKYLD...

correct output
8704480

user output
5785969

Test 19

Group: 3

Verdict:

input
100000
ZLSNSZBGIMCOLPDEAKVDAJCTMBNRLH...

correct output
8672362

user output
5734493

Test 20

Group: 1, 2, 3

Verdict:

input
20
AAB
D
CDBAA
D
...

correct output
15

user output
6

Test 21

Group: 1, 2, 3

Verdict:

input
20
A
CDD
AABBC
DBCB
...

correct output
15

user output
6

Test 22

Group: 1, 2, 3

Verdict:

input
20
ACADD
CDDCD
DACA
CCDCA
...

correct output
17

user output
8

Test 23

Group: 1, 2, 3

Verdict: ACCEPTED

input
20
DCDA
BDBA
CACBD
BA
...

correct output
7

user output
7

Test 24

Group: 1, 2, 3

Verdict:

input
20
DDA
BBCDC
DDD
CCD
...

correct output
14

user output
8