#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
int n, m;
struct st {
ll mini[2] = { (ll)1e18,(ll)1e18 };
st *left=NULL, *right=NULL;
}tree;
void update(st *h, int l, int r, int g,ll x, int type) {
if (r < g || g < l) return;
h->mini[type] = min(h->mini[type], x);
if (l != r) {
if (!h->left) h->left = new st;
if (!h->right) h->right = new st;
update(h->left, l, (l + r) / 2, g, x, type);
update(h->right, (l + r) / 2+1,r, g, x, type);
}
}
ll query(st *h, int l, int r, int gl, int gr, int type) {
if (r < gl || gr < l) return 1e18;
if (gl <= l && r <= gr) return h->mini[type];
if (!h->left) h->left = new st;
if (!h->right) h->right = new st;
return min(query(h->left, l, (l + r) / 2, gl, gr, type),
query(h->right, (l + r) / 2 + 1, r, gl, gr, type));
}
int main() {
scanf("%d %d", &m, &n);
st *rt = new st;
update(rt, 1, n, 1, 0, 0);
update(rt, 1, n, n, 0, 1);
ll res = 1e18;
for (int i = 0; i < m; i++) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
ll ql = query(rt, 1, n, a, b, 0), qr = query(rt, 1, n, a, b, 1);
res = min(res, ql+qr+d);
update(rt, 1, n, c, ql+d, 0);
update(rt, 1, n, c, qr+d, 1);
}
printf("%lld", res==1e18?-1:res);
return 0;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &m, &n);
~~~~~^~~~~~~~~~~~~~~~~
pinball.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &a, &b, &c, &d);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
368 KB |
Output is correct |
3 |
Correct |
3 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
2 ms |
652 KB |
Output is correct |
7 |
Correct |
1 ms |
652 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
368 KB |
Output is correct |
3 |
Correct |
3 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
2 ms |
652 KB |
Output is correct |
7 |
Correct |
1 ms |
652 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
652 KB |
Output is correct |
10 |
Correct |
4 ms |
748 KB |
Output is correct |
11 |
Correct |
6 ms |
936 KB |
Output is correct |
12 |
Correct |
5 ms |
1588 KB |
Output is correct |
13 |
Correct |
6 ms |
1736 KB |
Output is correct |
14 |
Correct |
5 ms |
1760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
368 KB |
Output is correct |
3 |
Correct |
3 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
2 ms |
652 KB |
Output is correct |
7 |
Correct |
1 ms |
652 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
652 KB |
Output is correct |
10 |
Correct |
4 ms |
748 KB |
Output is correct |
11 |
Correct |
6 ms |
936 KB |
Output is correct |
12 |
Correct |
5 ms |
1588 KB |
Output is correct |
13 |
Correct |
6 ms |
1736 KB |
Output is correct |
14 |
Correct |
5 ms |
1760 KB |
Output is correct |
15 |
Correct |
3 ms |
1760 KB |
Output is correct |
16 |
Correct |
4 ms |
1760 KB |
Output is correct |
17 |
Correct |
10 ms |
2424 KB |
Output is correct |
18 |
Correct |
6 ms |
2424 KB |
Output is correct |
19 |
Correct |
14 ms |
4972 KB |
Output is correct |
20 |
Correct |
9 ms |
4972 KB |
Output is correct |
21 |
Correct |
6 ms |
4972 KB |
Output is correct |
22 |
Correct |
11 ms |
5060 KB |
Output is correct |
23 |
Correct |
13 ms |
5748 KB |
Output is correct |
24 |
Correct |
13 ms |
5788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
368 KB |
Output is correct |
3 |
Correct |
3 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
500 KB |
Output is correct |
5 |
Correct |
2 ms |
500 KB |
Output is correct |
6 |
Correct |
2 ms |
652 KB |
Output is correct |
7 |
Correct |
1 ms |
652 KB |
Output is correct |
8 |
Correct |
3 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
652 KB |
Output is correct |
10 |
Correct |
4 ms |
748 KB |
Output is correct |
11 |
Correct |
6 ms |
936 KB |
Output is correct |
12 |
Correct |
5 ms |
1588 KB |
Output is correct |
13 |
Correct |
6 ms |
1736 KB |
Output is correct |
14 |
Correct |
5 ms |
1760 KB |
Output is correct |
15 |
Correct |
3 ms |
1760 KB |
Output is correct |
16 |
Correct |
4 ms |
1760 KB |
Output is correct |
17 |
Correct |
10 ms |
2424 KB |
Output is correct |
18 |
Correct |
6 ms |
2424 KB |
Output is correct |
19 |
Correct |
14 ms |
4972 KB |
Output is correct |
20 |
Correct |
9 ms |
4972 KB |
Output is correct |
21 |
Correct |
6 ms |
4972 KB |
Output is correct |
22 |
Correct |
11 ms |
5060 KB |
Output is correct |
23 |
Correct |
13 ms |
5748 KB |
Output is correct |
24 |
Correct |
13 ms |
5788 KB |
Output is correct |
25 |
Correct |
64 ms |
8644 KB |
Output is correct |
26 |
Correct |
228 ms |
42856 KB |
Output is correct |
27 |
Correct |
656 ms |
73920 KB |
Output is correct |
28 |
Correct |
320 ms |
73920 KB |
Output is correct |
29 |
Correct |
467 ms |
93652 KB |
Output is correct |
30 |
Correct |
721 ms |
93652 KB |
Output is correct |
31 |
Execution timed out |
1092 ms |
165688 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |