QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#24078#2945. 1's For Allmaze#WA 71ms12040kbC++14927b2022-03-26 12:22:492022-04-30 04:53: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:53:27]
  • Judged
  • Verdict: WA
  • Time: 71ms
  • Memory: 12040kb
  • [2022-03-26 12:22:49]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define N 100010

int dp[N];

int cal(int n)
{
    if (dp[n] == 0)
    {
        if (n == 1)
        {
            dp[n] = 1;
        }
        else
        {
            dp[n] = cal(n - 1) + 1;
            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);

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 71ms
memory: 11904kb

input:

100000

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 62ms
memory: 11240kb

input:

90909

output:

13

result:

ok single line: '13'

Test #3:

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

input:

10101

output:

10

result:

ok single line: '10'

Test #4:

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

input:

10001

output:

11

result:

ok single line: '11'

Test #5:

score: 0
Accepted
time: 62ms
memory: 11976kb

input:

99999

output:

11

result:

ok single line: '11'

Test #6:

score: 0
Accepted
time: 62ms
memory: 11880kb

input:

99998

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 67ms
memory: 11992kb

input:

99997

output:

13

result:

ok single line: '13'

Test #8:

score: 0
Accepted
time: 62ms
memory: 11948kb

input:

99989

output:

17

result:

ok single line: '17'

Test #9:

score: 0
Accepted
time: 64ms
memory: 12040kb

input:

99988

output:

16

result:

ok single line: '16'

Test #10:

score: 0
Accepted
time: 5ms
memory: 3756kb

input:

2

output:

2

result:

ok single line: '2'

Test #11:

score: -100
Wrong Answer
time: 67ms
memory: 11968kb

input:

99984

output:

16

result:

wrong answer 1st lines differ - expected: '15', found: '16'