답안 #897782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
897782 2024-01-03T16:37:47 Z aqxa 선물상자 (IOI15_boxes) C++17
100 / 100
477 ms 294004 KB
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long; 

const int N = 1e7 + 10; 

#include "boxes.h"

ll ans0[N], ans1[N]; 

long long delivery(int n, int k, int m, int p[]) {
	for (int i = 0; i < n; ++i) {
		if (i < k) {
			ans0[i] = p[i] + min(p[i], m - p[i]); 
			ans1[n - 1 - i] = (ll) m - p[n - 1 - i] + min((ll)p[n - 1 - i], (ll)m - p[n - 1 - i]); 
		} else {
			ans0[i] = ans0[i - k] + p[i] + min(p[i], m - p[i]); 
			ans1[n - 1 - i] = ans1[n - 1 - i + k] + (ll) m - p[n - 1 - i] + min((ll)p[n - 1 - i], (ll)m - p[n - 1 - i]); 
		}
	}
	ll ans = ans0[n - 1]; 
	ans = min(ans, ans1[0]); 
	for (int i = 0; i < n - 1; ++i) {
		ans = min(ans, ans0[i] + ans1[i + 1]); 
	}

    return ans;
}

 
 
// int32_t main() {
// 	ios::sync_with_stdio(false);
// 	cin.tie(nullptr);
 
// 	int n, k, m; 
// 	cin >> n >> k >> m; 
// 	int pos[n]; 
// 	for (int i = 0; i < n; ++i) {
// 		cin >> pos[i]; 
// 	}
// 	cout << "answer: " << delivery(n, k, m, pos) << "\n";
 
// 	return 0; 
// }	 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2496 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2496 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2496 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2492 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2496 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2500 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2496 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2492 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2496 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2500 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 39 ms 30580 KB Output is correct
34 Correct 13 ms 22872 KB Output is correct
35 Correct 16 ms 23248 KB Output is correct
36 Correct 40 ms 30652 KB Output is correct
37 Correct 40 ms 30516 KB Output is correct
38 Correct 39 ms 30492 KB Output is correct
39 Correct 35 ms 29200 KB Output is correct
40 Correct 19 ms 24400 KB Output is correct
41 Correct 39 ms 30544 KB Output is correct
42 Correct 20 ms 24708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2496 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2492 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2496 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2500 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 39 ms 30580 KB Output is correct
34 Correct 13 ms 22872 KB Output is correct
35 Correct 16 ms 23248 KB Output is correct
36 Correct 40 ms 30652 KB Output is correct
37 Correct 40 ms 30516 KB Output is correct
38 Correct 39 ms 30492 KB Output is correct
39 Correct 35 ms 29200 KB Output is correct
40 Correct 19 ms 24400 KB Output is correct
41 Correct 39 ms 30544 KB Output is correct
42 Correct 20 ms 24708 KB Output is correct
43 Correct 396 ms 292908 KB Output is correct
44 Correct 121 ms 215692 KB Output is correct
45 Correct 150 ms 223316 KB Output is correct
46 Correct 401 ms 294004 KB Output is correct
47 Correct 410 ms 293916 KB Output is correct
48 Correct 477 ms 293320 KB Output is correct
49 Correct 353 ms 278908 KB Output is correct
50 Correct 180 ms 232476 KB Output is correct
51 Correct 400 ms 293812 KB Output is correct
52 Correct 195 ms 235068 KB Output is correct