# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151746 | arnold518 | 요리 강좌 (KOI17_cook) | C++14 | 6 ms | 2812 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++)
{
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});
V.push_back({DQ[j].front().first-A[j][i], j});
}
sort(V.begin(), V.end());
if(i==M+1)
{
ans=V[0].first;
break;
}
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;
}
}
}
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... |