Submission #882451

#TimeUsernameProblemLanguageResultExecution timeMemory
882451MilosMilutinovicTreatment Project (JOI20_treatment)C++14
35 / 100
3039 ms44392 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> 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<vector<int>> g(m); for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { if (i == j) { continue; } if (t[i] >= t[j]) { if (l[i] <= l[j] + (t[i] - t[j]) && l[j] + (t[i] - t[j]) <= r[i]) { g[i].push_back(j); } } else { if (r[i] - (t[j] - t[i]) >= l[j] && l[j] >= l[i] - (t[j] - t[i])) { g[i].push_back(j); } } } } const long long inf = (long long) 1e18; vector<long long> dist(m, inf); set<pair<long long, int>> st; for (int i = 0; i < m; i++) { if (l[i] == 0) { dist[i] = c[i]; st.emplace(dist[i], i); } } while (!st.empty()) { auto it = st.begin(); int i = it->second; st.erase(it); for (int j : g[i]) { if (dist[j] > dist[i] + c[j]) { if (dist[j] != inf) { st.erase(st.find({dist[j], j})); } dist[j] = dist[i] + c[j]; st.emplace(dist[j], j); } } } long long res = inf; for (int i = 0; i < m; i++) { if (r[i] == n) { res = min(res, dist[i]); } } cout << (res == inf ? -1 : res) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...