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;
const int N = 3030;
int n, T;
int f[N][N];
bool minimize(int &u, int v){
if(u > v){
u = v;
return 1;
}
return 0;
}
int main(){
scanf("%d%d", &n, &T);
memset(f, 60, sizeof f);
f[0][0] = T;
for(int i = 0; i < n; ++i){
int U, V, D, E;
cin >> U >> V >> D >> E;
for(int j = 0; j <= n; ++j){
if(f[i][j] == f[n + 2][1]) continue;
f[i + 1][j] = min(f[i + 1][j], f[i][j] + U + V + T * (j * 2 + 1));
f[i + 1][j + 1] = min(f[i + 1][j + 1], f[i][j] + V + D + T * (j * 2 + 1));
if(j > 0){
f[i + 1][j] = min(f[i + 1][j], f[i][j] + E + D + T * (j * 2 + 1));
f[i + 1][j - 1] = min(f[i + 1][j - 1], f[i][j] + U + E + T * (j * 2 + 1));
}
}
set < pair < int, int > > heap;
for(int j = 0; j <= n; ++j){
heap.emplace(f[i + 1][j], j);
}
vector < bool > mark(n + 5, 0);
while(!heap.empty()){
int x = heap.begin() -> second;
heap.erase(heap.begin());
if(mark[x]) continue;
mark[x] = true;
if(x > 0 && minimize(f[i + 1][x - 1], f[i + 1][x] + U + E)) heap.emplace(f[i + 1][x - 1], x - 1);
if(x < n && minimize(f[i + 1][x + 1], f[i + 1][x] + V + D)) heap.emplace(f[i + 1][x + 1], x + 1);
}
}
cout << f[n][0] << endl;
return 0;
}
Compilation message (stderr)
stamps.cpp: In function 'int main()':
stamps.cpp:19:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &T);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |