# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1110864 | salmon | Ski 2 (JOI24_ski2) | C++14 | 664 ms | 665672 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;
int N, K, H;
long long int memo[400][400][400];
vector<pair<int,int>> v;
int h,h1;
vector<int> vh;
int cost[400];
const int inf = 1.1e9;
int sise[400];
int main(){
scanf(" %d",&N);
scanf(" %d",&K);
for(int i = 0; i < N; i++){
scanf(" %d",&h);
scanf(" %d",&h1);
v.push_back({h,h1});
}
sort(v.begin(),v.end());
int p = -1;
for(int i = 0; i < N; i++){
if(v[i].first <= p){
p++;
vh.push_back(p);
}
else{
p = v[i].first;
vh.push_back(p);
}
}
H = vh.size();
cost[0] = inf;
sise[0] = 0;
auto it = 0;
for(int i = 0; i < N; i++){
while(vh[it] != v[i].first){
it++;
cost[it] = cost[it - 1];
sise[it] = 0;
}
cost[it] = min(cost[it], v[i].second);
sise[it]++;
}
while(it != H - 1){
it++;
cost[it] = cost[it - 1];
sise[it] = 0;
}
for(int i = 0; i < H; i++){
for(int j = 0; j <= N; j++){
for(int k = 0; k <= N; k++){
memo[i][j][k] = -1;
}
}
}
for(int i = H - 1; i >= 0; i--){
if(i != H - 1){
}
long long int pre[N + 1][N + 1];
if(i != 0 && i != H - 1){
for(int j = 0; j <= N; j++){
for(int k = 0; k <= N; k++){
pre[j][k] = memo[i + 1][j][k] + j * (long long int)K;
}
}
for(int j = 1; j <= N; j++){
for(int k = 0; k <= N; k++){
if(k != N) pre[j][k] = min(pre[j - 1][k + 1] + cost[i - 1], pre[j][k]);
}
}
}
for(int j = 0; j <= N; j++){
for(int k = 1; k <= N; k++){
if(i == H - 1){
memo[i][j][k] = max(0,(j + sise[i] - k)) * (long long int)cost[i - 1];
}
else if(i == 0){
int num = max(0, j + sise[i] - k);
memo[i][j][k] = inf * (long long int)inf;
if(memo[i + 1][num][k] != -1){
memo[i][j][k] = min(memo[i][j][k], memo[i + 1][num][k] + num * (long long int)K);
}
}
else{
int num = max(0, j + sise[i] - k);
memo[i][j][k] = pre[num][k];
}
//printf("%d ",memo[i][j][k]);
}
//printf("\n");
}
//printf("\n");
//printf("\n");
//printf("\n");
}
printf("%lld",memo[0][0][1]);
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |