# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
79998 |
2018-10-18T05:01:50 Z |
leejseo |
None (KOI17_cook) |
C++17 |
|
648 ms |
296492 KB |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int N, M, S, E, T, M_;
int C[3001][6001], F[3001];
int D[3001][6001];
int A[3001][6001];
int B[3001][6001];
typedef pair<int, int> pii;
deque<pii> que[3001];
int readint(){
bool minus = false;
int result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus = true; else result = ch-'0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result*10 + (ch - '0');
}
if (minus)
return -result;
else
return result;
}
void init(){
N = readint(), M_ = readint(), S = readint(), E = readint(), T = readint();
M = M_+S-1;
for (int i=1; i<=N; i++)
for (int j=1; j<=M_; j++) C[i][j] = readint();
for (int i=1; i<=N; i++){
for (int j=1; j<=M; j++){
D[i][j] = INF;
A[i][j] = A[i][j-1] + C[i][j];
}
}
for (int i=1; i<=N; i++) F[i] = readint();
}
void solve(){
for (int j=1; j<=M; j++){
pii min3[3] = {pii(INF, -1), pii(INF, -1), pii(INF, -1)};
for (int i=1; i<=N; i++){
while (que[i].size() && que[i].front().second < j-E)
que[i].pop_front();
if (j - S >= S){
pii tmp = pii(B[i][j-S], j-S);
while (que[i].size() && que[i].back() >= tmp)
que[i].pop_back();
que[i].push_back(tmp);
}
if (que[i].size()) D[i][j] = min(D[i][j], que[i].front().first + A[i][j] + T);
if (j <= E) D[i][j] = min(D[i][j], A[i][j]);
pii tmp = pii(D[i][j], i);
if (min3[0] >= tmp){
min3[2] = min3[1], min3[1] = min3[0], min3[0] = tmp;
}
else if (min3[1] >= tmp){
min3[2] = min3[1], min3[1] = tmp;
}
else if (min3[2] >= tmp){
min3[2] = tmp;
}
}
//update B
for (int i=1; i<=N; i++){
for (int k=0; k<3; k++){
if (min3[k].second != i && min3[k].second != F[i]){
B[i][j] = min3[k].first - A[i][j];
break;
}
}
}
}
int ans = INF;
for (int i=1; i<=N; i++)
for (int j=M_; j<=M; j++)
ans = min(ans, D[i][j]);
printf("%d\n", ans);
}
int main(){
init();
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3168 KB |
Output is correct |
2 |
Correct |
4 ms |
3348 KB |
Output is correct |
3 |
Correct |
5 ms |
3468 KB |
Output is correct |
4 |
Correct |
4 ms |
3468 KB |
Output is correct |
5 |
Correct |
5 ms |
3468 KB |
Output is correct |
6 |
Correct |
4 ms |
3476 KB |
Output is correct |
7 |
Correct |
5 ms |
3508 KB |
Output is correct |
8 |
Correct |
5 ms |
3580 KB |
Output is correct |
9 |
Correct |
4 ms |
3580 KB |
Output is correct |
10 |
Correct |
4 ms |
3580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3168 KB |
Output is correct |
2 |
Correct |
4 ms |
3348 KB |
Output is correct |
3 |
Correct |
5 ms |
3468 KB |
Output is correct |
4 |
Correct |
4 ms |
3468 KB |
Output is correct |
5 |
Correct |
5 ms |
3468 KB |
Output is correct |
6 |
Correct |
4 ms |
3476 KB |
Output is correct |
7 |
Correct |
5 ms |
3508 KB |
Output is correct |
8 |
Correct |
5 ms |
3580 KB |
Output is correct |
9 |
Correct |
4 ms |
3580 KB |
Output is correct |
10 |
Correct |
18 ms |
10020 KB |
Output is correct |
11 |
Correct |
14 ms |
10020 KB |
Output is correct |
12 |
Correct |
17 ms |
10704 KB |
Output is correct |
13 |
Correct |
17 ms |
10704 KB |
Output is correct |
14 |
Correct |
17 ms |
12000 KB |
Output is correct |
15 |
Correct |
23 ms |
12236 KB |
Output is correct |
16 |
Correct |
17 ms |
12360 KB |
Output is correct |
17 |
Correct |
17 ms |
12360 KB |
Output is correct |
18 |
Correct |
17 ms |
13692 KB |
Output is correct |
19 |
Correct |
16 ms |
13692 KB |
Output is correct |
20 |
Correct |
4 ms |
3580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3168 KB |
Output is correct |
2 |
Correct |
4 ms |
3348 KB |
Output is correct |
3 |
Correct |
5 ms |
3468 KB |
Output is correct |
4 |
Correct |
4 ms |
3468 KB |
Output is correct |
5 |
Correct |
5 ms |
3468 KB |
Output is correct |
6 |
Correct |
4 ms |
3476 KB |
Output is correct |
7 |
Correct |
5 ms |
3508 KB |
Output is correct |
8 |
Correct |
5 ms |
3580 KB |
Output is correct |
9 |
Correct |
4 ms |
3580 KB |
Output is correct |
10 |
Correct |
18 ms |
10020 KB |
Output is correct |
11 |
Correct |
14 ms |
10020 KB |
Output is correct |
12 |
Correct |
17 ms |
10704 KB |
Output is correct |
13 |
Correct |
17 ms |
10704 KB |
Output is correct |
14 |
Correct |
17 ms |
12000 KB |
Output is correct |
15 |
Correct |
23 ms |
12236 KB |
Output is correct |
16 |
Correct |
17 ms |
12360 KB |
Output is correct |
17 |
Correct |
17 ms |
12360 KB |
Output is correct |
18 |
Correct |
17 ms |
13692 KB |
Output is correct |
19 |
Correct |
16 ms |
13692 KB |
Output is correct |
20 |
Correct |
215 ms |
79336 KB |
Output is correct |
21 |
Correct |
223 ms |
79676 KB |
Output is correct |
22 |
Correct |
208 ms |
84980 KB |
Output is correct |
23 |
Correct |
240 ms |
95736 KB |
Output is correct |
24 |
Correct |
234 ms |
104516 KB |
Output is correct |
25 |
Correct |
206 ms |
104516 KB |
Output is correct |
26 |
Correct |
212 ms |
104520 KB |
Output is correct |
27 |
Correct |
278 ms |
116024 KB |
Output is correct |
28 |
Correct |
225 ms |
116160 KB |
Output is correct |
29 |
Correct |
245 ms |
129344 KB |
Output is correct |
30 |
Correct |
4 ms |
3580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3168 KB |
Output is correct |
2 |
Correct |
4 ms |
3348 KB |
Output is correct |
3 |
Correct |
5 ms |
3468 KB |
Output is correct |
4 |
Correct |
4 ms |
3468 KB |
Output is correct |
5 |
Correct |
5 ms |
3468 KB |
Output is correct |
6 |
Correct |
4 ms |
3476 KB |
Output is correct |
7 |
Correct |
5 ms |
3508 KB |
Output is correct |
8 |
Correct |
5 ms |
3580 KB |
Output is correct |
9 |
Correct |
4 ms |
3580 KB |
Output is correct |
10 |
Correct |
18 ms |
10020 KB |
Output is correct |
11 |
Correct |
14 ms |
10020 KB |
Output is correct |
12 |
Correct |
17 ms |
10704 KB |
Output is correct |
13 |
Correct |
17 ms |
10704 KB |
Output is correct |
14 |
Correct |
17 ms |
12000 KB |
Output is correct |
15 |
Correct |
23 ms |
12236 KB |
Output is correct |
16 |
Correct |
17 ms |
12360 KB |
Output is correct |
17 |
Correct |
17 ms |
12360 KB |
Output is correct |
18 |
Correct |
17 ms |
13692 KB |
Output is correct |
19 |
Correct |
16 ms |
13692 KB |
Output is correct |
20 |
Correct |
109 ms |
129344 KB |
Output is correct |
21 |
Correct |
116 ms |
129344 KB |
Output is correct |
22 |
Correct |
107 ms |
129344 KB |
Output is correct |
23 |
Correct |
119 ms |
129344 KB |
Output is correct |
24 |
Correct |
111 ms |
129344 KB |
Output is correct |
25 |
Correct |
109 ms |
129344 KB |
Output is correct |
26 |
Correct |
109 ms |
129344 KB |
Output is correct |
27 |
Correct |
110 ms |
129344 KB |
Output is correct |
28 |
Correct |
115 ms |
129344 KB |
Output is correct |
29 |
Correct |
119 ms |
129344 KB |
Output is correct |
30 |
Correct |
4 ms |
3580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3168 KB |
Output is correct |
2 |
Correct |
4 ms |
3348 KB |
Output is correct |
3 |
Correct |
5 ms |
3468 KB |
Output is correct |
4 |
Correct |
4 ms |
3468 KB |
Output is correct |
5 |
Correct |
5 ms |
3468 KB |
Output is correct |
6 |
Correct |
4 ms |
3476 KB |
Output is correct |
7 |
Correct |
5 ms |
3508 KB |
Output is correct |
8 |
Correct |
5 ms |
3580 KB |
Output is correct |
9 |
Correct |
4 ms |
3580 KB |
Output is correct |
10 |
Correct |
18 ms |
10020 KB |
Output is correct |
11 |
Correct |
14 ms |
10020 KB |
Output is correct |
12 |
Correct |
17 ms |
10704 KB |
Output is correct |
13 |
Correct |
17 ms |
10704 KB |
Output is correct |
14 |
Correct |
17 ms |
12000 KB |
Output is correct |
15 |
Correct |
23 ms |
12236 KB |
Output is correct |
16 |
Correct |
17 ms |
12360 KB |
Output is correct |
17 |
Correct |
17 ms |
12360 KB |
Output is correct |
18 |
Correct |
17 ms |
13692 KB |
Output is correct |
19 |
Correct |
16 ms |
13692 KB |
Output is correct |
20 |
Correct |
215 ms |
79336 KB |
Output is correct |
21 |
Correct |
223 ms |
79676 KB |
Output is correct |
22 |
Correct |
208 ms |
84980 KB |
Output is correct |
23 |
Correct |
240 ms |
95736 KB |
Output is correct |
24 |
Correct |
234 ms |
104516 KB |
Output is correct |
25 |
Correct |
206 ms |
104516 KB |
Output is correct |
26 |
Correct |
212 ms |
104520 KB |
Output is correct |
27 |
Correct |
278 ms |
116024 KB |
Output is correct |
28 |
Correct |
225 ms |
116160 KB |
Output is correct |
29 |
Correct |
245 ms |
129344 KB |
Output is correct |
30 |
Correct |
109 ms |
129344 KB |
Output is correct |
31 |
Correct |
116 ms |
129344 KB |
Output is correct |
32 |
Correct |
107 ms |
129344 KB |
Output is correct |
33 |
Correct |
119 ms |
129344 KB |
Output is correct |
34 |
Correct |
111 ms |
129344 KB |
Output is correct |
35 |
Correct |
109 ms |
129344 KB |
Output is correct |
36 |
Correct |
109 ms |
129344 KB |
Output is correct |
37 |
Correct |
110 ms |
129344 KB |
Output is correct |
38 |
Correct |
115 ms |
129344 KB |
Output is correct |
39 |
Correct |
119 ms |
129344 KB |
Output is correct |
40 |
Correct |
166 ms |
136880 KB |
Output is correct |
41 |
Correct |
545 ms |
190488 KB |
Output is correct |
42 |
Correct |
512 ms |
205804 KB |
Output is correct |
43 |
Correct |
648 ms |
258140 KB |
Output is correct |
44 |
Correct |
212 ms |
258140 KB |
Output is correct |
45 |
Correct |
296 ms |
258140 KB |
Output is correct |
46 |
Correct |
336 ms |
258140 KB |
Output is correct |
47 |
Correct |
481 ms |
278092 KB |
Output is correct |
48 |
Correct |
526 ms |
279896 KB |
Output is correct |
49 |
Correct |
535 ms |
296492 KB |
Output is correct |
50 |
Correct |
4 ms |
3580 KB |
Output is correct |