Submission #124486

# Submission time Handle Problem Language Result Execution time Memory
124486 2019-07-03T12:08:01 Z DJ035 None (KOI17_cook) C++14
100 / 100
577 ms 78052 KB
#include<bits/stdc++.h>
#define OO 1987654321
using namespace std;
int N,M,S,E,T;
int A[3003][3003],B[3003];
int C[3003][3003],DP[3003][3003];
deque<pair<int,int> > dq[3003];
pair<int,int> mn[3003][3];
int get_min(int day, int academy){
	if(mn[day][0].second != academy && mn[day][0].second != B[academy]){
		return mn[day][0].first;
	}
	if(mn[day][1].second != academy && mn[day][1].second != B[academy]){
		return mn[day][1].first;
	}
	return mn[day][2].first;
}
int main(){
	scanf("%d%d%d%d%d",&N,&M,&S,&E,&T);
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=M;j++){
			scanf("%d",&A[i][j]);
			C[i][j] = C[i][j-1]+A[i][j];
		}
	}
	for(int i = 1;i<=N;i++){
		scanf("%d",&B[i]);
	}
	for(int i = 1;i<=M;i++){
		for(int j = 1;j<=N;j++){
			if(i>=S){
				int tmp = get_min(i-S,j)-C[j][i-S];
				while(!dq[j].empty() && dq[j].back().first >= tmp){
					dq[j].pop_back();
				}
				dq[j].push_back(make_pair(tmp,i-S));
			}
			while(!dq[j].empty() && dq[j].front().second < i-E){
				dq[j].pop_front();
			}
			if(dq[j].empty() || dq[j].front().first == OO){
				DP[i][j] = OO;
			}
			else{
				DP[i][j] = dq[j].front().first+T+C[j][i];
			}
		}
		for(int j = 0;j<3;j++){
			mn[i][j] = make_pair(OO,0);
		}
		for(int j = 1;j<=N;j++){
			if(DP[i][j] == OO){
				continue;
			}
			int tmp = DP[i][j];
			if(tmp<mn[i][0].first){
				mn[i][2] = mn[i][1], mn[i][1] = mn[i][0], mn[i][0] = make_pair(tmp,j);
			}
			else if(tmp<mn[i][1].first){
				mn[i][2] = mn[i][1], mn[i][1] = make_pair(tmp,j);
			}
			else if(tmp<mn[i][2].first){
				mn[i][2] = make_pair(tmp,j);
			}
		}
	}
	int ans = OO;
	for(int i = 1;i<=N;i++){
		for(int j = M-E;j<M;j++){
			int tmp = get_min(j,i);
			if(tmp == OO){
				continue;
			}
			ans = min(ans,tmp+C[i][M]-C[i][j]);
		}
	}
	printf("%d",ans);
}

Compilation message

cook.cpp: In function 'int main()':
cook.cpp:19: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:22:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&A[i][j]);
    ~~~~~^~~~~~~~~~~~~~~
cook.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&B[i]);
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 5 ms 3068 KB Output is correct
3 Correct 4 ms 2936 KB Output is correct
4 Correct 4 ms 2780 KB Output is correct
5 Correct 5 ms 2936 KB Output is correct
6 Correct 5 ms 3064 KB Output is correct
7 Correct 4 ms 2936 KB Output is correct
8 Correct 5 ms 3064 KB Output is correct
9 Correct 4 ms 2936 KB Output is correct
10 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 5 ms 3068 KB Output is correct
3 Correct 4 ms 2936 KB Output is correct
4 Correct 4 ms 2780 KB Output is correct
5 Correct 5 ms 2936 KB Output is correct
6 Correct 5 ms 3064 KB Output is correct
7 Correct 4 ms 2936 KB Output is correct
8 Correct 5 ms 3064 KB Output is correct
9 Correct 4 ms 2936 KB Output is correct
10 Correct 21 ms 7160 KB Output is correct
11 Correct 17 ms 6264 KB Output is correct
12 Correct 21 ms 7096 KB Output is correct
13 Correct 17 ms 6344 KB Output is correct
14 Correct 21 ms 7032 KB Output is correct
15 Correct 22 ms 7032 KB Output is correct
16 Correct 22 ms 7032 KB Output is correct
17 Correct 15 ms 5880 KB Output is correct
18 Correct 21 ms 7032 KB Output is correct
19 Correct 15 ms 5880 KB Output is correct
20 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 5 ms 3068 KB Output is correct
3 Correct 4 ms 2936 KB Output is correct
4 Correct 4 ms 2780 KB Output is correct
5 Correct 5 ms 2936 KB Output is correct
6 Correct 5 ms 3064 KB Output is correct
7 Correct 4 ms 2936 KB Output is correct
8 Correct 5 ms 3064 KB Output is correct
9 Correct 4 ms 2936 KB Output is correct
10 Correct 21 ms 7160 KB Output is correct
11 Correct 17 ms 6264 KB Output is correct
12 Correct 21 ms 7096 KB Output is correct
13 Correct 17 ms 6344 KB Output is correct
14 Correct 21 ms 7032 KB Output is correct
15 Correct 22 ms 7032 KB Output is correct
16 Correct 22 ms 7032 KB Output is correct
17 Correct 15 ms 5880 KB Output is correct
18 Correct 21 ms 7032 KB Output is correct
19 Correct 15 ms 5880 KB Output is correct
20 Correct 175 ms 37080 KB Output is correct
21 Correct 189 ms 36992 KB Output is correct
22 Correct 187 ms 37116 KB Output is correct
23 Correct 172 ms 37072 KB Output is correct
24 Correct 160 ms 37112 KB Output is correct
25 Correct 188 ms 37112 KB Output is correct
26 Correct 188 ms 37112 KB Output is correct
27 Correct 170 ms 37112 KB Output is correct
28 Correct 186 ms 37056 KB Output is correct
29 Correct 161 ms 37052 KB Output is correct
30 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 5 ms 3068 KB Output is correct
3 Correct 4 ms 2936 KB Output is correct
4 Correct 4 ms 2780 KB Output is correct
5 Correct 5 ms 2936 KB Output is correct
6 Correct 5 ms 3064 KB Output is correct
7 Correct 4 ms 2936 KB Output is correct
8 Correct 5 ms 3064 KB Output is correct
9 Correct 4 ms 2936 KB Output is correct
10 Correct 21 ms 7160 KB Output is correct
11 Correct 17 ms 6264 KB Output is correct
12 Correct 21 ms 7096 KB Output is correct
13 Correct 17 ms 6344 KB Output is correct
14 Correct 21 ms 7032 KB Output is correct
15 Correct 22 ms 7032 KB Output is correct
16 Correct 22 ms 7032 KB Output is correct
17 Correct 15 ms 5880 KB Output is correct
18 Correct 21 ms 7032 KB Output is correct
19 Correct 15 ms 5880 KB Output is correct
20 Correct 167 ms 25052 KB Output is correct
21 Correct 162 ms 25072 KB Output is correct
22 Correct 163 ms 25080 KB Output is correct
23 Correct 144 ms 25116 KB Output is correct
24 Correct 166 ms 25208 KB Output is correct
25 Correct 153 ms 25080 KB Output is correct
26 Correct 164 ms 25076 KB Output is correct
27 Correct 162 ms 25016 KB Output is correct
28 Correct 165 ms 25080 KB Output is correct
29 Correct 154 ms 25052 KB Output is correct
30 Correct 5 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3064 KB Output is correct
2 Correct 5 ms 3068 KB Output is correct
3 Correct 4 ms 2936 KB Output is correct
4 Correct 4 ms 2780 KB Output is correct
5 Correct 5 ms 2936 KB Output is correct
6 Correct 5 ms 3064 KB Output is correct
7 Correct 4 ms 2936 KB Output is correct
8 Correct 5 ms 3064 KB Output is correct
9 Correct 4 ms 2936 KB Output is correct
10 Correct 21 ms 7160 KB Output is correct
11 Correct 17 ms 6264 KB Output is correct
12 Correct 21 ms 7096 KB Output is correct
13 Correct 17 ms 6344 KB Output is correct
14 Correct 21 ms 7032 KB Output is correct
15 Correct 22 ms 7032 KB Output is correct
16 Correct 22 ms 7032 KB Output is correct
17 Correct 15 ms 5880 KB Output is correct
18 Correct 21 ms 7032 KB Output is correct
19 Correct 15 ms 5880 KB Output is correct
20 Correct 175 ms 37080 KB Output is correct
21 Correct 189 ms 36992 KB Output is correct
22 Correct 187 ms 37116 KB Output is correct
23 Correct 172 ms 37072 KB Output is correct
24 Correct 160 ms 37112 KB Output is correct
25 Correct 188 ms 37112 KB Output is correct
26 Correct 188 ms 37112 KB Output is correct
27 Correct 170 ms 37112 KB Output is correct
28 Correct 186 ms 37056 KB Output is correct
29 Correct 161 ms 37052 KB Output is correct
30 Correct 167 ms 25052 KB Output is correct
31 Correct 162 ms 25072 KB Output is correct
32 Correct 163 ms 25080 KB Output is correct
33 Correct 144 ms 25116 KB Output is correct
34 Correct 166 ms 25208 KB Output is correct
35 Correct 153 ms 25080 KB Output is correct
36 Correct 164 ms 25076 KB Output is correct
37 Correct 162 ms 25016 KB Output is correct
38 Correct 165 ms 25080 KB Output is correct
39 Correct 154 ms 25052 KB Output is correct
40 Correct 222 ms 28576 KB Output is correct
41 Correct 557 ms 53960 KB Output is correct
42 Correct 540 ms 65996 KB Output is correct
43 Correct 577 ms 78052 KB Output is correct
44 Correct 276 ms 40312 KB Output is correct
45 Correct 298 ms 45432 KB Output is correct
46 Correct 339 ms 50552 KB Output is correct
47 Correct 413 ms 60872 KB Output is correct
48 Correct 546 ms 66040 KB Output is correct
49 Correct 548 ms 66036 KB Output is correct
50 Correct 5 ms 2808 KB Output is correct