# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151749 | arnold518 | 요리 강좌 (KOI17_cook) | C++14 | 766 ms | 50516 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 3000;
int N, M, S, E, T, A[MAXN+10][MAXN+10], B[MAXN+10];
int dp[MAXN+10][MAXN+10], ans=2147483647;
deque<pii> DQ[MAXN+10];
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++) for(j=M; j>=0; j--) A[i][j]+=A[i][j+1];
for(i=1; i<=N; i++) scanf("%d", &B[i]);
for(i=2; i<=S; i++) for(j=1; j<=N; j++) dp[j][i]=11e7;
for(i=S+1; i<=M+1; i++)
{
priority_queue<pii> PQ;
vector<pii> V;
for(j=1; j<=N; j++)
{
while(!DQ[j].empty() && DQ[j].front().second<i-E) DQ[j].pop_front();
while(!DQ[j].empty() && DQ[j].back().first>=A[j][i-S]+dp[j][i-S]) DQ[j].pop_back();
DQ[j].push_back({dp[j][i-S]+A[j][i-S], i-S});
PQ.push({DQ[j].front().first-A[j][i], j});
while(PQ.size()>3) PQ.pop();
}
while(!PQ.empty()) V.push_back(PQ.top()), PQ.pop();
sort(V.begin(), V.end());
for(j=1; j<=N; j++)
{
for(auto it : V)
{
if(it.second==j || it.second==B[j]) continue;
dp[j][i]=it.first+T;
break;
}
}
}
for(i=M-E+1; i<=M; i++) for(j=1; j<=N; j++) ans=min(ans, dp[j][i]+A[j][i]);
printf("%d", ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |