# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
841336 |
2023-09-01T14:06:18 Z |
mwen |
Pinball (JOI14_pinball) |
C++14 |
|
145 ms |
18680 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
constexpr ll INF = 1e18;
void update(int pos, ll val, vector<ll>& tree) {
int n = (int)tree.size()/2;
pos += n;
while(pos > 0) {
tree[pos] = min(tree[pos], val);
pos >>= 1;
}
}
ll query(int l, int r, vector<ll>& tree) {
ll ans = INF;
int n = (int)tree.size()/2;
l += n;
r += n;
for(; l <= r; l>>=1, r>>=1) {
if(l%2==1) {
ans = min(ans, tree[l]);
l++;
}
if(r%2==0) {
ans = min(ans, tree[r]);
r--;
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> m >> n;
vector<tuple<int, int, int, ll>> intervals(m);
vector<int> seen;
for(int i = 0; i < m; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
seen.push_back(a);
seen.push_back(b);
seen.push_back(c);
intervals[i] = {a, b, c, d};
}
seen.push_back(1);
seen.push_back(n);
sort(seen.begin(), seen.end());
seen.erase(unique(seen.begin(), seen.end()), seen.end());
vector<ll> leftMinCost(m, INF);
vector<ll> rightMinCost(m, INF);
vector<ll> leftTree(2*seen.size(), INF);
vector<ll> rightTree(2*seen.size(), INF);
update(0, 0, leftTree);
update((int)seen.size()-1, 0, rightTree);
for(int i = 0; i < m; i++) {
get<0>(intervals[i]) = (int)(lower_bound(seen.begin(), seen.end(), get<0>(intervals[i]))-seen.begin());
get<1>(intervals[i]) = (int)(lower_bound(seen.begin(), seen.end(), get<1>(intervals[i]))-seen.begin());
get<2>(intervals[i]) = (int)(lower_bound(seen.begin(), seen.end(), get<2>(intervals[i]))-seen.begin());
int left = get<0>(intervals[i]);
int right = get<1>(intervals[i]);
int hole = get<2>(intervals[i]);
ll cost = get<3>(intervals[i]);
ll minLeft = query(left, right, leftTree);
leftMinCost[i] = min(leftMinCost[i], minLeft+cost);
update(hole, leftMinCost[i], leftTree);
ll minRight = query(left, right, rightTree);
rightMinCost[i] = min(rightMinCost[i], minRight+cost);
update(hole, rightMinCost[i], rightTree);
}
ll best = INF;
for(int i = 0; i < m; i++) {
best = min(best, leftMinCost[i]+rightMinCost[i]-get<3>(intervals[i]));
}
if(best == INF)
cout << -1 << "\n";
else
cout << best << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
388 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
388 KB |
Output is correct |
17 |
Correct |
2 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
10 ms |
1744 KB |
Output is correct |
26 |
Correct |
28 ms |
4180 KB |
Output is correct |
27 |
Correct |
87 ms |
9780 KB |
Output is correct |
28 |
Correct |
79 ms |
9368 KB |
Output is correct |
29 |
Correct |
58 ms |
7624 KB |
Output is correct |
30 |
Correct |
96 ms |
9788 KB |
Output is correct |
31 |
Correct |
125 ms |
14532 KB |
Output is correct |
32 |
Correct |
117 ms |
13080 KB |
Output is correct |
33 |
Correct |
15 ms |
3928 KB |
Output is correct |
34 |
Correct |
56 ms |
9412 KB |
Output is correct |
35 |
Correct |
78 ms |
18680 KB |
Output is correct |
36 |
Correct |
145 ms |
18628 KB |
Output is correct |
37 |
Correct |
105 ms |
18612 KB |
Output is correct |
38 |
Correct |
103 ms |
18628 KB |
Output is correct |