This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/JOI20_treatment
#include <bits/stdc++.h>
using namespace std;
namespace std {
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Dimension must be positive");
template <typename... Args>
Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T>
struct Vec<1, T> : public vector<T> {
Vec(int n = 0, T val = T()) : std::vector<T>(n, val) {}
};
/* Example
Vec<4, int64_t> f(n, k, 2, 2); // = f[n][k][2][2];
Vec<2, int> adj(n); // graph
*/
template <class Fun>
class y_combinator_result {
Fun fun_;
public:
template <class T>
explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}
template <class... Args>
decltype(auto) operator()(Args &&...args) {
return fun_(std::ref(*this), std::forward<Args>(args)...);
}
};
template <class Fun>
decltype(auto) y_combinator(Fun &&fun) {
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}
/* Example
auto fun = y_combinator([&](auto self, int x) -> void {
self(x + 1);
});
*/
} // namespace std
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> l(m), r(m), t(m), c(m);
for (int i = 0; i < m; i++) cin >> t[i] >> l[i] >> r[i] >> c[i];
for (int i = 0; i < m; i++) l[i]--;
vector<int64_t> d(m, 1e18);
vector<int> done(m);
for (int i = 0; i < m; i++) {
if (l[i] == 0) d[i] = c[i], done[i] = 1;
}
while (true) {
int j = -1;
int64_t best = 1e18;
for (int i = 0; i < m; i++) {
if (done[i] && d[i] < best) j = i, best = d[i];
}
if (j == -1) break;
done[j] = 0;
if (r[j] == n) {
cout << best;
return 0;
}
for (int i = 0; i < m; i++) {
if (t[i] >= t[j]) {
if (l[i] <= r[j] - (t[i] - t[j])) {
if (d[i] > d[j] + c[i]) {
d[i] = d[j] + c[i];
done[i] = 1;
}
}
} else {
if (l[i] <= r[j] - (t[j] - t[i])) {
if (d[i] > d[j] + c[i]) {
d[i] = d[j] + c[i];
done[i] = 1;
}
}
}
}
}
cout << -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |