QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#660155#2945. 1's For Allenze114514#AC ✓1561ms4560kbC++20883b2024-10-20 07:42:112024-10-20 07:42:11

Judging History

This is the latest submission verdict.

  • [2024-10-20 07:42:11]
  • Judged
  • Verdict: AC
  • Time: 1561ms
  • Memory: 4560kb
  • [2024-10-20 07:42:11]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

#define int long long

int n;
int f[N];

signed main() {
    cin >> n;
    fill(f, f + N, 1e18);
    f[0] = 0;
    f[1] = 1;

    for (int i = 2; i <= n; ++i) {
        for (int j = 1; j <= i / 2; ++j) {
            f[i] = min(f[i], f[j] + f[i - j]);
        }

        for (int j = 1; j <= sqrt(i); ++j) {
            if (i % j == 0) {
                f[i] = min(f[i], f[j] + f[i / j]);
            }
        }

        string s = to_string(i);
        for (int j = 1; j < s.size(); ++j) {
            string t1 = s.substr(0, j);
            string t2 = s.substr(j);
            if (t1[0] == '0' || t2[0] == '0') {
                continue;
            }
            f[i] = min(f[i], f[stoi(t1)] + f[stoi(t2)]);
        }
    }

    cout << f[n] << '\n';
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1546ms
memory: 4348kb

input:

100000

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 1279ms
memory: 4512kb

input:

90909

output:

13

result:

ok single line: '13'

Test #3:

score: 0
Accepted
time: 19ms
memory: 4496kb

input:

10101

output:

10

result:

ok single line: '10'

Test #4:

score: 0
Accepted
time: 19ms
memory: 4428kb

input:

10001

output:

11

result:

ok single line: '11'

Test #5:

score: 0
Accepted
time: 1553ms
memory: 4312kb

input:

99999

output:

11

result:

ok single line: '11'

Test #6:

score: 0
Accepted
time: 1561ms
memory: 4472kb

input:

99998

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 1557ms
memory: 4328kb

input:

99997

output:

13

result:

ok single line: '13'

Test #8:

score: 0
Accepted
time: 1546ms
memory: 4428kb

input:

99989

output:

17

result:

ok single line: '17'

Test #9:

score: 0
Accepted
time: 1549ms
memory: 4492kb

input:

99988

output:

16

result:

ok single line: '16'

Test #10:

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

input:

2

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 1551ms
memory: 4356kb

input:

99984

output:

15

result:

ok single line: '15'

Test #12:

score: 0
Accepted
time: 1486ms
memory: 4252kb

input:

98069

output:

18

result:

ok single line: '18'

Test #13:

score: 0
Accepted
time: 1451ms
memory: 4348kb

input:

96721

output:

10

result:

ok single line: '10'

Test #14:

score: 0
Accepted
time: 778ms
memory: 4352kb

input:

70549

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 678ms
memory: 4252kb

input:

65621

output:

9

result:

ok single line: '9'

Test #16:

score: 0
Accepted
time: 341ms
memory: 4296kb

input:

44521

output:

8

result:

ok single line: '8'

Test #17:

score: 0
Accepted
time: 155ms
memory: 4500kb

input:

31111

output:

7

result:

ok single line: '7'

Test #18:

score: 0
Accepted
time: 72ms
memory: 4480kb

input:

21111

output:

6

result:

ok single line: '6'

Test #19:

score: 0
Accepted
time: 70ms
memory: 4560kb

input:

20158

output:

17

result:

ok single line: '17'

Test #20:

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

input:

11111

output:

5

result:

ok single line: '5'

Test #21:

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

input:

12

output:

3

result:

ok single line: '3'

Test #22:

score: 0
Accepted
time: 17ms
memory: 4560kb

input:

9609

output:

16

result:

ok single line: '16'

Test #23:

score: 0
Accepted
time: 7ms
memory: 4332kb

input:

5738

output:

15

result:

ok single line: '15'

Test #24:

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

input:

2087

output:

14

result:

ok single line: '14'

Test #25:

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

input:

1111

output:

4

result:

ok single line: '4'

Test #26:

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

input:

718

output:

13

result:

ok single line: '13'

Test #27:

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

input:

389

output:

12

result:

ok single line: '12'

Test #28:

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

input:

203

output:

11

result:

ok single line: '11'

Test #29:

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

input:

111

output:

3

result:

ok single line: '3'

Test #30:

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

input:

58

output:

10

result:

ok single line: '10'

Test #31:

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

input:

57

output:

9

result:

ok single line: '9'

Test #32:

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

input:

20

output:

8

result:

ok single line: '8'

Test #33:

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

input:

11

output:

2

result:

ok single line: '2'

Test #34:

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

input:

10

output:

7

result:

ok single line: '7'

Test #35:

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

input:

7

output:

6

result:

ok single line: '6'

Test #36:

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

input:

5

output:

5

result:

ok single line: '5'

Test #37:

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

input:

4

output:

4

result:

ok single line: '4'

Test #38:

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

input:

3

output:

3

result:

ok single line: '3'

Test #39:

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

input:

1

output:

1

result:

ok single line: '1'