#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ryan bear
#define sq(X) ((X)*(X))
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
#define unq(V) (V).erase(unique(all(V)), (V).end())
using namespace std;
typedef long long ll;
typedef vector<ll> vlm;
typedef vector<int> vim;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
int N, M, S, E, T;
vim ar[3010]; int ban[3010]; deque<pii> dq[3010];
int Dp[3010][3010];
int get(int i, int s, int e) { return s?(ar[i][e]-ar[i][s-1]):ar[i][e]; }
int main() {
scanf("%d %d %d %d %d", &N, &M, &S, &E, &T);
for (int i=1; i<=N; i++) {
ar[i].resize(M+1);
for (int j=1; j<=M; j++) { scanf("%d", &ar[i][j]); ar[i][j]+=ar[i][j-1]; }
}
for (int i=1; i<=N; i++) scanf("%d", &ban[i]);
for (int i=2; i<=S; i++) for (int j=1; j<=N; j++) Dp[j][i]=(3<<29);
for (int i=S+1; i<=M; i++) {
pii m1, m2, m3, im; m1=m2=m3=pii((3<<29), (3<<29));
for (int j=1; j<=N; j++) {
while (!dq[j].empty()&&dq[j].front().fi<i-E) dq[j].pop_front();
while (!dq[j].empty()&&dq[j].back().se+get(j, dq[j].back().fi, i-1)>=Dp[j][i-S]+get(j, i-S, i-1)) dq[j].pop_back();
dq[j].eb(i-S, Dp[j][i-S]);
im=pii(dq[j].front().se+get(j, dq[j].front().fi, i-1), j);
if (im.fi<=m1.fi) { m3=m2; m2=m1; m1=im; }
else if (im.fi<=m2.fi) { m3=m2; m2=im; }
else if (im.fi<=m3.fi) m3=im;
}
for (int j=1; j<=N; j++) {
if (m1.se==j||m1.se==ban[j]) {
if (m2.se==j||m2.se==ban[j]) Dp[j][i]=m3.fi+T;
else Dp[j][i]=m2.fi+T;
}
else Dp[j][i]=m1.fi+T;
}
}
int ans=(3<<29);
for (int i=M-E+1; i<=M; i++) for (int j=1; j<=N; j++) ans=min(ans, Dp[j][i]+get(j, i, M));
printf("%d\n", ans);
return 0;
}
Compilation message
cook.cpp: In function 'int main()':
cook.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d %d", &N, &M, &S, &E, &T);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cook.cpp:27:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int j=1; j<=M; j++) { scanf("%d", &ar[i][j]); ar[i][j]+=ar[i][j-1]; }
~~~~~^~~~~~~~~~~~~~~~~
cook.cpp:29:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1; i<=N; i++) scanf("%d", &ban[i]);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
6 ms |
2552 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2552 KB |
Output is correct |
5 |
Correct |
6 ms |
2652 KB |
Output is correct |
6 |
Correct |
5 ms |
2684 KB |
Output is correct |
7 |
Correct |
5 ms |
2680 KB |
Output is correct |
8 |
Correct |
5 ms |
2680 KB |
Output is correct |
9 |
Correct |
5 ms |
2680 KB |
Output is correct |
10 |
Correct |
5 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
6 ms |
2552 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2552 KB |
Output is correct |
5 |
Correct |
6 ms |
2652 KB |
Output is correct |
6 |
Correct |
5 ms |
2684 KB |
Output is correct |
7 |
Correct |
5 ms |
2680 KB |
Output is correct |
8 |
Correct |
5 ms |
2680 KB |
Output is correct |
9 |
Correct |
5 ms |
2680 KB |
Output is correct |
10 |
Correct |
20 ms |
4856 KB |
Output is correct |
11 |
Correct |
17 ms |
4472 KB |
Output is correct |
12 |
Correct |
22 ms |
4960 KB |
Output is correct |
13 |
Correct |
18 ms |
4600 KB |
Output is correct |
14 |
Correct |
21 ms |
4856 KB |
Output is correct |
15 |
Correct |
22 ms |
4856 KB |
Output is correct |
16 |
Correct |
21 ms |
4900 KB |
Output is correct |
17 |
Correct |
14 ms |
3960 KB |
Output is correct |
18 |
Correct |
20 ms |
4856 KB |
Output is correct |
19 |
Correct |
14 ms |
4088 KB |
Output is correct |
20 |
Correct |
5 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
6 ms |
2552 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2552 KB |
Output is correct |
5 |
Correct |
6 ms |
2652 KB |
Output is correct |
6 |
Correct |
5 ms |
2684 KB |
Output is correct |
7 |
Correct |
5 ms |
2680 KB |
Output is correct |
8 |
Correct |
5 ms |
2680 KB |
Output is correct |
9 |
Correct |
5 ms |
2680 KB |
Output is correct |
10 |
Correct |
20 ms |
4856 KB |
Output is correct |
11 |
Correct |
17 ms |
4472 KB |
Output is correct |
12 |
Correct |
22 ms |
4960 KB |
Output is correct |
13 |
Correct |
18 ms |
4600 KB |
Output is correct |
14 |
Correct |
21 ms |
4856 KB |
Output is correct |
15 |
Correct |
22 ms |
4856 KB |
Output is correct |
16 |
Correct |
21 ms |
4900 KB |
Output is correct |
17 |
Correct |
14 ms |
3960 KB |
Output is correct |
18 |
Correct |
20 ms |
4856 KB |
Output is correct |
19 |
Correct |
14 ms |
4088 KB |
Output is correct |
20 |
Correct |
181 ms |
26528 KB |
Output is correct |
21 |
Correct |
198 ms |
26488 KB |
Output is correct |
22 |
Correct |
192 ms |
26616 KB |
Output is correct |
23 |
Correct |
178 ms |
26616 KB |
Output is correct |
24 |
Correct |
162 ms |
26588 KB |
Output is correct |
25 |
Correct |
197 ms |
26488 KB |
Output is correct |
26 |
Correct |
200 ms |
26536 KB |
Output is correct |
27 |
Correct |
166 ms |
26492 KB |
Output is correct |
28 |
Correct |
197 ms |
26564 KB |
Output is correct |
29 |
Correct |
159 ms |
26488 KB |
Output is correct |
30 |
Correct |
5 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
6 ms |
2552 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2552 KB |
Output is correct |
5 |
Correct |
6 ms |
2652 KB |
Output is correct |
6 |
Correct |
5 ms |
2684 KB |
Output is correct |
7 |
Correct |
5 ms |
2680 KB |
Output is correct |
8 |
Correct |
5 ms |
2680 KB |
Output is correct |
9 |
Correct |
5 ms |
2680 KB |
Output is correct |
10 |
Correct |
20 ms |
4856 KB |
Output is correct |
11 |
Correct |
17 ms |
4472 KB |
Output is correct |
12 |
Correct |
22 ms |
4960 KB |
Output is correct |
13 |
Correct |
18 ms |
4600 KB |
Output is correct |
14 |
Correct |
21 ms |
4856 KB |
Output is correct |
15 |
Correct |
22 ms |
4856 KB |
Output is correct |
16 |
Correct |
21 ms |
4900 KB |
Output is correct |
17 |
Correct |
14 ms |
3960 KB |
Output is correct |
18 |
Correct |
20 ms |
4856 KB |
Output is correct |
19 |
Correct |
14 ms |
4088 KB |
Output is correct |
20 |
Correct |
181 ms |
14392 KB |
Output is correct |
21 |
Correct |
158 ms |
14420 KB |
Output is correct |
22 |
Correct |
163 ms |
14456 KB |
Output is correct |
23 |
Correct |
144 ms |
14328 KB |
Output is correct |
24 |
Correct |
168 ms |
14380 KB |
Output is correct |
25 |
Correct |
160 ms |
14464 KB |
Output is correct |
26 |
Correct |
163 ms |
14388 KB |
Output is correct |
27 |
Correct |
170 ms |
14436 KB |
Output is correct |
28 |
Correct |
176 ms |
14460 KB |
Output is correct |
29 |
Correct |
154 ms |
14472 KB |
Output is correct |
30 |
Correct |
5 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2680 KB |
Output is correct |
2 |
Correct |
6 ms |
2552 KB |
Output is correct |
3 |
Correct |
5 ms |
2680 KB |
Output is correct |
4 |
Correct |
5 ms |
2552 KB |
Output is correct |
5 |
Correct |
6 ms |
2652 KB |
Output is correct |
6 |
Correct |
5 ms |
2684 KB |
Output is correct |
7 |
Correct |
5 ms |
2680 KB |
Output is correct |
8 |
Correct |
5 ms |
2680 KB |
Output is correct |
9 |
Correct |
5 ms |
2680 KB |
Output is correct |
10 |
Correct |
20 ms |
4856 KB |
Output is correct |
11 |
Correct |
17 ms |
4472 KB |
Output is correct |
12 |
Correct |
22 ms |
4960 KB |
Output is correct |
13 |
Correct |
18 ms |
4600 KB |
Output is correct |
14 |
Correct |
21 ms |
4856 KB |
Output is correct |
15 |
Correct |
22 ms |
4856 KB |
Output is correct |
16 |
Correct |
21 ms |
4900 KB |
Output is correct |
17 |
Correct |
14 ms |
3960 KB |
Output is correct |
18 |
Correct |
20 ms |
4856 KB |
Output is correct |
19 |
Correct |
14 ms |
4088 KB |
Output is correct |
20 |
Correct |
181 ms |
26528 KB |
Output is correct |
21 |
Correct |
198 ms |
26488 KB |
Output is correct |
22 |
Correct |
192 ms |
26616 KB |
Output is correct |
23 |
Correct |
178 ms |
26616 KB |
Output is correct |
24 |
Correct |
162 ms |
26588 KB |
Output is correct |
25 |
Correct |
197 ms |
26488 KB |
Output is correct |
26 |
Correct |
200 ms |
26536 KB |
Output is correct |
27 |
Correct |
166 ms |
26492 KB |
Output is correct |
28 |
Correct |
197 ms |
26564 KB |
Output is correct |
29 |
Correct |
159 ms |
26488 KB |
Output is correct |
30 |
Correct |
181 ms |
14392 KB |
Output is correct |
31 |
Correct |
158 ms |
14420 KB |
Output is correct |
32 |
Correct |
163 ms |
14456 KB |
Output is correct |
33 |
Correct |
144 ms |
14328 KB |
Output is correct |
34 |
Correct |
168 ms |
14380 KB |
Output is correct |
35 |
Correct |
160 ms |
14464 KB |
Output is correct |
36 |
Correct |
163 ms |
14388 KB |
Output is correct |
37 |
Correct |
170 ms |
14436 KB |
Output is correct |
38 |
Correct |
176 ms |
14460 KB |
Output is correct |
39 |
Correct |
154 ms |
14472 KB |
Output is correct |
40 |
Correct |
227 ms |
18424 KB |
Output is correct |
41 |
Correct |
601 ms |
42360 KB |
Output is correct |
42 |
Correct |
563 ms |
42360 KB |
Output is correct |
43 |
Correct |
639 ms |
54280 KB |
Output is correct |
44 |
Correct |
268 ms |
22588 KB |
Output is correct |
45 |
Correct |
319 ms |
26324 KB |
Output is correct |
46 |
Correct |
357 ms |
30884 KB |
Output is correct |
47 |
Correct |
450 ms |
38376 KB |
Output is correct |
48 |
Correct |
618 ms |
42360 KB |
Output is correct |
49 |
Correct |
616 ms |
42360 KB |
Output is correct |
50 |
Correct |
5 ms |
2552 KB |
Output is correct |