結果
| 問題 |
No.1037 exhausted
|
| コンテスト | |
| ユーザー |
sykwer
|
| 提出日時 | 2020-04-25 00:35:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,585 bytes |
| コンパイル時間 | 1,153 ms |
| コンパイル使用メモリ | 122,028 KB |
| 実行使用メモリ | 45,696 KB |
| 最終ジャッジ日時 | 2024-10-15 04:03:23 |
| 合計ジャッジ時間 | 4,777 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 TLE * 1 -- * 10 |
ソースコード
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>
// type
#include <cstdint>
#include <functional>
/* ---------- Namespace ---------- */
using namespace std;
/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>
/* ---------- Constants */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int N, V, L;
cin >> N >> V >> L;
vector<int> x(N+2);
vector<int> f(N+2);
vector<int> w(N+2);
for (int i = 1; i <= N ;i++) cin >> x[i] >> f[i] >> w[i];
x[0] = 0;
f[0] = 0;
w[0] = 0;
x[N+1] = L;
f[N+1] = 0;
w[N+1] = 0;
vector<unordered_map<int, int>> dp(N+2); // <remain fuel, total cost>
dp[0][V] = 0;
for (int i = 0; i <= N; i++) {
for (auto it = dp[i].begin(); it != dp[i].end(); it++) {
int v = it->first;
int costs = it->second;
for (int j = i + 1; j <= N + 1; j++) {
if (v - (x[j] - x[i]) < 0) break;
int vv = min(V, v - (x[j] - x[i]) + f[j]);
if (dp[j].find(vv) == dp[j].end()) dp[j][vv] = INF;
chmin(dp[j][vv], costs + w[j]);
}
}
}
/*
for (int i = 0; i <= N+1; i++) {
for (auto it = dp[i].begin(); it != dp[i].end(); it++) {
cout << "(" << it->first << "," << it->second << ") ";
}
cout << endl;
}
*/
int ret = INF;
for (auto it = dp[N+1].begin(); it != dp[N+1].end(); it++) {
ret = min(ret, it->second);
}
if (ret == INF) ret = -1;
cout << ret << endl;
return 0;
}
sykwer