# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1094370 | 2024-09-29T13:15:16 Z | thangdz2k7 | Treatment Project (JOI20_treatment) | C++17 | 3000 ms | 7348 KB |
// author : thembululquaUwU // 3.9.2024 #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define endl '\n' using namespace std; using ll = long long; using ii = pair <int, int>; using li = pair <ll, int>; using vi = vector <int>; const int N = 1e5 + 5; const int mod = 1e9 + 7; const ll inf = 1e18; void maxl(auto &a, auto b) {a = max(a, b);} void minl(auto &a, auto b) {a = min(a, b);} struct project{ int t, l, r, c; bool operator < (project other){ return l - t < other.l - other.t; } } p[N]; int NN, m, Min[4 * N]; ll d[N]; void build(int s = 1, int l = 1, int r = m){ if (l == r){ Min[s] = p[l].l + p[l].t; return; } int mid = l + r >> 1; build(s << 1, l, mid); build(s << 1 | 1, mid + 1, r); Min[s] = min(Min[s << 1], Min[s << 1 | 1]); } priority_queue <li, vector <li>, greater <li>> qu; void get(int u, int v, ll k, int s = 1, int l = 1, int r = m){ if (p[l].l - p[l].t > u || Min[s] > v) return; if (l == r){ if (d[l] == inf){ d[l] = k + p[l].c; qu.push({d[l], l}); } Min[s] = inf; return; } int mid = l + r >> 1; get(u, v, k, s << 1, l, mid); get(u, v, k, s << 1 | 1, mid + 1, r); Min[s] = min(Min[s << 1], Min[s << 1 | 1]); } void solve(){ cin >> NN >> m; for (int i = 1; i <= m; ++ i){ cin >> p[i].t >> p[i].l >> p[i].r >> p[i].c; d[i] = inf; } sort(p + 1, p + m + 1); build(); for (int i = 1; i <= m; ++ i) if (p[i].l == 1){ d[i] = p[i].c; qu.push({d[i], i}); } while (qu.size()){ auto [du, u] = qu.top(); qu.pop(); get(p[u].r - p[u].t + 1, p[u].r + p[u].t + 1, du); } ll ans = inf; for (int i = 1; i <= m; ++ i) if (p[i].r == NN) minl(ans, d[i]); if (ans == inf) cout << -1; else cout << ans; } int main(){ if (fopen("pqh.inp", "r")){ freopen("pqh.inp", "r", stdin); freopen("pqh.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t --) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3065 ms | 7348 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2392 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 0 ms | 2396 KB | Output is correct |
7 | Correct | 0 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2396 KB | Output is correct |
9 | Correct | 0 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2392 KB | Output is correct |
13 | Correct | 1 ms | 2396 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 1 ms | 2396 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 1 ms | 2392 KB | Output is correct |
18 | Correct | 1 ms | 2396 KB | Output is correct |
19 | Correct | 0 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Correct | 1 ms | 2392 KB | Output is correct |
5 | Correct | 0 ms | 2396 KB | Output is correct |
6 | Correct | 0 ms | 2396 KB | Output is correct |
7 | Correct | 0 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2396 KB | Output is correct |
9 | Correct | 0 ms | 2396 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 0 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2392 KB | Output is correct |
13 | Correct | 1 ms | 2396 KB | Output is correct |
14 | Correct | 0 ms | 2396 KB | Output is correct |
15 | Correct | 1 ms | 2396 KB | Output is correct |
16 | Correct | 0 ms | 2396 KB | Output is correct |
17 | Correct | 1 ms | 2392 KB | Output is correct |
18 | Correct | 1 ms | 2396 KB | Output is correct |
19 | Correct | 0 ms | 2396 KB | Output is correct |
20 | Correct | 131 ms | 2652 KB | Output is correct |
21 | Correct | 134 ms | 2832 KB | Output is correct |
22 | Correct | 74 ms | 2652 KB | Output is correct |
23 | Correct | 41 ms | 2648 KB | Output is correct |
24 | Correct | 127 ms | 2932 KB | Output is correct |
25 | Correct | 99 ms | 2652 KB | Output is correct |
26 | Correct | 94 ms | 2648 KB | Output is correct |
27 | Correct | 92 ms | 2652 KB | Output is correct |
28 | Correct | 128 ms | 2908 KB | Output is correct |
29 | Correct | 75 ms | 2652 KB | Output is correct |
30 | Correct | 2 ms | 2648 KB | Output is correct |
31 | Correct | 2 ms | 2644 KB | Output is correct |
32 | Correct | 150 ms | 2908 KB | Output is correct |
33 | Correct | 182 ms | 2908 KB | Output is correct |
34 | Correct | 106 ms | 2652 KB | Output is correct |
35 | Correct | 152 ms | 2908 KB | Output is correct |
36 | Correct | 172 ms | 2900 KB | Output is correct |
37 | Correct | 111 ms | 2648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3065 ms | 7348 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |