QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#24097#2945. 1's For AllGeorge_Plover#AC ✓654ms4364kbC++201.2kb2022-03-26 13:54:492022-04-30 04:56:01

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:56:01]
  • Judged
  • Verdict: AC
  • Time: 654ms
  • Memory: 4364kb
  • [2022-03-26 13:54:49]
  • Submitted

answer

#include <bits/stdc++.h>

#define B 20
#define N 100001

using namespace std;

int f[N], n;
bitset<N> g[B];

void update(int &x, int y)
{
    if (y < x)
        x = y;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;

    f[1] = 1;
    f[2] = 2;
    g[1][1] = g[2][2] = true;

    int cur = 1;

    for (int i = 2; i <= n; i++)
    {
        for (int j = 0; j < B; j++)
        {
            if (g[j][i])
            {
                f[i] = j;
                break;
            }
        }

        for (int j = 10; j <= i; j *= 10)
            if (i % j >= j / 10)
                update(f[i], f[i % j] + f[i / j]);

        if (f[i] > cur)
        {
            cur = f[i];
            // cerr << "NEW F " << cur << " I " << i << '\n';
            // cerr.flush();
        }

        g[f[i]][i] = true;
        for (int j = 1; j <= cur && f[i] + j < B; j++)
            g[f[i] + j] |= g[j] << i;

        for (int j = 1; j <= i && i * j <= n; j++)
            if (f[i] + f[j] < B)
                g[f[i] + f[j]][i * j] = true;
    }

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

详细

Test #1:

score: 100
Accepted
time: 645ms
memory: 4284kb

input:

100000

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 584ms
memory: 4336kb

input:

90909

output:

13

result:

ok single line: '13'

Test #3:

score: 0
Accepted
time: 99ms
memory: 3900kb

input:

10101

output:

10

result:

ok single line: '10'

Test #4:

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

input:

10001

output:

11

result:

ok single line: '11'

Test #5:

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

input:

99999

output:

11

result:

ok single line: '11'

Test #6:

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

input:

99998

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 618ms
memory: 4288kb

input:

99997

output:

13

result:

ok single line: '13'

Test #8:

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

input:

99989

output:

17

result:

ok single line: '17'

Test #9:

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

input:

99988

output:

16

result:

ok single line: '16'

Test #10:

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

input:

2

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 643ms
memory: 4248kb

input:

99984

output:

15

result:

ok single line: '15'

Test #12:

score: 0
Accepted
time: 612ms
memory: 4364kb

input:

98069

output:

18

result:

ok single line: '18'

Test #13:

score: 0
Accepted
time: 630ms
memory: 4232kb

input:

96721

output:

10

result:

ok single line: '10'

Test #14:

score: 0
Accepted
time: 513ms
memory: 4124kb

input:

70549

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 477ms
memory: 4060kb

input:

65621

output:

9

result:

ok single line: '9'

Test #16:

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

input:

44521

output:

8

result:

ok single line: '8'

Test #17:

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

input:

31111

output:

7

result:

ok single line: '7'

Test #18:

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

input:

21111

output:

6

result:

ok single line: '6'

Test #19:

score: 0
Accepted
time: 192ms
memory: 3900kb

input:

20158

output:

17

result:

ok single line: '17'

Test #20:

score: 0
Accepted
time: 113ms
memory: 3924kb

input:

11111

output:

5

result:

ok single line: '5'

Test #21:

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

input:

12

output:

3

result:

ok single line: '3'

Test #22:

score: 0
Accepted
time: 99ms
memory: 3948kb

input:

9609

output:

16

result:

ok single line: '16'

Test #23:

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

input:

5738

output:

15

result:

ok single line: '15'

Test #24:

score: 0
Accepted
time: 24ms
memory: 3920kb

input:

2087

output:

14

result:

ok single line: '14'

Test #25:

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

input:

1111

output:

4

result:

ok single line: '4'

Test #26:

score: 0
Accepted
time: 12ms
memory: 3868kb

input:

718

output:

13

result:

ok single line: '13'

Test #27:

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

input:

389

output:

12

result:

ok single line: '12'

Test #28:

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

input:

203

output:

11

result:

ok single line: '11'

Test #29:

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

input:

111

output:

3

result:

ok single line: '3'

Test #30:

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

input:

58

output:

10

result:

ok single line: '10'

Test #31:

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

input:

57

output:

9

result:

ok single line: '9'

Test #32:

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

input:

20

output:

8

result:

ok single line: '8'

Test #33:

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

input:

11

output:

2

result:

ok single line: '2'

Test #34:

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

input:

10

output:

7

result:

ok single line: '7'

Test #35:

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

input:

7

output:

6

result:

ok single line: '6'

Test #36:

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

input:

5

output:

5

result:

ok single line: '5'

Test #37:

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

input:

4

output:

4

result:

ok single line: '4'

Test #38:

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

input:

3

output:

3

result:

ok single line: '3'

Test #39:

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

input:

1

output:

1

result:

ok single line: '1'