# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
125024 | 2019-07-04T11:48:39 Z | ansol4328 | 요리 강좌 (KOI17_cook) | C++11 | 5 ms | 3064 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(n,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][j],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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 5 ms | 2936 KB | Output is correct |
3 | Correct | 5 ms | 3064 KB | Output is correct |
4 | Incorrect | 4 ms | 2808 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 5 ms | 2936 KB | Output is correct |
3 | Correct | 5 ms | 3064 KB | Output is correct |
4 | Incorrect | 4 ms | 2808 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 5 ms | 2936 KB | Output is correct |
3 | Correct | 5 ms | 3064 KB | Output is correct |
4 | Incorrect | 4 ms | 2808 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 5 ms | 2936 KB | Output is correct |
3 | Correct | 5 ms | 3064 KB | Output is correct |
4 | Incorrect | 4 ms | 2808 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3064 KB | Output is correct |
2 | Correct | 5 ms | 2936 KB | Output is correct |
3 | Correct | 5 ms | 3064 KB | Output is correct |
4 | Incorrect | 4 ms | 2808 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |