답안 #469346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469346 2021-08-31T14:24:49 Z 1bin 요리 강좌 (KOI17_cook) C++14
100 / 100
527 ms 124944 KB
#include <bits/stdc++.h>

using namespace std;

#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 3e3 + 5;
ll n, m, s, e, t, c[NMAX][NMAX], b[NMAX], mn[3], ix[3], x, p[NMAX][NMAX], ans;
deque <pair<ll, ll>> dq[NMAX];

void go(ll idx, ll v) {
	if (v < mn[2]) {
		mn[2] = v; ix[2] = idx;
	}
	for (int k = 2; k; k--)
		if (mn[k - 1] > mn[k]) {
			swap(mn[k - 1], mn[k]);
			swap(ix[k - 1], ix[k]);
		}
	return;
}

int main(void) {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n >> m >> s >> e >> t;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			cin >> c[i][j];
			c[i][j] += c[i][j - 1];
		}

	fill(&p[0][0], &p[NMAX - 1][NMAX], 1e18);
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		dq[i].emplace_back(1e18, 0);
		p[i][s] = 0;
	}
	ans = 1e18;
	for (int j = 1; j <= m; j++) {
		for (int i = 1; i <= n; i++) {
			x = p[i][j];
			while (dq[i].size() && dq[i].back().first >= x) dq[i].pop_back();
			dq[i].emplace_back(x, j - s + 1);
			if (dq[i].front().second == j - e) dq[i].pop_front();
		}

		for (int k = 0; k < 3; k++) mn[k] = 1e18;
		for (int i = 1; i <= n; i++) {
			x = dq[i].front().first + c[i][j];
			go(i, x);
		}

		for (int i = 1; i <= n; i++)
			for (int k = 0; k < 3; k++) {
				if (ix[k] == i || ix[k] == b[i]) continue;
				x = mn[k] - c[i][j] + t * (j != m);
				if (j + s <= m) p[i][j + s] = x;
				if (j + e >= m) ans = min(ans, x + c[i][m]);
				break;
			}
	}
	cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 73156 KB Output is correct
2 Correct 35 ms 73164 KB Output is correct
3 Correct 39 ms 73156 KB Output is correct
4 Correct 35 ms 73144 KB Output is correct
5 Correct 33 ms 73228 KB Output is correct
6 Correct 33 ms 73236 KB Output is correct
7 Correct 33 ms 73120 KB Output is correct
8 Correct 33 ms 73164 KB Output is correct
9 Correct 35 ms 73192 KB Output is correct
10 Correct 34 ms 73136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 73156 KB Output is correct
2 Correct 35 ms 73164 KB Output is correct
3 Correct 39 ms 73156 KB Output is correct
4 Correct 35 ms 73144 KB Output is correct
5 Correct 33 ms 73228 KB Output is correct
6 Correct 33 ms 73236 KB Output is correct
7 Correct 33 ms 73120 KB Output is correct
8 Correct 33 ms 73164 KB Output is correct
9 Correct 35 ms 73192 KB Output is correct
10 Correct 34 ms 73136 KB Output is correct
11 Correct 45 ms 75404 KB Output is correct
12 Correct 42 ms 74928 KB Output is correct
13 Correct 44 ms 75436 KB Output is correct
14 Correct 42 ms 74956 KB Output is correct
15 Correct 47 ms 75456 KB Output is correct
16 Correct 46 ms 75324 KB Output is correct
17 Correct 46 ms 75348 KB Output is correct
18 Correct 41 ms 74556 KB Output is correct
19 Correct 43 ms 75332 KB Output is correct
20 Correct 41 ms 74528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 73156 KB Output is correct
2 Correct 35 ms 73164 KB Output is correct
3 Correct 39 ms 73156 KB Output is correct
4 Correct 35 ms 73144 KB Output is correct
5 Correct 33 ms 73228 KB Output is correct
6 Correct 33 ms 73236 KB Output is correct
7 Correct 33 ms 73120 KB Output is correct
8 Correct 33 ms 73164 KB Output is correct
9 Correct 35 ms 73192 KB Output is correct
10 Correct 45 ms 75404 KB Output is correct
11 Correct 42 ms 74928 KB Output is correct
12 Correct 44 ms 75436 KB Output is correct
13 Correct 42 ms 74956 KB Output is correct
14 Correct 47 ms 75456 KB Output is correct
15 Correct 46 ms 75324 KB Output is correct
16 Correct 46 ms 75348 KB Output is correct
17 Correct 41 ms 74556 KB Output is correct
18 Correct 43 ms 75332 KB Output is correct
19 Correct 41 ms 74528 KB Output is correct
20 Correct 34 ms 73136 KB Output is correct
21 Correct 174 ms 97036 KB Output is correct
22 Correct 197 ms 96964 KB Output is correct
23 Correct 179 ms 97044 KB Output is correct
24 Correct 173 ms 96964 KB Output is correct
25 Correct 177 ms 97280 KB Output is correct
26 Correct 220 ms 96964 KB Output is correct
27 Correct 182 ms 97020 KB Output is correct
28 Correct 174 ms 97008 KB Output is correct
29 Correct 229 ms 97072 KB Output is correct
30 Correct 170 ms 96964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 73156 KB Output is correct
2 Correct 35 ms 73164 KB Output is correct
3 Correct 39 ms 73156 KB Output is correct
4 Correct 35 ms 73144 KB Output is correct
5 Correct 33 ms 73228 KB Output is correct
6 Correct 33 ms 73236 KB Output is correct
7 Correct 33 ms 73120 KB Output is correct
8 Correct 33 ms 73164 KB Output is correct
9 Correct 35 ms 73192 KB Output is correct
10 Correct 45 ms 75404 KB Output is correct
11 Correct 42 ms 74928 KB Output is correct
12 Correct 44 ms 75436 KB Output is correct
13 Correct 42 ms 74956 KB Output is correct
14 Correct 47 ms 75456 KB Output is correct
15 Correct 46 ms 75324 KB Output is correct
16 Correct 46 ms 75348 KB Output is correct
17 Correct 41 ms 74556 KB Output is correct
18 Correct 43 ms 75332 KB Output is correct
19 Correct 41 ms 74528 KB Output is correct
20 Correct 34 ms 73136 KB Output is correct
21 Correct 156 ms 84864 KB Output is correct
22 Correct 153 ms 85052 KB Output is correct
23 Correct 151 ms 84932 KB Output is correct
24 Correct 147 ms 84896 KB Output is correct
25 Correct 153 ms 84932 KB Output is correct
26 Correct 151 ms 85016 KB Output is correct
27 Correct 158 ms 84944 KB Output is correct
28 Correct 150 ms 84936 KB Output is correct
29 Correct 156 ms 84940 KB Output is correct
30 Correct 171 ms 85008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 73156 KB Output is correct
2 Correct 35 ms 73164 KB Output is correct
3 Correct 39 ms 73156 KB Output is correct
4 Correct 35 ms 73144 KB Output is correct
5 Correct 33 ms 73228 KB Output is correct
6 Correct 33 ms 73236 KB Output is correct
7 Correct 33 ms 73120 KB Output is correct
8 Correct 33 ms 73164 KB Output is correct
9 Correct 35 ms 73192 KB Output is correct
10 Correct 45 ms 75404 KB Output is correct
11 Correct 42 ms 74928 KB Output is correct
12 Correct 44 ms 75436 KB Output is correct
13 Correct 42 ms 74956 KB Output is correct
14 Correct 47 ms 75456 KB Output is correct
15 Correct 46 ms 75324 KB Output is correct
16 Correct 46 ms 75348 KB Output is correct
17 Correct 41 ms 74556 KB Output is correct
18 Correct 43 ms 75332 KB Output is correct
19 Correct 41 ms 74528 KB Output is correct
20 Correct 174 ms 97036 KB Output is correct
21 Correct 197 ms 96964 KB Output is correct
22 Correct 179 ms 97044 KB Output is correct
23 Correct 173 ms 96964 KB Output is correct
24 Correct 177 ms 97280 KB Output is correct
25 Correct 220 ms 96964 KB Output is correct
26 Correct 182 ms 97020 KB Output is correct
27 Correct 174 ms 97008 KB Output is correct
28 Correct 229 ms 97072 KB Output is correct
29 Correct 170 ms 96964 KB Output is correct
30 Correct 156 ms 84864 KB Output is correct
31 Correct 153 ms 85052 KB Output is correct
32 Correct 151 ms 84932 KB Output is correct
33 Correct 147 ms 84896 KB Output is correct
34 Correct 153 ms 84932 KB Output is correct
35 Correct 151 ms 85016 KB Output is correct
36 Correct 158 ms 84944 KB Output is correct
37 Correct 150 ms 84936 KB Output is correct
38 Correct 156 ms 84940 KB Output is correct
39 Correct 171 ms 85008 KB Output is correct
40 Correct 34 ms 73136 KB Output is correct
41 Correct 199 ms 88940 KB Output is correct
42 Correct 505 ms 112836 KB Output is correct
43 Correct 478 ms 112788 KB Output is correct
44 Correct 527 ms 124944 KB Output is correct
45 Correct 237 ms 92868 KB Output is correct
46 Correct 292 ms 96964 KB Output is correct
47 Correct 341 ms 100816 KB Output is correct
48 Correct 429 ms 108948 KB Output is correct
49 Correct 496 ms 112944 KB Output is correct
50 Correct 514 ms 112912 KB Output is correct