#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"
using ll = long long;
using ld = long double;
template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}
const int N = 3e3 + 5, INF = 1e15;
int n, T, U[N], V[N], E[N], D[N];
ll dp[N][N];
void Main()
{
cin >> n >> T;
FOR(i, 1, n){
cin >> U[i] >> V[i] >> D[i] >> E[i];
}
FOR(i, 0, n) FOR(j, 0, n + 1) dp[i][j] = INF;
dp[0][0] = 0;
FOR(i, 1, n){
FOR(j, 0, n + 1){
dp[i][j] = min(dp[i][j], dp[i - 1][j] + (U[i] + V[i]) + T * (2 * j + 1));
if(j) dp[i][j] = min(dp[i][j], dp[i - 1][j] + (D[i] + E[i]) + T * (2 * j + 1));
}
ll best = dp[i - 1][n + 1] + (U[i] + E[i]) * (n + 1) + T * (2 * (n + 1) + 1);
ROF(j, n, 0){
dp[i][j] = min(dp[i][j], best - (U[i] + E[i]) * j);
best = min(best, dp[i - 1][j] + (U[i] + E[i]) * j + T * (2 * j + 1));
}
best = dp[i - 1][0] + T;
FOR(j, 1, n){
dp[i][j] = min(dp[i][j], best + (V[i] + D[i]) * j);
best = min(best, dp[i - 1][j] - (V[i] + D[i]) * j + T * (2 * j + 1));
}
}
cout << dp[n][0] + T << el;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
int t = 1; while(t--) Main();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
stamps.cpp:32:30: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
32 | const int N = 3e3 + 5, INF = 1e15;
| ^~~~
stamps.cpp: In function 'int32_t main()':
stamps.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(name".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stamps.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(name".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... |