# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
481018 |
2021-10-19T08:09:46 Z |
blue |
Pinball (JOI14_pinball) |
C++17 |
|
854 ms |
90700 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
const long long INF = 1'000'000'000'000'000'000LL;
struct segtree
{
int l;
int r;
long long mn = INF;
segtree* left = NULL;
segtree* right = NULL;
segtree()
{
;
}
segtree(int L, int R)
{
l = L;
r = R;
if(l == r) return;
int m = (l+r)/2;
left = new segtree(l, m);
right = new segtree(m+1, r);
}
void update(int I, long long V)
{
if(I < l || r < I) return;
else if(l == r) mn = min(mn, V);
else
{
left->update(I, V);
right->update(I, V);
mn = min(left->mn, right->mn);
}
}
long long rangemin(int L, int R)
{
if(R < l || r < L) return INF;
else if(L <= l && r <= R) return mn;
else return min(left->rangemin(L, R), right->rangemin(L, R));
}
};
long long op(long long q)
{
if(q >= INF) q = -1;
return q;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int M, N;
cin >> M >> N;
set<int> vals;
map<int, int> newvals;
vector<int> A(1+M), B(1+M), C(1+M);
vector<long long> D(1+M);
for(int i = 1; i <= M; i++)
{
cin >> A[i] >> B[i] >> C[i] >> D[i];
vals.insert(A[i]);
vals.insert(B[i]);
vals.insert(C[i]);
}
vals.insert(1);
vals.insert(N);
int ct = 0;
for(int v: vals)
{
ct++;
newvals[v] = ct;
}
for(int i = 1; i <= M; i++)
{
A[i] = newvals[A[i]];
B[i] = newvals[B[i]];
C[i] = newvals[C[i]];
}
N = newvals[N];
// cerr << N << '\n';
// for(int i = 1; i <= M; i++) cerr << A[i] << ' ' << B[i] << ' ' << C[i] << '\n';
//
// cerr << "\n\n";
segtree lft(1, N), rgt(1, N);
lft.update(1, 0);
rgt.update(N, 0);
long long ans = INF;
// cerr << "i = " << 0 << '\n';
// for(int j = 1; j <= N; j++) cerr << op(lft.rangemin(j, j)) << ' ';
// cerr << '\n';
// for(int j = 1; j <= N; j++) cerr << op(rgt.rangemin(j, j)) << ' ';
// cerr << '\n';
// cerr << "ans = " << ans << '\n';
for(int i = 1; i <= M; i++)
{
// cerr << "\n\n";
// cerr << "i = " << i << '\n';
long long LV = lft.rangemin(A[i], N);
long long RV = rgt.rangemin(1, B[i]);
ans = min(ans, LV + RV + D[i]);
// cerr << lft.rangemin(C[i], C[i]) << ' ' << rgt.rangemin(C[i], C[i]) << '\n';
// cerr << LV << ' ' << RV << ' ' << D[i] << '\n';
lft.update(C[i], D[i] + LV);
rgt.update(C[i], D[i] + RV);
// for(int j = 1; j <= N; j++) cerr << op(lft.rangemin(j, j)) << ' ';
// cerr << '\n';
// for(int j = 1; j <= N; j++) cerr << op(rgt.rangemin(j, j)) << ' ';
// cerr << '\n';
// cerr << "ans = " << ans << '\n';
}
if(ans >= INF) ans = -1;
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
716 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
1100 KB |
Output is correct |
20 |
Correct |
2 ms |
580 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
4 ms |
1100 KB |
Output is correct |
23 |
Correct |
3 ms |
1100 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
716 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
1100 KB |
Output is correct |
20 |
Correct |
2 ms |
580 KB |
Output is correct |
21 |
Correct |
2 ms |
716 KB |
Output is correct |
22 |
Correct |
4 ms |
1100 KB |
Output is correct |
23 |
Correct |
3 ms |
1100 KB |
Output is correct |
24 |
Correct |
3 ms |
1100 KB |
Output is correct |
25 |
Correct |
33 ms |
5616 KB |
Output is correct |
26 |
Correct |
117 ms |
17348 KB |
Output is correct |
27 |
Correct |
340 ms |
32800 KB |
Output is correct |
28 |
Correct |
135 ms |
6584 KB |
Output is correct |
29 |
Correct |
257 ms |
28868 KB |
Output is correct |
30 |
Correct |
234 ms |
11080 KB |
Output is correct |
31 |
Correct |
611 ms |
53380 KB |
Output is correct |
32 |
Correct |
521 ms |
40132 KB |
Output is correct |
33 |
Correct |
76 ms |
17892 KB |
Output is correct |
34 |
Correct |
322 ms |
45356 KB |
Output is correct |
35 |
Correct |
408 ms |
90436 KB |
Output is correct |
36 |
Correct |
854 ms |
90700 KB |
Output is correct |
37 |
Correct |
690 ms |
90616 KB |
Output is correct |
38 |
Correct |
626 ms |
90528 KB |
Output is correct |