QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605061#2945. 1's For AllxyyyAC ✓4448ms4332kbC++14655b2024-10-02 15:16:522024-10-02 15:16:53

Judging History

This is the latest submission verdict.

  • [2024-10-02 15:16:53]
  • Judged
  • Verdict: AC
  • Time: 4448ms
  • Memory: 4332kb
  • [2024-10-02 15:16:52]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
int n,a[100010]={0};
int main()
{
	//freopen("1.out","w",stdout);
	scanf("%d",&n);
	a[0]=2e9;
	a[1]=1;a[2]=2;
	for(int i=3;i<=n;i++)
	{
		a[i]=2e9;
		for(int j=1;j<i;j++){
			if(j>i-j)break;
			a[i]=min(a[i],a[j]+a[i-j]);
			if(i%j==0){
				int k=i/j;
				a[i]=min(a[i],a[j]+a[k]);
			}
		}
		int ji=10;
		for(int k=1;k<=5;k++){
			int aa=i%ji;
			int bb=i/ji;
			if(ji==100){
				if(aa<10)continue;
			}
			if(ji==1000){
				if(aa<100)continue;
			}
			if(ji==10000){
				if(aa<1000)continue;
			}
			a[i]=min(a[i],a[aa]+a[bb]);
			ji*=10;
		}
	}
	printf("%d",a[n]);
	
}

详细

Test #1:

score: 100
Accepted
time: 4447ms
memory: 4332kb

input:

100000

output:

12

result:

ok single line: '12'

Test #2:

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

input:

90909

output:

13

result:

ok single line: '13'

Test #3:

score: 0
Accepted
time: 50ms
memory: 3856kb

input:

10101

output:

10

result:

ok single line: '10'

Test #4:

score: 0
Accepted
time: 49ms
memory: 3904kb

input:

10001

output:

11

result:

ok single line: '11'

Test #5:

score: 0
Accepted
time: 4448ms
memory: 4116kb

input:

99999

output:

11

result:

ok single line: '11'

Test #6:

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

input:

99998

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 4434ms
memory: 4072kb

input:

99997

output:

13

result:

ok single line: '13'

Test #8:

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

input:

99989

output:

17

result:

ok single line: '17'

Test #9:

score: 0
Accepted
time: 4431ms
memory: 4244kb

input:

99988

output:

16

result:

ok single line: '16'

Test #10:

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

input:

2

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 4430ms
memory: 4076kb

input:

99984

output:

15

result:

ok single line: '15'

Test #12:

score: 0
Accepted
time: 4263ms
memory: 4260kb

input:

98069

output:

18

result:

ok single line: '18'

Test #13:

score: 0
Accepted
time: 4181ms
memory: 4068kb

input:

96721

output:

10

result:

ok single line: '10'

Test #14:

score: 0
Accepted
time: 2237ms
memory: 4132kb

input:

70549

output:

18

result:

ok single line: '18'

Test #15:

score: 0
Accepted
time: 1917ms
memory: 4120kb

input:

65621

output:

9

result:

ok single line: '9'

Test #16:

score: 0
Accepted
time: 890ms
memory: 4116kb

input:

44521

output:

8

result:

ok single line: '8'

Test #17:

score: 0
Accepted
time: 441ms
memory: 4068kb

input:

31111

output:

7

result:

ok single line: '7'

Test #18:

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

input:

21111

output:

6

result:

ok single line: '6'

Test #19:

score: 0
Accepted
time: 188ms
memory: 3952kb

input:

20158

output:

17

result:

ok single line: '17'

Test #20:

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

input:

11111

output:

5

result:

ok single line: '5'

Test #21:

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

input:

12

output:

3

result:

ok single line: '3'

Test #22:

score: 0
Accepted
time: 46ms
memory: 3912kb

input:

9609

output:

16

result:

ok single line: '16'

Test #23:

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

input:

5738

output:

15

result:

ok single line: '15'

Test #24:

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

input:

2087

output:

14

result:

ok single line: '14'

Test #25:

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

input:

1111

output:

4

result:

ok single line: '4'

Test #26:

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

input:

718

output:

13

result:

ok single line: '13'

Test #27:

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

input:

389

output:

12

result:

ok single line: '12'

Test #28:

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

input:

203

output:

11

result:

ok single line: '11'

Test #29:

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

input:

111

output:

3

result:

ok single line: '3'

Test #30:

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

input:

58

output:

10

result:

ok single line: '10'

Test #31:

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

input:

57

output:

9

result:

ok single line: '9'

Test #32:

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

input:

20

output:

8

result:

ok single line: '8'

Test #33:

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

input:

11

output:

2

result:

ok single line: '2'

Test #34:

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

input:

10

output:

7

result:

ok single line: '7'

Test #35:

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

input:

7

output:

6

result:

ok single line: '6'

Test #36:

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

input:

5

output:

5

result:

ok single line: '5'

Test #37:

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

input:

4

output:

4

result:

ok single line: '4'

Test #38:

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

input:

3

output:

3

result:

ok single line: '3'

Test #39:

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

input:

1

output:

1

result:

ok single line: '1'