제출 #220262

#제출 시각아이디문제언어결과실행 시간메모리
220262fedoseevtimofey치료 계획 (JOI20_treatment)C++14
35 / 100
2182 ms524292 KiB
#include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <random> #include <iomanip> #include <functional> #include <cassert> using namespace std; typedef long long ll; const ll Inf = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, m; cin >> n >> m; vector <int> t(m + 1), l(m + 1), r(m + 1), c(m + 2); for (int i = 1; i <= m; ++i) { cin >> t[i] >> l[i] >> r[i] >> c[i]; --l[i]; } vector <vector <int>> g(m + 2); for (int i = 1; i <= m; ++i) { if (l[i] == 0) { g[0].push_back(i); } if (r[i] == n) { g[i].push_back(m + 1); } } for (int i = 1; i <= m; ++i) { for (int j = 1; j <= m; ++j) { if (i == j) continue; int tm = abs(t[i] - t[j]); if (r[i] - tm >= l[j]) { g[i].push_back(j); } } } vector <ll> d(m + 2, Inf); d[0] = 0; vector <int> used(m + 2); while (true) { int id = -1; for (int u = 0; u < m + 2; ++u) { if (!used[u] && (id == -1 || d[u] < d[id])) { id = u; } } if (id == -1) break; used[id] = 1; if (d[id] != Inf) { d[id] += c[id]; for (auto v : g[id]) { if (d[v] > d[id]) { d[v] = d[id]; } } } } if (d[m + 1] == Inf) { cout << "-1\n"; } else { cout << d[m + 1] << '\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...