# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
955727 | 2024-03-31T11:20:13 Z | vjudge1 | Pinball (JOI14_pinball) | C++17 | 1000 ms | 3600 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll m, n, i, j, k, a, b, w = 0, ma, r = (1LL << 50); cin >> m >> n; vector<vector<ll> > v, vv(m); vector<ll> lp, nlp, nrp, rp; vector<ll> d(m), s(3 * m); for (i = 0; i < m; i++) { cin >> j; v.push_back({j - 1, i, -1}); cin >> j; v.push_back({j - 1, i, 1}); cin >> j; v.push_back({j - 1, i, 0}); cin >> d[i]; } sort(v.begin(), v.end()); if (v[0][0] || v[3 * m - 1][0] != n - 1) { cout << -1; return 0; } for (i = 0; i < 3 * m; i++) { if (!i) s[i] = 0; else if (v[i][0] > v[i - 1][0]) s[i] = s[i - 1] + 1; else s[i] = s[i - 1]; w = max(w, s[i]); } for (i = 0; i < 3 * m; i++) v[i] = {v[i][1], s[i], v[i][2]}; sort(v.begin(), v.end()); for (i = 0; i < m; i++) vv[i] = {v[3 * i][1], v[3 * i + 1][1], v[3 * i + 2][1]}; nlp.resize(w + 1); nrp.resize(w + 1); for (i = 0; i <= w; i++) nlp[i] = nrp[i] = r; nlp[0] = nrp[w] = 0; lp = nlp; rp = nrp; ma = r; for (i = 0; i < m; i++) { for (j = vv[i][0]; j <= vv[i][2]; j++) { if (j < vv[i][1]) { nlp[vv[i][1]] = min(nlp[vv[i][1]], lp[j] + d[i]); } if (j > vv[i][1]) { nrp[vv[i][1]] = min(nrp[vv[i][1]], rp[j] + d[i]); } } for (j = 1; j <= w; j++) rp[j] = min(rp[j], rp[j - 1]); for (j = w - 1; j >= 0; j--) lp[j] = min(lp[j], lp[j + 1]); ma = min(ma, lp[vv[i][0]] + rp[vv[i][2]] + d[i]); lp = nlp; rp = nrp; } for (j = 1; j <= w; j++) rp[j] = min(rp[j], rp[j - 1]); for (j = w - 1; j >= 0; j--) lp[j] = min(lp[j], lp[j + 1]); for (j = 0; j <= w; j++) ma = min(ma, lp[j] + rp[j]); if (ma < r) cout << ma; else cout << -1; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 2 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 2 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 344 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 15 ms | 604 KB | Output is correct |
18 | Correct | 3 ms | 708 KB | Output is correct |
19 | Correct | 3 ms | 604 KB | Output is correct |
20 | Correct | 10 ms | 604 KB | Output is correct |
21 | Correct | 6 ms | 604 KB | Output is correct |
22 | Correct | 22 ms | 820 KB | Output is correct |
23 | Correct | 22 ms | 604 KB | Output is correct |
24 | Correct | 23 ms | 828 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 440 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 2 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 344 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 15 ms | 604 KB | Output is correct |
18 | Correct | 3 ms | 708 KB | Output is correct |
19 | Correct | 3 ms | 604 KB | Output is correct |
20 | Correct | 10 ms | 604 KB | Output is correct |
21 | Correct | 6 ms | 604 KB | Output is correct |
22 | Correct | 22 ms | 820 KB | Output is correct |
23 | Correct | 22 ms | 604 KB | Output is correct |
24 | Correct | 23 ms | 828 KB | Output is correct |
25 | Execution timed out | 1088 ms | 3600 KB | Time limit exceeded |
26 | Halted | 0 ms | 0 KB | - |