# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
125035 | 2019-07-04T12:21:40 Z | ansol4328 | None (KOI17_cook) | C++11 | 699 ms | 90232 KB |
#include<stdio.h> #include<deque> #include<utility> #include<algorithm> using namespace std; typedef pair<int,int> P; int n, m, s, e, t; int xy[3005][3005], lst[3005]; int dp[3005][3005], sum[3005][3005]; deque<P> dq[3005]; P mval[3005][3]; const int INF=1e9; void set_mval(int idx) { mval[idx][0]=mval[idx][1]=mval[idx][2]=P(INF,INF); for(int i=1 ; i<=n ; i++) { if(mval[idx][0].first>dp[i][idx]) { mval[idx][2]=mval[idx][1]; mval[idx][1]=mval[idx][0]; mval[idx][0]=P(dp[i][idx],i); } else if(mval[idx][1].first>dp[i][idx]) { mval[idx][2]=mval[idx][1]; mval[idx][1]=P(dp[i][idx],i); } else if(mval[idx][2].first>dp[i][idx]) { mval[idx][2]=P(dp[i][idx],i); } } } int get_mval(int idx, int t) { if(lst[t]!=mval[idx][0].second && t!=mval[idx][0].second) return mval[idx][0].first; if(lst[t]!=mval[idx][1].second && t!=mval[idx][1].second) return mval[idx][1].first; return mval[idx][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",&xy[i][j]); sum[i][j]=xy[i][j]+sum[i][j-1]; dp[i][j]=INF; if(j>=s && j<=e) dp[i][j]=sum[i][j]; } } for(int i=1 ; i<=n ; i++) scanf("%d",&lst[i]); for(int i=1 ; i<=min(m,2*s) ; i++) set_mval(i); for(int j=2*s ; j<=m ; j++) { for(int i=1 ; i<=n ; i++) { P val=P(get_mval(j-s,i)-sum[i][j-s],j-s); while(!dq[i].empty() && dq[i].back().first>val.first) dq[i].pop_back(); dq[i].push_back(val); while(!dq[i].empty() && dq[i].front().second<j-e) dq[i].pop_front(); } for(int i=1 ; i<=n ; i++) dp[i][j]=min(dp[i][j],dq[i][0].first+sum[i][j]+t); set_mval(j); } for(int j=max(s,m-s+1) ; j<m ; j++) { for(int i=1 ; i<=n ; i++) { P val=P(get_mval(j,i)-sum[i][j],j); while(!dq[i].empty() && dq[i].back().first>val.first) dq[i].pop_back(); dq[i].push_back(val); while(!dq[i].empty() && dq[i].front().second<m-e) dq[i].pop_front(); } for(int i=1 ; i<=n ; i++) dp[i][m]=min(dp[i][m],dq[i][0].first+sum[i][m]+t); } int res=INF; for(int i=1 ; i<=n ; i++) res=min(res,dp[i][m]); printf("%d",res); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3064 KB | Output is correct |
3 | Correct | 5 ms | 2936 KB | Output is correct |
4 | Correct | 4 ms | 2648 KB | Output is correct |
5 | Correct | 5 ms | 3064 KB | Output is correct |
6 | Correct | 5 ms | 3064 KB | Output is correct |
7 | Correct | 5 ms | 2936 KB | Output is correct |
8 | Correct | 5 ms | 3036 KB | Output is correct |
9 | Correct | 5 ms | 3036 KB | Output is correct |
10 | Correct | 4 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3064 KB | Output is correct |
3 | Correct | 5 ms | 2936 KB | Output is correct |
4 | Correct | 4 ms | 2648 KB | Output is correct |
5 | Correct | 5 ms | 3064 KB | Output is correct |
6 | Correct | 5 ms | 3064 KB | Output is correct |
7 | Correct | 5 ms | 2936 KB | Output is correct |
8 | Correct | 5 ms | 3036 KB | Output is correct |
9 | Correct | 5 ms | 3036 KB | Output is correct |
10 | Correct | 22 ms | 7544 KB | Output is correct |
11 | Correct | 18 ms | 7032 KB | Output is correct |
12 | Correct | 23 ms | 7544 KB | Output is correct |
13 | Correct | 18 ms | 7032 KB | Output is correct |
14 | Correct | 22 ms | 7672 KB | Output is correct |
15 | Correct | 23 ms | 7544 KB | Output is correct |
16 | Correct | 23 ms | 7544 KB | Output is correct |
17 | Correct | 15 ms | 5752 KB | Output is correct |
18 | Correct | 22 ms | 7544 KB | Output is correct |
19 | Correct | 15 ms | 5880 KB | Output is correct |
20 | Correct | 4 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3064 KB | Output is correct |
3 | Correct | 5 ms | 2936 KB | Output is correct |
4 | Correct | 4 ms | 2648 KB | Output is correct |
5 | Correct | 5 ms | 3064 KB | Output is correct |
6 | Correct | 5 ms | 3064 KB | Output is correct |
7 | Correct | 5 ms | 2936 KB | Output is correct |
8 | Correct | 5 ms | 3036 KB | Output is correct |
9 | Correct | 5 ms | 3036 KB | Output is correct |
10 | Correct | 22 ms | 7544 KB | Output is correct |
11 | Correct | 18 ms | 7032 KB | Output is correct |
12 | Correct | 23 ms | 7544 KB | Output is correct |
13 | Correct | 18 ms | 7032 KB | Output is correct |
14 | Correct | 22 ms | 7672 KB | Output is correct |
15 | Correct | 23 ms | 7544 KB | Output is correct |
16 | Correct | 23 ms | 7544 KB | Output is correct |
17 | Correct | 15 ms | 5752 KB | Output is correct |
18 | Correct | 22 ms | 7544 KB | Output is correct |
19 | Correct | 15 ms | 5880 KB | Output is correct |
20 | Correct | 212 ms | 53964 KB | Output is correct |
21 | Correct | 235 ms | 54008 KB | Output is correct |
22 | Correct | 237 ms | 54040 KB | Output is correct |
23 | Correct | 202 ms | 53980 KB | Output is correct |
24 | Correct | 178 ms | 53968 KB | Output is correct |
25 | Correct | 237 ms | 54068 KB | Output is correct |
26 | Correct | 238 ms | 54136 KB | Output is correct |
27 | Correct | 196 ms | 54008 KB | Output is correct |
28 | Correct | 229 ms | 54128 KB | Output is correct |
29 | Correct | 176 ms | 54068 KB | Output is correct |
30 | Correct | 4 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3064 KB | Output is correct |
3 | Correct | 5 ms | 2936 KB | Output is correct |
4 | Correct | 4 ms | 2648 KB | Output is correct |
5 | Correct | 5 ms | 3064 KB | Output is correct |
6 | Correct | 5 ms | 3064 KB | Output is correct |
7 | Correct | 5 ms | 2936 KB | Output is correct |
8 | Correct | 5 ms | 3036 KB | Output is correct |
9 | Correct | 5 ms | 3036 KB | Output is correct |
10 | Correct | 22 ms | 7544 KB | Output is correct |
11 | Correct | 18 ms | 7032 KB | Output is correct |
12 | Correct | 23 ms | 7544 KB | Output is correct |
13 | Correct | 18 ms | 7032 KB | Output is correct |
14 | Correct | 22 ms | 7672 KB | Output is correct |
15 | Correct | 23 ms | 7544 KB | Output is correct |
16 | Correct | 23 ms | 7544 KB | Output is correct |
17 | Correct | 15 ms | 5752 KB | Output is correct |
18 | Correct | 22 ms | 7544 KB | Output is correct |
19 | Correct | 15 ms | 5880 KB | Output is correct |
20 | Correct | 169 ms | 17844 KB | Output is correct |
21 | Correct | 164 ms | 17916 KB | Output is correct |
22 | Correct | 170 ms | 18140 KB | Output is correct |
23 | Correct | 152 ms | 17928 KB | Output is correct |
24 | Correct | 167 ms | 18000 KB | Output is correct |
25 | Correct | 155 ms | 17960 KB | Output is correct |
26 | Correct | 167 ms | 17912 KB | Output is correct |
27 | Correct | 165 ms | 17884 KB | Output is correct |
28 | Correct | 168 ms | 17972 KB | Output is correct |
29 | Correct | 156 ms | 18016 KB | Output is correct |
30 | Correct | 4 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 6 ms | 3064 KB | Output is correct |
3 | Correct | 5 ms | 2936 KB | Output is correct |
4 | Correct | 4 ms | 2648 KB | Output is correct |
5 | Correct | 5 ms | 3064 KB | Output is correct |
6 | Correct | 5 ms | 3064 KB | Output is correct |
7 | Correct | 5 ms | 2936 KB | Output is correct |
8 | Correct | 5 ms | 3036 KB | Output is correct |
9 | Correct | 5 ms | 3036 KB | Output is correct |
10 | Correct | 22 ms | 7544 KB | Output is correct |
11 | Correct | 18 ms | 7032 KB | Output is correct |
12 | Correct | 23 ms | 7544 KB | Output is correct |
13 | Correct | 18 ms | 7032 KB | Output is correct |
14 | Correct | 22 ms | 7672 KB | Output is correct |
15 | Correct | 23 ms | 7544 KB | Output is correct |
16 | Correct | 23 ms | 7544 KB | Output is correct |
17 | Correct | 15 ms | 5752 KB | Output is correct |
18 | Correct | 22 ms | 7544 KB | Output is correct |
19 | Correct | 15 ms | 5880 KB | Output is correct |
20 | Correct | 212 ms | 53964 KB | Output is correct |
21 | Correct | 235 ms | 54008 KB | Output is correct |
22 | Correct | 237 ms | 54040 KB | Output is correct |
23 | Correct | 202 ms | 53980 KB | Output is correct |
24 | Correct | 178 ms | 53968 KB | Output is correct |
25 | Correct | 237 ms | 54068 KB | Output is correct |
26 | Correct | 238 ms | 54136 KB | Output is correct |
27 | Correct | 196 ms | 54008 KB | Output is correct |
28 | Correct | 229 ms | 54128 KB | Output is correct |
29 | Correct | 176 ms | 54068 KB | Output is correct |
30 | Correct | 169 ms | 17844 KB | Output is correct |
31 | Correct | 164 ms | 17916 KB | Output is correct |
32 | Correct | 170 ms | 18140 KB | Output is correct |
33 | Correct | 152 ms | 17928 KB | Output is correct |
34 | Correct | 167 ms | 18000 KB | Output is correct |
35 | Correct | 155 ms | 17960 KB | Output is correct |
36 | Correct | 167 ms | 17912 KB | Output is correct |
37 | Correct | 165 ms | 17884 KB | Output is correct |
38 | Correct | 168 ms | 17972 KB | Output is correct |
39 | Correct | 156 ms | 18016 KB | Output is correct |
40 | Correct | 225 ms | 23068 KB | Output is correct |
41 | Correct | 617 ms | 54052 KB | Output is correct |
42 | Correct | 606 ms | 54132 KB | Output is correct |
43 | Correct | 699 ms | 90232 KB | Output is correct |
44 | Correct | 265 ms | 28280 KB | Output is correct |
45 | Correct | 312 ms | 33352 KB | Output is correct |
46 | Correct | 350 ms | 38648 KB | Output is correct |
47 | Correct | 421 ms | 48792 KB | Output is correct |
48 | Correct | 617 ms | 54096 KB | Output is correct |
49 | Correct | 670 ms | 54008 KB | Output is correct |
50 | Correct | 4 ms | 2680 KB | Output is correct |