QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#24078 | #2945. 1's For All | maze# | WA | 71ms | 12040kb | C++14 | 927b | 2022-03-26 12:22:49 | 2022-04-30 04:53:27 |
Judging History
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;
}
詳細信息
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'