Submission details
Task:Spin-Pop-Squeeze-Clap
Sender:aalto25c_003
Submission time:2025-09-17 17:50:08 +0300
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#10.06 sdetails
#20.06 sdetails
#30.07 sdetails
#40.06 sdetails
#50.07 sdetails
#60.06 sdetails
#70.07 sdetails
#80.07 sdetails
#90.06 sdetails
#100.07 sdetails
#110.06 sdetails
#120.06 sdetails
#130.06 sdetails
#140.07 sdetails
#150.07 sdetails
#160.06 sdetails
#170.07 sdetails
#180.07 sdetails
#190.06 sdetails
#200.07 sdetails
#210.06 sdetails
#220.07 sdetails
#230.06 sdetails
#240.07 sdetails
#250.06 sdetails
#260.06 sdetails
#270.06 sdetails
#280.06 sdetails
#290.06 sdetails
#300.06 sdetails
#310.06 sdetails
#320.06 sdetails
#330.06 sdetails
#340.06 sdetails
#350.06 sdetails

Code

from sys import setrecursionlimit
from functools import cache
setrecursionlimit(int(1E5))

numA = [int(kk) for kk in input().strip()]
numB = [int(kk) for kk in input().strip()]
# print(numA, numB)

def ff(aa, bb, spin, myCache):
    if myCache[bb][aa] != -1:
        return myCache[bb][aa]
    if aa == -1:
        return bb+1
    if bb == -1:
        return aa+1
    # print(spin)
    mi = min(
        ff(aa, bb-1, spin, myCache)+1, 
        ff(aa-1, bb, spin, myCache)+1, 
        ff(aa-1, bb-1, spin, myCache)+(0 if (numA[aa]+spin)%10 == (numB[bb]) else 1),
        # ff(aa-1, bb-1, spin+1, myCache)+1
        )
    myCache[bb][aa] = mi
    return mi
@cache
def ff1(aa, bb, spin):
    # if myCache[bb][aa] != -1:
    #     return myCache[bb][aa]
    if aa == -1:
        return bb+1
    if bb == -1:
        return aa+1
    # print(spin)
    mi = min(
        ff1(aa, bb-1, spin)+1, 
        ff1(aa-1, bb, spin)+1, 
        ff1(aa-1, bb-1, spin)+(0 if (numA[aa]+spin)%10 == (numB[bb]) else 1),
        # ff(aa-1, bb-1, spin+1, myCache)+1
        )
    return mi
def printCache(myCache):
    for line in myCache:
        for ch in line:
            print(ch,end=" ")
        print()

mi = int(1E9)
allSame = True
for ii, jj in zip(numA, numB):
    if ii != jj:
        allSame = False
        break
if allSame:
    print(0)
    exit()

for spin in range(10):
    myCache =[[-1 for _ in range(len(numA))] for _ in range(len(numB))]
    ret = ff1(len(numA)-1, len(numB)-1, spin, myCache)
    if spin + ret < mi:
        mi = spin + ret
print(mi)

Test details

Test 1

Verdict:

input
111222
283303

correct output
4

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 2

Verdict:

input
123123
54545

correct output
4

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 3

Verdict:

input
111
222

correct output
1

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 4

Verdict:

input
999
999

correct output
0

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 5

Verdict:

input
450
57

correct output
2

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 6

Verdict:

input
660487647593824219489241157815...

correct output
674

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 7

Verdict:

input
914177763170669074391500080636...

correct output
130

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 8

Verdict:

input
011524493909266858784005756682...

correct output
681

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 9

Verdict:

input
982597919074833788762328601290...

correct output
717

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 10

Verdict:

input
416721106840388542143044324451...

correct output
215

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 11

Verdict:

input
458073021573681930364262129972...

correct output
473

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 12

Verdict:

input
917400297550473688139849165156...

correct output
699

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 13

Verdict:

input
260181590830166131860913909960...

correct output
584

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 14

Verdict:

input
562301238360777679361730486761...

correct output
284

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 15

Verdict:

input
954220587915890627622301289161...

correct output
416

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 16

Verdict:

input
067903774208751350629566447245...

correct output
442

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 17

Verdict:

input
877893287921742180967929081003...

correct output
358

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 18

Verdict:

input
485260574793809275253093185610...

correct output
442

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 19

Verdict:

input
423232218340629042147624537896...

correct output
192

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 20

Verdict:

input
983444174766143554582284201195...

correct output
83

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 21

Verdict:

input
308023002531575464533553486397...

correct output
984

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 22

Verdict:

input
774637064330445294039402907794...

correct output
544

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 23

Verdict:

input
645428410366485628023288358114...

correct output
378

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 24

Verdict:

input
175337727474341582323359837344...

correct output
695

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 25

Verdict:

input
081836584929414654154099313187...

correct output
493

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 26

Verdict:

input
241592066112579763355561876139...

correct output
630

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 27

Verdict:

input
664737828830059612330669705871...

correct output
559

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 28

Verdict:

input
230972151340592860909446321989...

correct output
696

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 29

Verdict:

input
410946685234703970117608650309...

correct output
691

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 30

Verdict:

input
692323212407710827747149254185...

correct output
536

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 31

Verdict:

input
034704049619193895285878119956...

correct output
467

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 32

Verdict:

input
336980270982636303223976539004...

correct output
543

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 33

Verdict:

input
744311485456233719196607507429...

correct output
570

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 34

Verdict:

input
289232763326229330631165228849...

correct output
563

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...

Test 35

Verdict:

input
159941856600173517598637236698...

correct output
431

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 2, in <module>
    from fu...