Submission #915587

# Submission time Handle Problem Language Result Execution time Memory
915587 2024-01-24T08:20:46 Z vjudge1 Treatment Project (JOI20_treatment) C++17
35 / 100
3000 ms 6236 KB
// 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
1 Execution timed out 3082 ms 6236 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 108 ms 936 KB Output is correct
21 Correct 101 ms 856 KB Output is correct
22 Correct 67 ms 604 KB Output is correct
23 Correct 43 ms 600 KB Output is correct
24 Correct 9 ms 600 KB Output is correct
25 Correct 55 ms 760 KB Output is correct
26 Correct 45 ms 600 KB Output is correct
27 Correct 46 ms 764 KB Output is correct
28 Correct 11 ms 788 KB Output is correct
29 Correct 42 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 580 KB Output is correct
32 Correct 3 ms 604 KB Output is correct
33 Correct 3 ms 600 KB Output is correct
34 Correct 147 ms 752 KB Output is correct
35 Correct 3 ms 672 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 140 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3082 ms 6236 KB Time limit exceeded
2 Halted 0 ms 0 KB -