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>
#define ll long long
#define pb push_back
#define task "talltree"
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define fi first
#define se second
#define ull unsigned long long
using namespace std;
const ll mod = 1e15+7;
const ll N = 3005;
vector<pll> adj[N];
vector<ll> kq;
ll n, m, t, k, b[N], lab[N], u, v, h[N], a[N], ans, tong, dp[N][N];
priority_queue< pii, vector<pii>, greater<pii> > pq;
struct
{
ll u, v, d, e, gor, gol, str, stl;
}p[N];
void sol()
{
cin >> n >> t;
for(int i = 0; i < n; i ++)
{
cin >> p[i].u >> p[i].v >> p[i].d >> p[i].e;
p[i].gor = p[i].u + p[i].e;
p[i].gol = p[i].v + p[i].d;
p[i].str = p[i].u + p[i].v;
p[i].stl = p[i].d + p[i].e;
}
for(int i = 0; i <= n; i ++)for(int j = 0; j <= n+1; j ++)dp[i][j] = mod;
dp[0][0] = 0;
for(int i = 0; i < n; i ++)
{
for(int j = 0; j <= n; j ++)
{
if(j > 0)dp[i][j] = min(dp[i][j], dp[i][j-1] + p[i].gol - 2 * t * i);
dp[i+1][j] = min(dp[i+1][j], dp[i][j] + p[i].str);
if(j > 0)dp[i+1][j] = min(dp[i+1][j], dp[i][j] + p[i].stl);
dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + p[i].gol - 2 * t * i);
if(j > 0)dp[i+1][j-1] = min(dp[i+1][j-1], dp[i][j] + p[i].gor + 2 * i * t);
}
}
cout << t * (n+1) + dp[n][0];
}
int main()
{
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message (stderr)
stamps.cpp: In function 'int main()':
stamps.cpp:50:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
50 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stamps.cpp:51:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
51 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |