# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
581509 |
2022-06-22T17:16:33 Z |
Vanilla |
Pinball (JOI14_pinball) |
C++17 |
|
13 ms |
19028 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 1e5 + 2;
int64 a[maxn], b[maxn], c[maxn], cost[maxn];
vector <int64> coord;
int64 l[12 * maxn];// l[i] -> min cost sa ajungi in device i incepand de pe coloana 1
int64 r[12 * maxn];// r[i] -> min cost sa ajungi in device i incepand de pe coloana m
int64 query (int x, int l, int r, int il, int ir, int64 sgt[]) {
if (il <= l && r <= ir) return sgt[x];
if (l > ir || r < il) return 1e18;
int mid = (l + r) / 2;
return min(query(2 * x, l, mid, il, ir, sgt), query(2 * x + 1, mid + 1, r, il, ir, sgt));
}
int64 update (int x, int l, int r, int pos, int64 val, int64 sgt[]) {
if (l == pos && r == pos) return sgt[x] = min(val, sgt[x]);
if (l > pos || r < pos) return 1e18;
int mid = (l + r) / 2;
return sgt[x] = min(update(2 * x, l, mid, pos, val, sgt), update(2 * x + 1, mid + 1, r, pos, val, sgt));
}
int main() {
int64 n,m;
cin >> n >> m;
bool f1 = 0, f2 = 0;
for (int i = 0; i < 12 * maxn; i++){
l[i] = r[i] = 1e18;
}
for (int i = 0; i < n; i++){
cin >> a[i] >> b[i] >> c[i] >> cost[i];
if (a[i] == 1) f1 = 1;
if (b[i] == m) f2 = 1;
coord.push_back(a[i]);
coord.push_back(b[i]);
coord.push_back(c[i]);
}
if (!f1 || !f2){
cout << -1;
return 0;
}
sort(coord.begin(), coord.end());
m = 0;
for (int i = 0; i < n; i++){
a[i] = lower_bound(coord.begin(), coord.end(), a[i]) - coord.begin();
b[i] = lower_bound(coord.begin(), coord.end(), b[i]) - coord.begin();
c[i] = lower_bound(coord.begin(), coord.end(), c[i]) - coord.begin();
m = max(m, b[i]);
// cout << a[i] << " " << b[i] << " " << c[i] << "\n";
}
int64 rs = 1e18;
for (int i = 0; i < n; i++){
rs = min(rs, query(1, 0, 3 * n, a[i], b[i], l) + query(1, 0, 3 * n, a[i], b[i], r) + cost[i]);
if (a[i] == 0) {
update(1, 0, 3 * n, c[i], cost[i], l);
rs = min(rs, query(1, 0, 3 * n, a[i], b[i], r) + cost[i]);
}
else update(1, 0, 3 * n, c[i], query(1, 0, 3 * n, a[i], b[i], l) + cost[i], l);
if (b[i] == m) {
update(1, 0, 3 * n, c[i], cost[i], r);
rs = min(rs, query(1, 0, 3 * n, a[i], b[i], l) + cost[i]);
}
else update(1, 0, 3 * n, c[i], query(1, 0, 3 * n, a[i], b[i], r) + cost[i], r);
}
cout << (rs >= 1e15 ? -1: rs);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
9 ms |
19028 KB |
Output is correct |
3 |
Correct |
13 ms |
19028 KB |
Output is correct |
4 |
Correct |
9 ms |
19028 KB |
Output is correct |
5 |
Correct |
11 ms |
19028 KB |
Output is correct |
6 |
Correct |
8 ms |
19024 KB |
Output is correct |
7 |
Correct |
9 ms |
19028 KB |
Output is correct |
8 |
Correct |
9 ms |
19028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
9 ms |
19028 KB |
Output is correct |
3 |
Correct |
13 ms |
19028 KB |
Output is correct |
4 |
Correct |
9 ms |
19028 KB |
Output is correct |
5 |
Correct |
11 ms |
19028 KB |
Output is correct |
6 |
Correct |
8 ms |
19024 KB |
Output is correct |
7 |
Correct |
9 ms |
19028 KB |
Output is correct |
8 |
Correct |
9 ms |
19028 KB |
Output is correct |
9 |
Correct |
9 ms |
19028 KB |
Output is correct |
10 |
Correct |
10 ms |
19028 KB |
Output is correct |
11 |
Incorrect |
9 ms |
19028 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
9 ms |
19028 KB |
Output is correct |
3 |
Correct |
13 ms |
19028 KB |
Output is correct |
4 |
Correct |
9 ms |
19028 KB |
Output is correct |
5 |
Correct |
11 ms |
19028 KB |
Output is correct |
6 |
Correct |
8 ms |
19024 KB |
Output is correct |
7 |
Correct |
9 ms |
19028 KB |
Output is correct |
8 |
Correct |
9 ms |
19028 KB |
Output is correct |
9 |
Correct |
9 ms |
19028 KB |
Output is correct |
10 |
Correct |
10 ms |
19028 KB |
Output is correct |
11 |
Incorrect |
9 ms |
19028 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
19028 KB |
Output is correct |
2 |
Correct |
9 ms |
19028 KB |
Output is correct |
3 |
Correct |
13 ms |
19028 KB |
Output is correct |
4 |
Correct |
9 ms |
19028 KB |
Output is correct |
5 |
Correct |
11 ms |
19028 KB |
Output is correct |
6 |
Correct |
8 ms |
19024 KB |
Output is correct |
7 |
Correct |
9 ms |
19028 KB |
Output is correct |
8 |
Correct |
9 ms |
19028 KB |
Output is correct |
9 |
Correct |
9 ms |
19028 KB |
Output is correct |
10 |
Correct |
10 ms |
19028 KB |
Output is correct |
11 |
Incorrect |
9 ms |
19028 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |