Submission #898592

#TimeUsernameProblemLanguageResultExecution timeMemory
898592boxTreatment Project (JOI20_treatment)C++17
35 / 100
3051 ms2652 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
template <class T, class... U> void bug_h(const T& t, const U&... u) { cerr << t; ((cerr << " | " << u), ...); cerr << endl; }
#define bug(...) cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: ", bug_h(__VA_ARGS__)
#else
#define cerr if (0) cerr
#define bug(...)
#endif

#define ar array
#define all(v) std::begin(v), std::end(v)
#define sz(v) int(std::size(v))
typedef long long i64;
typedef vector<int> vi;
typedef pair<int, int> pi;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N, M;
    cin >> N >> M;
    vi T(M), L(M), R(M), C(M);
    for (int i = 0; i < M; i++) cin >> T[i] >> L[i] >> R[i] >> C[i], L[i]--;
    vector<i64> dist(M, -1);
    typedef pair<i64, int> U;
    priority_queue<U, vector<U>, greater<U>> pq;
    for (int i = 0; i < M; i++) if (L[i] == 0) pq.push({dist[i] = C[i], i});
    while (sz(pq)) {
        auto [d, i] = pq.top(); pq.pop();
        for (int j = 0; j < M; j++) if (dist[j] == -1) {
            if (T[i] <= T[j] && L[j] + T[j] <= R[i] + T[i])
                pq.push({dist[j] = dist[i] + C[j], j});
            if (T[j] < T[i] && R[i] - T[i] >= L[j] - T[j])
                pq.push({dist[j] = dist[i] + C[j], j});
        }
    }
    i64 ans = LLONG_MAX;
    for (int i = 0; i < M; i++) if (~dist[i] && R[i] == N)
        ans = min(ans, dist[i]);
    cout << (ans == LLONG_MAX ? -1 : ans) << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...