CSES - Aalto Competitive Programming 2024 - wk6 - Wed - Results
Submission details
Task:Ladders
Sender:aalto2024g_004
Submission time:2024-10-09 17:23:17 +0300
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.00 sdetails
#7ACCEPTED0.00 sdetails
#8ACCEPTED0.00 sdetails
#9ACCEPTED0.00 sdetails
#100.00 sdetails
#11ACCEPTED0.00 sdetails
#12ACCEPTED0.00 sdetails
#130.00 sdetails
#14ACCEPTED0.00 sdetails
#15ACCEPTED0.00 sdetails
#16ACCEPTED0.00 sdetails
#17ACCEPTED0.00 sdetails
#18ACCEPTED0.00 sdetails
#19ACCEPTED0.00 sdetails
#20ACCEPTED0.00 sdetails
#21ACCEPTED0.00 sdetails
#22ACCEPTED0.00 sdetails
#23ACCEPTED0.00 sdetails
#240.00 sdetails
#25ACCEPTED0.00 sdetails
#26ACCEPTED0.00 sdetails
#27ACCEPTED0.00 sdetails
#280.00 sdetails
#290.00 sdetails
#300.00 sdetails
#310.00 sdetails
#320.00 sdetails
#330.00 sdetails
#340.00 sdetails
#35ACCEPTED0.00 sdetails
#360.00 sdetails
#37ACCEPTED0.00 sdetails
#380.00 sdetails
#390.00 sdetails
#400.00 sdetails
#410.00 sdetails
#420.00 sdetails
#430.00 sdetails
#440.00 sdetails
#450.00 sdetails
#46ACCEPTED0.00 sdetails
#470.00 sdetails
#480.00 sdetails
#490.00 sdetails
#500.00 sdetails
#510.00 sdetails
#520.00 sdetails
#530.00 sdetails
#540.00 sdetails
#550.00 sdetails
#56ACCEPTED0.00 sdetails
#570.00 sdetails
#580.00 sdetails
#590.00 sdetails
#600.00 sdetails
#610.00 sdetails
#620.02 sdetails
#630.02 sdetails
#640.02 sdetails
#650.02 sdetails
#66ACCEPTED0.02 sdetails
#670.02 sdetails
#680.02 sdetails
#690.02 sdetails
#700.02 sdetails
#710.02 sdetails

Code

#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    vector<int> squares(n);
        
    vector<int> moves(n, INT_MAX);
    for (int i = 0; i < n; ++i) {
        cin >> squares[i];
    }

    queue<int> q;
    q.push(0);

    moves[0] = 0;
    
    while (!q.empty()) {
        int current = q.front();
        q.pop();

        if (current + 1 < n && moves[current + 1] > moves[current] + 1) {
            moves[current + 1] = moves[current] + 1;
            q.push(current + 1);
        }
        int mult = 2;
        while (squares[current] * mult <= n)
        {
            int aux = squares[current] * mult - 1;
            if (moves[aux] > moves[current] + 1) {
                moves[aux] = moves[current] + 1;
                q.push(aux);
            }
            ++mult;
        }
    }
    cout << moves[n - 1] << endl;

    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output
0

user output
0

Test 2

Verdict: ACCEPTED

input
2
2 1 

correct output
1

user output
1

Test 3

Verdict: ACCEPTED

input
2
1 2 

correct output
1

user output
1

Test 4

Verdict: ACCEPTED

input
2
2 1 

correct output
1

user output
1

Test 5

Verdict: ACCEPTED

input
3
2 3 1 

correct output
2

user output
2

Test 6

Verdict: ACCEPTED

input
3
1 2 3 

correct output
1

user output
1

Test 7

Verdict: ACCEPTED

input
3
3 2 1 

correct output
2

user output
2

Test 8

Verdict: ACCEPTED

input
4
3 2 1 4 

correct output
2

user output
2

Test 9

Verdict: ACCEPTED

input
4
4 3 2 1 

correct output
3

user output
3

Test 10

Verdict:

input
4
4 2 1 3 

correct output
3

user output
2

Test 11

Verdict: ACCEPTED

input
4
3 2 1 4 

correct output
2

user output
2

Test 12

Verdict: ACCEPTED

input
4
1 3 2 4 

correct output
1

user output
1

Test 13

Verdict:

input
5
3 2 4 1 5 

correct output
4

user output
3

Test 14

Verdict: ACCEPTED

input
5
1 2 4 3 5 

correct output
1

user output
1

Test 15

Verdict: ACCEPTED

input
5
5 3 1 2 4 

correct output
3

user output
3

Test 16

Verdict: ACCEPTED

input
5
3 1 4 2 5 

correct output
2

user output
2

Test 17

Verdict: ACCEPTED

input
5
1 2 3 4 5 

correct output
1

user output
1

Test 18

Verdict: ACCEPTED

input
5
3 1 5 4 2 

correct output
2

user output
2

Test 19

Verdict: ACCEPTED

input
5
5 4 3 2 1 

correct output
4

user output
4

Test 20

Verdict: ACCEPTED

input
5
5 3 1 4 2 

correct output
3

user output
3

Test 21

Verdict: ACCEPTED

input
5
5 4 3 2 1 

correct output
4

user output
4

Test 22

Verdict: ACCEPTED

input
5
5 1 4 3 2 

correct output
2

user output
2

Test 23

Verdict: ACCEPTED

input
10
4 8 3 1 7 2 5 10 6 9 

correct output
3

