#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
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
0 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
876 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
876 KB |
Output is correct |
4 |
Correct |
1 ms |
476 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
620 KB |
Output is correct |
7 |
Correct |
1 ms |
876 KB |
Output is correct |
8 |
Correct |
1 ms |
876 KB |
Output is correct |
9 |
Correct |
1 ms |
876 KB |
Output is correct |
10 |
Correct |
1 ms |
896 KB |
Output is correct |
11 |
Correct |
1 ms |
876 KB |
Output is correct |
12 |
Correct |
1 ms |
876 KB |
Output is correct |
13 |
Correct |
1 ms |
876 KB |
Output is correct |
14 |
Correct |
1 ms |
876 KB |
Output is correct |
15 |
Correct |
1 ms |
876 KB |
Output is correct |
16 |
Correct |
1 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
71148 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
101 ms |
71332 KB |
Output is correct |
4 |
Correct |
84 ms |
62956 KB |
Output is correct |
5 |
Correct |
67 ms |
52204 KB |
Output is correct |
6 |
Correct |
29 ms |
24428 KB |
Output is correct |
7 |
Correct |
18 ms |
15468 KB |
Output is correct |
8 |
Correct |
101 ms |
71252 KB |
Output is correct |
9 |
Correct |
109 ms |
71148 KB |
Output is correct |
10 |
Correct |
102 ms |
71276 KB |
Output is correct |
11 |
Correct |
100 ms |
71276 KB |
Output is correct |
12 |
Correct |
101 ms |
71276 KB |
Output is correct |
13 |
Correct |
101 ms |
71276 KB |
Output is correct |
14 |
Correct |
101 ms |
71312 KB |
Output is correct |
15 |
Correct |
100 ms |
71276 KB |
Output is correct |
16 |
Correct |
100 ms |
71276 KB |
Output is correct |
17 |
Correct |
102 ms |
71420 KB |
Output is correct |