# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
101232 | 2019-03-18T01:43:50 Z | knon0501 | 요리 강좌 (KOI17_cook) | C++14 | 674 ms | 77632 KB |
#include <bits/stdc++.h> using namespace std; #define f first #define s second int n,m; int s,e,t; pair<int,int> dm[3005][3]; int d[3005][3005]; deque<pair<int,int>> deq[3005]; int ss[3005][3005]; int b[3005]; int a[3005][3005]; int main(){ int i,j; scanf("%d %d %d %d %d",&n,&m,&s,&e,&t); for(i=1 ; i<=n ; i++)for(j=1 ; j<=m ; j++)scanf("%d",&a[i][j]); for(i=1 ; i<=n ; i++)scanf("%d",&b[i]); for(i=1 ; i<=n ; i++)for(j=1 ; j<=m ; j++)ss[i][j]=ss[i][j-1]+a[i][j]; for(i=1 ; i<=n ; i++)deq[i].push_front(make_pair(-t,0)); for(i=1 ; i<=m ; i++)for(j=0 ; j<3 ; j++)dm[i][j].f=2e9; for(i=s ;i<=m ; i++){ for(j=1 ; j<=n ; j++){ while(deq[j].front().s<i-e){ deq[j].pop_front(); } /// if(deq[j].empty())printf("!!!!!!!"); d[i][j]=deq[j].front().f+ss[j][i]+t; /// printf("%d %d : %d %d %d %d \n",i,j,d[i][j],deq[j].front().f,deq[j].front().s,ss[j][i]); if(dm[i][0].f>=d[i][j]){ dm[i][2]=dm[i][1]; dm[i][1]=dm[i][0]; dm[i][0].f=d[i][j]; dm[i][0].s=j; } else if(dm[i][1].f>=d[i][j]){ dm[i][2]=dm[i][1]; dm[i][1].f=d[i][j]; dm[i][1].s=j; } else if(dm[i][2].f>=d[i][j]){ dm[i][2].f=d[i][j]; dm[i][2].s=j; } } if(i-s<0)continue; for(j=1 ; j<=n ; j++){ pair<int,int> v; if(dm[i-s+1][0].s!=j && dm[i-s+1][0].s!=b[j]){ v=dm[i-s+1][0]; } else if(dm[i-s+1][1].s!=j && dm[i-s+1][1].s!=b[j]){ v=dm[i-s+1][1]; } else{ v=dm[i-s+1][2]; } v.f-=ss[j][i-s+1]; v.s=i-s+1; /// if(i==4 &&j==2)printf("%d %d\n",v.f,ss[j][i-s+1]); if(deq[j].empty() || deq[j].front().f>=v.f){ deq[j].push_front(v); } else{ while(!deq[j].empty() && deq[j].back().f>=v.f){ deq[j].pop_back(); } deq[j].push_back(v); } } } int ans=2e9; for(i=1 ; i<=n ; i++)ans=min(ans,d[m][i]); for(i=m-s+1 ; i<m ;i++){ for(j=1 ; j<=n ; j++){ if(j!=dm[i][0].s &&b[j]!=dm[i][0].s){ ans=min(ans,t+dm[i][0].f+ss[j][m]-ss[j][i]); } else if(j!=dm[i][1].s && b[j]!=dm[i][1].s){ ans=min(ans,t+dm[i][1].f+ss[j][m]-ss[j][i]); } else{ ans=min(ans,t+dm[i][2].f+ss[j][m]-ss[j][i]); } } } cout<<ans; /// cout<<d[5][3]<<endl<<dm[3][0].f<<endl<<dm[3][1].f<<endl<<dm[3][2].f<<endl<<d[3][1]<<ss[1][3]; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3072 KB | Output is correct |
2 | Correct | 5 ms | 2944 KB | Output is correct |
3 | Correct | 5 ms | 2944 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 5 ms | 3044 KB | Output is correct |
6 | Correct | 6 ms | 2944 KB | Output is correct |
7 | Correct | 5 ms | 2944 KB | Output is correct |
8 | Correct | 15 ms | 2944 KB | Output is correct |
9 | Correct | 5 ms | 2816 KB | Output is correct |
10 | Correct | 5 ms | 2944 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3072 KB | Output is correct |
2 | Correct | 5 ms | 2944 KB | Output is correct |
3 | Correct | 5 ms | 2944 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 5 ms | 3044 KB | Output is correct |
6 | Correct | 6 ms | 2944 KB | Output is correct |
7 | Correct | 5 ms | 2944 KB | Output is correct |
8 | Correct | 15 ms | 2944 KB | Output is correct |
9 | Correct | 5 ms | 2816 KB | Output is correct |
10 | Correct | 22 ms | 7040 KB | Output is correct |
11 | Correct | 17 ms | 6796 KB | Output is correct |
12 | Correct | 28 ms | 7672 KB | Output is correct |
13 | Correct | 17 ms | 6784 KB | Output is correct |
14 | Correct | 18 ms | 6628 KB | Output is correct |
15 | Correct | 18 ms | 7140 KB | Output is correct |
16 | Correct | 24 ms | 7524 KB | Output is correct |
17 | Correct | 21 ms | 4992 KB | Output is correct |
18 | Correct | 33 ms | 7048 KB | Output is correct |
19 | Correct | 14 ms | 4992 KB | Output is correct |
20 | Correct | 5 ms | 2944 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3072 KB | Output is correct |
2 | Correct | 5 ms | 2944 KB | Output is correct |
3 | Correct | 5 ms | 2944 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 5 ms | 3044 KB | Output is correct |
6 | Correct | 6 ms | 2944 KB | Output is correct |
7 | Correct | 5 ms | 2944 KB | Output is correct |
8 | Correct | 15 ms | 2944 KB | Output is correct |
9 | Correct | 5 ms | 2816 KB | Output is correct |
10 | Correct | 22 ms | 7040 KB | Output is correct |
11 | Correct | 17 ms | 6796 KB | Output is correct |
12 | Correct | 28 ms | 7672 KB | Output is correct |
13 | Correct | 17 ms | 6784 KB | Output is correct |
14 | Correct | 18 ms | 6628 KB | Output is correct |
15 | Correct | 18 ms | 7140 KB | Output is correct |
16 | Correct | 24 ms | 7524 KB | Output is correct |
17 | Correct | 21 ms | 4992 KB | Output is correct |
18 | Correct | 33 ms | 7048 KB | Output is correct |
19 | Correct | 14 ms | 4992 KB | Output is correct |
20 | Correct | 190 ms | 45048 KB | Output is correct |
21 | Correct | 193 ms | 43504 KB | Output is correct |
22 | Correct | 182 ms | 43508 KB | Output is correct |
23 | Correct | 204 ms | 41580 KB | Output is correct |
24 | Correct | 175 ms | 40172 KB | Output is correct |
25 | Correct | 207 ms | 43112 KB | Output is correct |
26 | Correct | 196 ms | 43316 KB | Output is correct |
27 | Correct | 197 ms | 42732 KB | Output is correct |
28 | Correct | 219 ms | 42744 KB | Output is correct |
29 | Correct | 181 ms | 40144 KB | Output is correct |
30 | Correct | 5 ms | 2944 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3072 KB | Output is correct |
2 | Correct | 5 ms | 2944 KB | Output is correct |
3 | Correct | 5 ms | 2944 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 5 ms | 3044 KB | Output is correct |
6 | Correct | 6 ms | 2944 KB | Output is correct |
7 | Correct | 5 ms | 2944 KB | Output is correct |
8 | Correct | 15 ms | 2944 KB | Output is correct |
9 | Correct | 5 ms | 2816 KB | Output is correct |
10 | Correct | 22 ms | 7040 KB | Output is correct |
11 | Correct | 17 ms | 6796 KB | Output is correct |
12 | Correct | 28 ms | 7672 KB | Output is correct |
13 | Correct | 17 ms | 6784 KB | Output is correct |
14 | Correct | 18 ms | 6628 KB | Output is correct |
15 | Correct | 18 ms | 7140 KB | Output is correct |
16 | Correct | 24 ms | 7524 KB | Output is correct |
17 | Correct | 21 ms | 4992 KB | Output is correct |
18 | Correct | 33 ms | 7048 KB | Output is correct |
19 | Correct | 14 ms | 4992 KB | Output is correct |
20 | Correct | 160 ms | 29808 KB | Output is correct |
21 | Correct | 176 ms | 27816 KB | Output is correct |
22 | Correct | 165 ms | 30192 KB | Output is correct |
23 | Correct | 155 ms | 14600 KB | Output is correct |
24 | Correct | 166 ms | 30188 KB | Output is correct |
25 | Correct | 187 ms | 26460 KB | Output is correct |
26 | Correct | 180 ms | 30032 KB | Output is correct |
27 | Correct | 173 ms | 30152 KB | Output is correct |
28 | Correct | 168 ms | 29440 KB | Output is correct |
29 | Correct | 176 ms | 25052 KB | Output is correct |
30 | Correct | 5 ms | 2944 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3072 KB | Output is correct |
2 | Correct | 5 ms | 2944 KB | Output is correct |
3 | Correct | 5 ms | 2944 KB | Output is correct |
4 | Correct | 4 ms | 2688 KB | Output is correct |
5 | Correct | 5 ms | 3044 KB | Output is correct |
6 | Correct | 6 ms | 2944 KB | Output is correct |
7 | Correct | 5 ms | 2944 KB | Output is correct |
8 | Correct | 15 ms | 2944 KB | Output is correct |
9 | Correct | 5 ms | 2816 KB | Output is correct |
10 | Correct | 22 ms | 7040 KB | Output is correct |
11 | Correct | 17 ms | 6796 KB | Output is correct |
12 | Correct | 28 ms | 7672 KB | Output is correct |
13 | Correct | 17 ms | 6784 KB | Output is correct |
14 | Correct | 18 ms | 6628 KB | Output is correct |
15 | Correct | 18 ms | 7140 KB | Output is correct |
16 | Correct | 24 ms | 7524 KB | Output is correct |
17 | Correct | 21 ms | 4992 KB | Output is correct |
18 | Correct | 33 ms | 7048 KB | Output is correct |
19 | Correct | 14 ms | 4992 KB | Output is correct |
20 | Correct | 190 ms | 45048 KB | Output is correct |
21 | Correct | 193 ms | 43504 KB | Output is correct |
22 | Correct | 182 ms | 43508 KB | Output is correct |
23 | Correct | 204 ms | 41580 KB | Output is correct |
24 | Correct | 175 ms | 40172 KB | Output is correct |
25 | Correct | 207 ms | 43112 KB | Output is correct |
26 | Correct | 196 ms | 43316 KB | Output is correct |
27 | Correct | 197 ms | 42732 KB | Output is correct |
28 | Correct | 219 ms | 42744 KB | Output is correct |
29 | Correct | 181 ms | 40144 KB | Output is correct |
30 | Correct | 160 ms | 29808 KB | Output is correct |
31 | Correct | 176 ms | 27816 KB | Output is correct |
32 | Correct | 165 ms | 30192 KB | Output is correct |
33 | Correct | 155 ms | 14600 KB | Output is correct |
34 | Correct | 166 ms | 30188 KB | Output is correct |
35 | Correct | 187 ms | 26460 KB | Output is correct |
36 | Correct | 180 ms | 30032 KB | Output is correct |
37 | Correct | 173 ms | 30152 KB | Output is correct |
38 | Correct | 168 ms | 29440 KB | Output is correct |
39 | Correct | 176 ms | 25052 KB | Output is correct |
40 | Correct | 264 ms | 35308 KB | Output is correct |
41 | Correct | 601 ms | 66440 KB | Output is correct |
42 | Correct | 528 ms | 66396 KB | Output is correct |
43 | Correct | 674 ms | 77632 KB | Output is correct |
44 | Correct | 303 ms | 38000 KB | Output is correct |
45 | Correct | 263 ms | 35524 KB | Output is correct |
46 | Correct | 303 ms | 43152 KB | Output is correct |
47 | Correct | 368 ms | 38888 KB | Output is correct |
48 | Correct | 512 ms | 66288 KB | Output is correct |
49 | Correct | 532 ms | 65244 KB | Output is correct |
50 | Correct | 5 ms | 2944 KB | Output is correct |