# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1034824 |
2024-07-25T19:14:10 Z |
vjudge1 |
Pinball (JOI14_pinball) |
C++17 |
|
97 ms |
14280 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define lwb lower_bound
#define upb upper_bound
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) x * y / __gcd(x, y)
const int mod = 1e9 + 7;
const ll inf = 1e18;
const int mxN = 1e6 + 5;
const int block = 450;
const int base = 311;
const int LOG = 19;
struct pinball {
ll a, b, c, d;
} a[mxN];
int m, n;
namespace sub3 {
bool check() {
return m <= 1000;
}
ll L[mxN], R[mxN];
void solve() {
for (int i = 1; i <= m; i++) {
L[i] = inf;
R[i] = inf;
}
for (int i = 1; i <= m; i++) {
if (a[i].a == 1) {
L[i] = a[i].d;
}
if (a[i].b == n) {
R[i] = a[i].d;
}
for (int j = 1; j < i; j++) {
if (a[j].a < a[i].a && a[i].a <= a[j].c && a[j].c <= a[i].b) {
L[i] = min(L[i], L[j] + a[i].d);
}
if (a[j].b > a[i].b && a[i].a <= a[j].c && a[j].c <= a[i].b) {
R[i] = min(R[i], R[j] + a[i].d);
}
}
}
ll ans = inf;
for (int i = 1; i <= m; i++) {
ans = min(ans, L[i] + R[i] - a[i].d);
}
if (ans == inf) {
cout << -1;
}
else {
cout << ans;
}
}
}
namespace sub4 {
struct SegTree {
int n;
ll st[4 * mxN];
void build() {
for (int i = 1; i <= 4 * n; i++) {
st[i] = inf;
}
}
void update(int i, int l, int r, int p, ll val) {
if (p < l || p > r) {
return;
}
if (l == r) {
st[i] = val;
return;
}
int m = (l + r) / 2;
update(i * 2, l, m, p, val);
update(i * 2 + 1, m + 1, r, p, val);
st[i] = min(st[i * 2], st[i * 2 + 1]);
}
ll get(int i, int l, int r, int u, int v) {
if (v < l || u > r) {
return inf;
}
if (u <= l && r <= v) {
return st[i];
}
int m = (l + r) / 2;
return min(get(i * 2, l, m, u, v), get(i * 2 + 1, m + 1, r, u, v));
}
} L, R;
ll p[mxN], q[mxN];
vector<ll> v;
void solve() {
for (int i = 1; i <= m; i++) {
v.pb(a[i].a);
v.pb(a[i].b);
v.pb(a[i].c);
}
v.pb(n);
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
n = lwb(v.begin(), v.end(), n) - v.begin() + 1;
for (int i = 1; i <= m; i++) {
a[i].a = lwb(v.begin(), v.end(), a[i].a) - v.begin() + 1;
a[i].b = lwb(v.begin(), v.end(), a[i].b) - v.begin() + 1;
a[i].c = lwb(v.begin(), v.end(), a[i].c) - v.begin() + 1;
}
L.n = n;
R.n = n;
L.build();
R.build();
for (int i = 1; i <= m; i++) {
p[i] = inf;
q[i] = inf;
}
for (int i = 1; i <= m; i++) {
if (a[i].a == 1) {
p[i] = a[i].d;
}
if (a[i].b == n) {
q[i] = a[i].d;
}
ll x = L.get(1, 1, n, a[i].a, a[i].b);
ll y = R.get(1, 1, n, a[i].a, a[i].b);
p[i] = min(p[i], x + a[i].d);
q[i] = min(q[i], y + a[i].d);
L.update(1, 1, n, a[i].c, p[i]);
R.update(1, 1, n, a[i].c, q[i]);
}
// for (int i = 1; i <= m; i++) {
// cout << p[i] << " ";
// }
// cout << '\n';
// for (int i = 1; i <= m; i++) {
// cout << p[i] << " ";
// }
ll ans = inf;
for (int i = 1; i <= m; i++) {
ans = min(ans, p[i] + q[i] - a[i].d);
}
if (ans == inf) {
cout << -1;
}
else {
cout << ans;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> m >> n;
for (int i = 1; i <= m; i++) {
cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
}
if (sub3::check()) return sub3::solve(), 0;
sub4::solve();
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
524 KB |
Output is correct |
18 |
Correct |
3 ms |
472 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
3 ms |
524 KB |
Output is correct |
18 |
Correct |
3 ms |
472 KB |
Output is correct |
19 |
Correct |
3 ms |
348 KB |
Output is correct |
20 |
Correct |
3 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
524 KB |
Output is correct |
25 |
Correct |
12 ms |
2528 KB |
Output is correct |
26 |
Correct |
34 ms |
6616 KB |
Output is correct |
27 |
Correct |
97 ms |
14280 KB |
Output is correct |
28 |
Incorrect |
85 ms |
11576 KB |
Output isn't correct |
29 |
Halted |
0 ms |
0 KB |
- |