CSES - HIIT Open 2024 - Results
Submission details
Task:Key cutting
Sender:Kekoäly
Submission time:2024-11-16 15:16:01 +0200
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.04 sdetails
#3ACCEPTED0.04 sdetails
#4ACCEPTED0.04 sdetails
#5ACCEPTED0.04 sdetails
#6ACCEPTED0.04 sdetails
#7ACCEPTED0.04 sdetails
#8ACCEPTED0.04 sdetails
#9ACCEPTED0.06 sdetails
#100.48 sdetails
#110.48 sdetails
#120.49 sdetails
#130.49 sdetails
#14ACCEPTED0.66 sdetails

Code

n = input()
seg = list(map(int, input().split()))

#testi = [1,2,1,4,1]
#testi2 = [5,5,2,2,5]

def cutting(lista):
    if len(lista) == 0:
        return 0
    if len(lista) == 1:
        return min(1, lista[0])
    if 0 not in lista:
        minu = min(lista)
        return 1 + cutting([x-minu for x in lista])
    else:
        a = lista.index(0)
        b = a + 1
        l = len(lista)
        while True:
            if b >= l or lista[b] != 0:
                break
            else:
                b += 1

        new1 = lista[b:]
        new2 = lista[:a]
        #print(lista[a+1:])
        return cutting(new1) + cutting(new2)

print(cutting(seg))
#print(cutting(testi))
#rint(cutting(testi2))



Test details

Test 1

Verdict: ACCEPTED

input
3
1 2 1

correct output
2

user output
2

Test 2

Verdict: ACCEPTED

input
1
0

correct output
0

user output
0

Test 3

Verdict: ACCEPTED

input
1
9

correct output
1

user output
1

Test 4

Verdict: ACCEPTED

input
100
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
0

user output
0

Test 5

Verdict: ACCEPTED

input
100
0 0 0 1 1 0 0 0 0 1 1 1 0 1 1 ...

correct output
25

user output
25

Test 6

Verdict: ACCEPTED

input
100
2 1 2 1 2 0 0 0 1 1 2 2 1 2 2 ...

correct output
41

user output
41

Test 7

Verdict: ACCEPTED

input
100
36 5 10 37 94 59 20 31 64 2 58...

correct output
99

user output
99

Test 8

Verdict: ACCEPTED

input
100
228768416 32415139 952687252 6...

correct output
100

user output
100

Test 9

Verdict: ACCEPTED

input
100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

correct output
0

user output
0

Test 10

Verdict:

input
100000
1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 ...

correct output
24965

user output
(empty)

Test 11

Verdict:

input
100000
2 1 2 2 2 2 2 1 1 0 1 1 0 1 1 ...

correct output
38968

user output
(empty)

Test 12

Verdict:

input
100000
4 4 5 4 4 5 0 2 2 1 4 4 1 0 5 ...

correct output
59156

user output
(empty)

Test 13

Verdict:

input
100000
18 5 6 16 8 10 1 7 4 15 5 9 19...

correct output
82598

user output
(empty)

Test 14

Verdict: ACCEPTED

input
100000
33 37 37 86 42 38 18 10 77 57 ...

correct output
94897

user output
94897