이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E){
int N = W.size(), q = E.size();
vector<tuple<int, int, int> > items;
vector<ll> ans;
for(int i = 0; i < N; ++i) items.push_back(make_tuple(W[i], A[i], B[i]));
sort(items.begin(), items.end());
sort(items.begin(), items.end());
for (int i = 0; i < N; ++i) {
auto [w, a, b] = items[i];
W[i] = w, A[i] = a, B[i] = b;
}
for(int i = 0; i < q; ++i){
int d = E[i];
vector<ll> dp(N + 1, LLONG_MAX);
for(int i = 0; i < N; ++i){
if(i == 0) dp[i] = (ll)A[i];
else if(i == 1){
if(W[i] - W[i - 1] <= d) dp[i] = (ll)B[i] + (ll)B[i - 1];
else dp[i] = dp[i - 1] + (ll)A[i];
}
else{
dp[i] = dp[i - 1] + (ll)A[i];
if(W[i] - W[i - 1] <= d) dp[i] = min(dp[i], (ll)((ll)B[i] + (ll)B[i - 1] + dp[i - 2]));
if(W[i] - W[i - 2] <= d){
if(i >= 3) dp[i] = min(dp[i], (ll)((ll)B[i] + (ll)A[i - 1] + (ll)B[i - 2] + dp[i - 3]));
else dp[i] = min(dp[i], (ll)((ll)B[i] + (ll)A[i - 1] + (ll)B[i - 2]));
}
}
}
ans.push_back(dp[N - 1]);
}
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |