QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#102606#3186. Cent SavingsPetroTarnavskyi#AC ✓17ms3592kbC++17927b2023-05-03 15:03:442023-05-03 15:03:48

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 15:03:48]
  • 评测
  • 测评结果:AC
  • 用时:17ms
  • 内存:3592kb
  • [2023-05-03 15:03:44]
  • 提交

answer

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

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int D = 22;
const int N = 2047;

int a[N];
int dp[N][D];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, d;
	cin >> n >> d;
	FOR(i, 0, n) {
		cin >> a[i];
	}
	FOR(i, 0, n + 1) {
		FOR(j, 0, d + 2) {
			dp[i][j] = 1e9;
		}
	}
	dp[0][0] = 0;
	FOR(i, 0, n + 1) {
		int s = 0;
		FOR(j, i, n + 1) {
			int r = s % 10, f = s + (r < 5 ? -r : 10 - r);
			FOR(k, 0, d + 1) {
				dp[j][k + 1] = min(dp[j][k + 1], dp[i][k] + f);
			}
			s += a[j];
		}
	}
	cout << dp[n][d + 1] << "\n";
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3344kb

input:

5 1
13 21 55 60 42

output:

190

result:

ok single line: '190'

Test #2:

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

input:

5 2
1 1 1 1 1

output:

0

result:

ok single line: '0'

Test #3:

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

input:

2 1
8 8

output:

20

result:

ok single line: '20'

Test #4:

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

input:

7 2
5 6 5 5 7 6 1

output:

30

result:

ok single line: '30'

Test #5:

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

input:

50 10
315 7066 3645 9498 1341 7180 5232 3439 1395 3682 597 3540 620 2755 303 609 871 9488 6121 1925 3677 9788 3467 7139 13 689 9777 2500 1175 7955 6817 8947 9192 9487 9747 2860 7389 6659 7062 5213 3870 8791 9436 6035 5180 5235 1203 8839 5271 5624

output:

248620

result:

ok single line: '248620'

Test #6:

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

input:

43 20
1 3 1 1 2 1 2 1 1 1 2 2 2 3 1 4 1 2 1 1 3 2 2 2 2 1 1 2 2 2 3 1 4 4 4 1 2 1 4 3 1 1 3

output:

0

result:

ok single line: '0'

Test #7:

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

input:

2000 20
9820 9702 7536 3536 7446 1612 3742 3409 9499 8258 7797 3589 4545 5120 2944 268 8899 6092 2926 750 1106 7007 4567 8528 7260 7341 1383 6055 5035 679 4000 7953 6570 7120 3890 5382 6484 9578 6822 6510 3417 5257 5981 3500 8012 5573 37 2180 697 9622 3368 4386 4844 4586 5590 6951 5045 7282 85 3811 ...

output:

9970950

result:

ok single line: '9970950'

Test #8:

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

input:

1000 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...

output:

500430

result:

ok single line: '500430'

Test #9:

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

input:

1000 20
10000 9999 9998 9997 9996 9995 9994 9993 9992 9991 9990 9989 9988 9987 9986 9985 9984 9983 9982 9981 9980 9979 9978 9977 9976 9975 9974 9973 9972 9971 9970 9969 9968 9967 9966 9965 9964 9963 9962 9961 9960 9959 9958 9957 9956 9955 9954 9953 9952 9951 9950 9949 9948 9947 9946 9945 9944 9943 9...

output:

9500430

result:

ok single line: '9500430'

Test #10:

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

input:

44 20
1 3 1 1 2 1 2 1 1 1 2 2 2 3 1 4 1 2 1 1 3 2 2 2 2 1 1 2 2 2 3 1 4 4 4 1 2 1 4 3 1 1 3 1

output:

10

result:

ok single line: '10'

Test #11:

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

input:

2000 20
9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 9999 99...

output:

19997920

result:

ok single line: '19997920'

Test #12:

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

input:

826 11
3955 556 3570 6805 8504 9683 7121 4544 7985 9609 7533 4695 2868 9932 2667 4719 8797 2092 4580 5581 2413 972 2364 2934 8612 5840 8808 792 774 1921 4447 3166 6475 9628 4446 616 6329 5717 5350 925 9149 8996 9468 9768 4086 837 1628 8736 8551 9184 2583 4281 6840 8084 2183 6075 5466 8091 5750 8559 ...

output:

4169890

result:

ok single line: '4169890'

Test #13:

score: 0
Accepted
time: 8ms
memory: 3416kb

input:

1000 20
8114 8919 6184 7431 8416 581 4464 7966 4110 6198 5043 7 8422 7159 280 3955 1955 9791 8349 5873 935 2786 2660 1298 4511 9636 365 4013 357 8961 9590 4141 5592 4824 2025 2823 3821 7298 5465 9899 9639 5509 2424 6823 8642 7621 9834 8152 2841 2841 3715 1792 3521 797 8699 1086 7997 161 7374 9212 52...

output:

5018970

result:

ok single line: '5018970'

Test #14:

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

input:

1000 1
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...

output:

10000

result:

ok single line: '10000'

Test #15:

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

input:

1000 5
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

980

result:

ok single line: '980'

Test #16:

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

input:

2 1
7 7

output:

10

result:

ok single line: '10'

Test #17:

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

input:

3 20
7 8 9

output:

20

result:

ok single line: '20'

Test #18:

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

input:

2 2
14 22

output:

30

result:

ok single line: '30'

Test #19:

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

input:

3 20
14 22 33

output:

60

result:

ok single line: '60'

Test #20:

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

input:

2000 20
10 10 20 20 30 30 40 40 50 50 60 60 70 70 80 80 90 90 100 100 10 10 20 20 30 30 40 40 50 50 60 60 70 70 80 80 90 90 100 100 10 10 20 20 30 30 40 40 50 50 60 60 70 70 80 80 90 90 100 100 10 10 20 20 30 30 40 40 50 50 60 60 70 70 80 80 90 90 100 100 10 10 20 20 30 30 40 40 50 50 60 60 70 70 80...

output:

110000

result:

ok single line: '110000'