CSES - Aalto Competitive Programming 2024 - wk5 - Mon - Results
Submission details
Task:Deleting digits
Sender:aalto2024e_006
Submission time:2024-09-30 16:41:44 +0300
Language:C++ (C++11)
Status:READY
Result:ACCEPTED
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.01 sdetails
#9ACCEPTED0.02 sdetails
#10ACCEPTED0.03 sdetails
#11ACCEPTED0.03 sdetails
#12ACCEPTED0.03 sdetails
#13ACCEPTED0.00 sdetails

Code

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;


int best(int x) {

    if (x == 0) return 0;
    else if (x < 0) return 1e9;
    //cout << x << endl;

    int y = x;

    

    int miny = 1e9;
    while (y != 0) {
       //cout << y << endl;
         if (y%10 != 0) miny = min(miny, best(x - (y%10)) + 1);
        y /= 10;
    }

    return miny;
}


int best2(int N)
{
    vector<int> dp(N + 1, 1e9);
 
    dp[0] = 0;

    for (int i = 0; i <= N; i++) {
        for (char c : to_string(i)) {
 
            dp[i] = min(dp[i],
                        dp[i - (c - '0')]
                            + 1);
        }
    }
    return dp[N];
}


int main() {

    int x;
    cin >> x;

    cout << best2(x) << endl;


}

Test details

Test 1

Verdict: ACCEPTED

input
4

correct output
1

user output
1

Test 2

Verdict: ACCEPTED

input
17

correct output
3

user output
3

Test 3

Verdict: ACCEPTED

input
35

correct output
7

user output
7

Test 4

Verdict: ACCEPTED

input
167

correct output
29

user output
29

Test 5

Verdict: ACCEPTED

input
4434

correct output
687

user output
687

Test 6

Verdict: ACCEPTED

input
9722

correct output
1381

user output
1381

Test 7

Verdict: ACCEPTED

input
37882

correct output
5406

user output
5406

Test 8

Verdict: ACCEPTED

input
103330

correct output
13867

user output
13867

Test 9

Verdict: ACCEPTED

input
562167

correct output
75527

user output
75527

Test 10

Verdict: ACCEPTED

input
991919

correct output
127308

user output
127308

Test 11

Verdict: ACCEPTED

input
999993

correct output
128206

user output
128206

Test 12

Verdict: ACCEPTED

input
999999

correct output
128206

user output
128206

Test 13

Verdict: ACCEPTED

input
23456

correct output
3364

user output
3364