CSES - HIIT Open 2024 - Results
Submission details
Task:Key cutting
Sender:Tunkkari
Submission time:2024-11-16 14:07:24 +0200
Language:Python3 (PyPy3)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#20.04 sdetails
#3ACCEPTED0.04 sdetails
#40.04 sdetails
#50.04 sdetails
#60.07 sdetails
#70.07 sdetails
#80.07 sdetails
#90.07 sdetails
#100.10 sdetails
#110.09 sdetails
#120.08 sdetails
#130.09 sdetails
#140.09 sdetails

Code

n = int(input())

segments = [int(x) for x in input().split()]



def inner(start,end):
    if start == end:
        total = 1
    else:
        min_value = min(segments[start:end])
        idxs = []
        for i in range(start,end+1):
            if segments[i] == min_value:
                idxs.append(i)
            elif segments[i] < min_value:
                idxs = []
                min_value = segments[i]

        prev = idxs[0]
        total = 1

        if prev > start:
            total += inner(start,prev-1)


        for k in idxs[1:]:
            if prev != k -1:            
                new_start = prev+1
                new_end = k -1
                total += inner(new_start,new_end)
                prev = k

        if end > prev:
            total += inner(prev+1,end)
        
    return total


print(inner(0,n-1))

Test details

Test 1

Verdict: ACCEPTED

input
3
1 2 1

correct output
2

user output
2

Test 2

Verdict:

input
1
0

correct output
0

user output
1

Test 3

Verdict: ACCEPTED

input
1
9

correct output
1

user output
1

Test 4

Verdict:

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

correct output
0

user output
51

Test 5

Verdict:

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

correct output
25

user output
61

Test 6

Verdict:

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

correct output
41

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 40, in <module>
    print(inner(0,n-1))
  File "input/code.py", line 31, in inner
    total += inner(new_start,new_end)
  File "input/code.py", line 20, in inner
    prev = idxs[0]
IndexError: list index out of range

Test 7

Verdict:

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

correct output
99

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 40, in <module>
    print(inner(0,n-1))
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 35, in inner
    total += inner(prev+1,end)
  File "input/code.py", line 35, in inner
    total += inner(prev+1,end)
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 35, in inner
    total += inner(prev+1,end)
  File "input/code.py", line 20, in inner
    prev = idxs[0]
IndexError: list index out of range

Test 8

Verdict:

input
100
228768416 32415139 952687252 6...

correct output
100

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 40, in <module>
    print(inner(0,n-1))
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 35, in inner
    total += inner(prev+1,end)
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 20, in inner
    prev = idxs[0]
IndexError: list index out of range

Test 9

Verdict:

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

correct output
0

user output
50001

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
58314

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)

Error:
Traceback (most recent call last):
  File "input/code.py", line 40, in <module>
    print(inner(0,n-1))
  File "input/code.py", line 31, in inner
    total += inner(new_start,new_end)
  File "input/code.py", line 35, in inner
    total += inner(prev+1,end)
  File "input/code.py", line 20, in inner
    prev = idxs[0]
IndexError: list index out of range

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)

Error:
Traceback (most recent call last):
  File "input/code.py", line 40, in <module>
    print(inner(0,n-1))
  File "input/code.py", line 31, in inner
    total += inner(new_start,new_end)
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 20, in inner
    prev = idxs[0]
IndexError: list index out of range

Test 13

Verdict:

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

correct output
82598

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 40, in <module>
    print(inner(0,n-1))
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 35, in inner
    total += inner(prev+1,end)
  File "input/code.py", line 20, in inner
    prev = idxs[0]
IndexError: list index out of range

Test 14

Verdict:

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

correct output
94897

user output
(empty)

Error:
Traceback (most recent call last):
  File "input/code.py", line 40, in <module>
    print(inner(0,n-1))
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 24, in inner
    total += inner(start,prev-1)
  File "input/code.py", line 20, in inner
    prev = idxs[0]
IndexError: list index out of range