# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
319776 |
2020-11-06T12:11:27 Z |
Pety |
Pinball (JOI14_pinball) |
C++14 |
|
971 ms |
32080 KB |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100002], b[100002], c[100002], d[100002];
long long aint[2000002], dp1[100002], dp2[100002];
const long long inf = 1e18;
void update (int nod, int st, int dr, int pozV, long long new_val) {
if (st == dr)
aint[nod] = min(aint[nod], new_val);
else {
int med = (st + dr) / 2;
if (pozV <= med)
update(2 * nod, st, med, pozV, new_val);
if (pozV >= med + 1)
update (2 * nod + 1, med + 1, dr, pozV, new_val);
aint[nod] = min(aint[2 * nod], aint[2 * nod + 1]);
}
}
long long query (int nod, int st, int dr, int a, int b) {
if (a <= st && dr <= b)
return aint[nod];
else {
int med = (st + dr) / 2;
long long ans = inf;
if (a <= med)
ans = min(ans, query(2 * nod, st, med, a, b));
if (b >= med + 1)
ans = min(ans, query(2 * nod + 1, med + 1, dr, a, b));
return ans;
}
}
map<int, int>mp;
int main ()
{
cin >> m >> n;
vector<int>norm;
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
norm.push_back(a[i]);
norm.push_back(b[i]);
norm.push_back(c[i]);
}
sort(norm.begin(), norm.end());
int nr = 0;
for (int i = 0; i < norm.size(); i++) {
if (!i || norm[i] != norm[i - 1]) {
mp[norm[i]] = ++nr;
}
}
for (int i = 1; i <= 4 * nr; i++)
aint[i] = inf;
for (int i = 1; i <= m; i++)
dp1[i] = dp2[i] = inf;
for (int i = 1; i <= m; i++) {
if (a[i] == 1)
dp1[i] = d[i];
else
dp1[i] = min(dp1[i], d[i] + query(1, 1, nr, mp[a[i]], mp[b[i]]));
update(1, 1, nr, mp[c[i]], dp1[i]);
}
for (int i = 1; i <= 4 * nr; i++)
aint[i] = inf;
for (int i = 1; i <= m; i++) {
if (b[i] == n)
dp2[i] = d[i];
else
dp2[i] = min(dp2[i], d[i] + query(1, 1, nr, mp[a[i]], mp[b[i]]));
update(1, 1, nr, mp[c[i]], dp2[i]);
}
long long ans = 1e18;
for (int i = 1; i <= m; i++)
ans = min(ans, dp1[i] + dp2[i] - d[i]);
cout << (ans < inf ? ans : -1);
return 0;
}
Compilation message
pinball.cpp: In function 'int main()':
pinball.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = 0; i < norm.size(); i++) {
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
396 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
396 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
388 KB |
Output is correct |
17 |
Correct |
7 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
620 KB |
Output is correct |
20 |
Correct |
4 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
6 ms |
748 KB |
Output is correct |
23 |
Correct |
4 ms |
748 KB |
Output is correct |
24 |
Correct |
5 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
396 KB |
Output is correct |
14 |
Correct |
1 ms |
492 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
388 KB |
Output is correct |
17 |
Correct |
7 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
620 KB |
Output is correct |
20 |
Correct |
4 ms |
492 KB |
Output is correct |
21 |
Correct |
2 ms |
492 KB |
Output is correct |
22 |
Correct |
6 ms |
748 KB |
Output is correct |
23 |
Correct |
4 ms |
748 KB |
Output is correct |
24 |
Correct |
5 ms |
620 KB |
Output is correct |
25 |
Correct |
43 ms |
2548 KB |
Output is correct |
26 |
Correct |
152 ms |
6876 KB |
Output is correct |
27 |
Correct |
510 ms |
13908 KB |
Output is correct |
28 |
Correct |
315 ms |
8656 KB |
Output is correct |
29 |
Correct |
331 ms |
11608 KB |
Output is correct |
30 |
Correct |
411 ms |
9932 KB |
Output is correct |
31 |
Correct |
839 ms |
21840 KB |
Output is correct |
32 |
Correct |
710 ms |
18000 KB |
Output is correct |
33 |
Correct |
87 ms |
6496 KB |
Output is correct |
34 |
Correct |
374 ms |
16344 KB |
Output is correct |
35 |
Correct |
518 ms |
32080 KB |
Output is correct |
36 |
Correct |
971 ms |
31952 KB |
Output is correct |
37 |
Correct |
775 ms |
32080 KB |
Output is correct |
38 |
Correct |
744 ms |
32080 KB |
Output is correct |