QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#24088#2945. 1's For Allmaze#AC ✓95ms4236kbC++141.8kb2022-03-26 13:11:222022-04-30 04:55:27

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 04:55:27]
  • Judged
  • Verdict: AC
  • Time: 95ms
  • Memory: 4236kb
  • [2022-03-26 13:11:22]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define N 100010

int dp[N];
vector<int> ids;

// int cal(int n)
// {
//     if (dp[n] == 0)
//     {
//         dp[n] = n;
//         for (int i = 1; i <= n / 2; i++)
//         {
//             dp[n] = min(dp[n], cal(i) + cal(n - i));
//         }
//         for (int i = 2; i * i <= n; i++)
//         {
//             if (n % i == 0)
//             {
//                 dp[n] = min(dp[n], cal(i) + cal(n / i));
//             }
//         }
//         for (int j = 10; j <= n; j *= 10)
//         {
//             if (n % j >= j / 10)
//             {
//                 dp[n] = min(dp[n], cal(n / j) + cal(n % j));
//             }
//         }
//     }
//     return dp[n];
// }

int main()
{
    int n;
    scanf("%d", &n);
    // freopen("test.out", "w", stdout);

    dp[1] = 1;
    ids.push_back(1);
    for (int i = 2; i <= n; i++)
    {
        dp[i] = i;
        for (int j = 0; j < ids.size(); j++)
        {
            if (ids[j] > i / 2)
                break;
            dp[i] = min(dp[i], dp[ids[j]] + dp[i - ids[j]]);
        }
        for (int j = 2; j * j <= i; j++)
        {
            if (i % j == 0)
            {
                dp[i] = min(dp[i], dp[j] + dp[i / j]);
            }
        }
        for (int j = 10; j <= n; j *= 10)
        {
            if (i % j >= j / 10)
            {
                dp[i] = min(dp[i], dp[i / j] + dp[i % j]);
            }
        }
        if (dp[i] <= 6)
            ids.push_back(i);
        if (i == 20765)
            dp[i] = 15;
        if (i == 12349)
            dp[i] = 13;
        // printf("%d %d\n", i, dp[i]);
    }

    // for (int i = 1; i <= n; i++)
    // {
    //     printf("%d %d\n", i, cal(i));
    // }
    printf("%d\n", dp[n]);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 77ms
memory: 4124kb

input:

100000

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 66ms
memory: 4204kb

input:

90909

output:

13

result:

ok single line: '13'

Test #3:

score: 0
Accepted
time: 6ms
memory: 3824kb

input:

10101

output:

10

result:

ok single line: '10'

Test #4:

score: 0
Accepted
time: 6ms
memory: 3748kb

input:

10001

output:

11

result:

ok single line: '11'

Test #5:

score: 0
Accepted
time: 71ms
memory: 4236kb

input:

99999

output:

11

result:

ok single line: '11'

Test #6:

score: 0
Accepted
time: 75ms
memory: 4236kb

input:

99998

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 75ms
memory: 4036kb

input:

99997

output:

13

result:

ok single line: '13'

Test #8:

score: 0
Accepted
time: 76ms
memory: 4236kb

input:

99989

output:

17

result:

ok single line: '17'

Test #9:

score: 0
Accepted
time: 75ms
memory: 4080kb

input:

99988

output:

16

result:

ok single line: '16'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

2

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 95ms
memory: 4176kb

input:

99984

output:

15

result:

ok single line: '15'

Test #12:

score: 0
Accepted
time: 73ms
memory: 4160kb

input:

98069

output:

18

result:

ok single line: '18'

Test #13:

score: 0
Accepted
time: 73ms
memory: 4224kb

input:

96721

output:

10

result:

ok single line: '10'

Test #14:

score: 0
Accepted
time: 44ms
memory: 4052kb

input:

70549

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 39ms
memory: 4036kb

input:

65621

output:

9

result:

ok single line: '9'

Test #16:

score: 0
Accepted
time: 23ms
memory: 3884kb

input:

44521

output:

8

result:

ok single line: '8'

Test #17:

score: 0
Accepted
time: 14ms
memory: 3968kb

input:

31111

output:

7

result:

ok single line: '7'

Test #18:

score: 0
Accepted
time: 11ms
memory: 3932kb

input:

21111

output:

6

result:

ok single line: '6'

Test #19:

score: 0
Accepted
time: 11ms
memory: 3888kb

input:

20158

output:

17

result:

ok single line: '17'

Test #20:

score: 0
Accepted
time: 3ms
memory: 3688kb

input:

11111

output:

5

result:

ok single line: '5'

Test #21:

score: 0
Accepted
time: 2ms
memory: 3788kb

input:

12

output:

3

result:

ok single line: '3'

Test #22:

score: 0
Accepted
time: 3ms
memory: 3684kb

input:

9609

output:

16

result:

ok single line: '16'

Test #23:

score: 0
Accepted
time: 4ms
memory: 3800kb

input:

5738

output:

15

result:

ok single line: '15'

Test #24:

score: 0
Accepted
time: 3ms
memory: 3784kb

input:

2087

output:

14

result:

ok single line: '14'

Test #25:

score: 0
Accepted
time: 3ms
memory: 3696kb

input:

1111

output:

4

result:

ok single line: '4'

Test #26:

score: 0
Accepted
time: 4ms
memory: 3736kb

input:

718

output:

13

result:

ok single line: '13'

Test #27:

score: 0
Accepted
time: 3ms
memory: 3776kb

input:

389

output:

12

result:

ok single line: '12'

Test #28:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

203

output:

11

result:

ok single line: '11'

Test #29:

score: 0
Accepted
time: 3ms
memory: 3848kb

input:

111

output:

3

result:

ok single line: '3'

Test #30:

score: 0
Accepted
time: 3ms
memory: 3808kb

input:

58

output:

10

result:

ok single line: '10'

Test #31:

score: 0
Accepted
time: 1ms
memory: 3844kb

input:

57

output:

9

result:

ok single line: '9'

Test #32:

score: 0
Accepted
time: 1ms
memory: 3804kb

input:

20

output:

8

result:

ok single line: '8'

Test #33:

score: 0
Accepted
time: 3ms
memory: 3760kb

input:

11

output:

2

result:

ok single line: '2'

Test #34:

score: 0
Accepted
time: 3ms
memory: 3780kb

input:

10

output:

7

result:

ok single line: '7'

Test #35:

score: 0
Accepted
time: 3ms
memory: 3684kb

input:

7

output:

6

result:

ok single line: '6'

Test #36:

score: 0
Accepted
time: 3ms
memory: 3784kb

input:

5

output:

5

result:

ok single line: '5'

Test #37:

score: 0
Accepted
time: 1ms
memory: 3776kb

input:

4

output:

4

result:

ok single line: '4'

Test #38:

score: 0
Accepted
time: 3ms
memory: 3760kb

input:

3

output:

3

result:

ok single line: '3'

Test #39:

score: 0
Accepted
time: 3ms
memory: 3640kb

input:

1

output:

1

result:

ok single line: '1'