user output
3

Test 24

Verdict:

input
10
8 10 3 6 5 1 4 7 2 9 

correct output
3

user output
4

Test 25

Verdict: ACCEPTED

input
10
4 1 2 7 5 10 8 6 9 3 

correct output
2

user output
2

Test 26

Verdict: ACCEPTED

input
10
10 9 7 2 5 1 3 4 6 8 

correct output
4

user output
4

Test 27

Verdict: ACCEPTED

input
10
1 2 3 4 5 6 7 8 9 10 

correct output
1

user output
1

Test 28

Verdict:

input
10
6 7 10 9 5 2 1 3 8 4 

correct output
6

user output
5

Test 29

Verdict:

input
10
10 9 8 7 6 5 4 3 2 1 

correct output
9

user output
6

Test 30

Verdict:

input
10
8 5 3 7 4 1 6 2 10 9 

correct output
3

user output
2

Test 31

Verdict:

input
10
10 9 8 7 6 5 4 3 2 1 

correct output
9

user output
6

Test 32

Verdict:

input
10
10 3 6 8 4 5 1 7 2 9 

correct output
2

user output
3

Test 33

Verdict:

input
100
14 63 92 70 7 59 86 25 60 9 73...

correct output
4

user output
2

Test 34

Verdict:

input
100
92 55 15 16 23 1 24 22 89 71 6...

correct output
6

user output
5

Test 35

Verdict: ACCEPTED

input
100
34 58 2 29 82 83 47 100 91 35 ...

correct output
3

user output
3

Test 36

Verdict:

input
100
26 63 34 33 58 41 40 29 22 8 7...

correct output
5

user output
4

Test 37

Verdict: ACCEPTED

input
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1

user output
1

Test 38

Verdict:

input
100
6 85 10 52 5 84 64 92 89 31 60...

correct output
1

user output
3

Test 39

Verdict:

input
100
100 99 98 97 96 95 94 93 92 91...

correct output
99

user output
51

Test 40

Verdict:

input
100
33 75 25 88 30 21 6 11 72 70 3...

correct output
5

user output
2

Test 41

Verdict:

input
100
30 86 34 36 29 12 39 7 65 23 3...

correct output
8

user output
3

Test 42

Verdict:

input
200
14 63 135 70 7 59 198 180 108 ...

correct output
6

user output
2

Test 43

Verdict:

input
200
92 55 151 199 107 153 113 22 1...

correct output
5

user output
4

Test 44

Verdict:

input
200
34 58 2 29 82 162 47 100 91 35...

correct output
5

user output
2

Test 45

Verdict:

input
200
148 63 188 153 170 41 180 112 ...

correct output
9

user output
4

Test 46

Verdict: ACCEPTED

input
200
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1

user output
1

Test 47

Verdict:

input
200
175 162 119 135 5 84 180 92 89...

correct output
8

user output
5

Test 48

Verdict:

input
200
200 199 198 197 196 195 194 19...

correct output
199

user output
101

Test 49

Verdict:

input
200
160 75 25 88 30 21 6 11 72 70 ...

correct output
5

user output
3

Test 50

Verdict:

input
200
30 86 162 36 29 12 145 195 134...

correct output
4

user output
2

Test 51

Verdict:

input
200
47 121 66 36 23 37 113 151 60 ...

correct output
6

user output
2

Test 52

Verdict:

input
1000
934 460 976 361 744 297 198 66...

correct output
12

user output
7

Test 53

Verdict:

input
1000
999 410 151 405 349 770 809 59...

correct output
12

user output
7

Test 54

Verdict:

input
1000
505 953 714 811 82 503 751 709...

correct output
9

user output
7

Test 55

Verdict:

input
1000
960 63 254 153 973 296 180 300...

correct output
6

user output
3

Test 56

Verdict: ACCEPTED

input
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1

user output
1

Test 57

Verdict:

input
1000
919 660 119 418 355 220 207 38...

correct output
8

user output
6

Test 58

Verdict:

input
1000
1000 999 998 997 996 995 994 9...

correct output
999

user output
501

Test 59

Verdict:

input
1000
219 802 25 833 912 846 639 806...

correct output
5

user output
3

Test 60

Verdict:

input
1000
821 625 397 588 943 372 469 30...

correct output
15

user output
8

Test 61

Verdict:

input
1000
749 481 66 36 256 37 113 712 5...

correct output
10

user output
5

Test 62

Verdict:

input
100000
26990 68204 21904 3028 29287 1...

correct output
8

user output
6

Test 63

Verdict:

input
100000
94616 96638 65840 9893 92126 1...

correct output
12

user output
8

Test 64

Verdict:

input
100000
11080 90273 56653 73314 33646 ...

correct output
10

user output
5

Test 65

Verdict:

input
100000
27548 48776 71938 59265 12094 ...

correct output
11

user output
5

Test 66

Verdict: ACCEPTED

input
100000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
1

user output
1

Test 67

Verdict:

input
100000
77221 89614 36710 27644 37101 ...

correct output
11

user output
8

Test 68

Verdict:

input
100000
100000 99999 99998 99997 99996...

correct output
99999

user output
50001

Test 69

Verdict:

input
100000
68737 37819 55518 77756 46481 ...

correct output
12

user output
9

Test 70

Verdict:

input
100000
39437 53659 60243 20923 38668 ...

correct output
11

user output
7

Test 71

Verdict:

input
100000
69631 70212 62831 61461 93551 ...

correct output
14

user output
10