답안 #728348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
728348 2023-04-22T09:00:28 Z Kahou Pinball (JOI14_pinball) C++14
51 / 100
48 ms 7028 KB
/* In the name of God, aka Allah */
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll inf = 1e18;
const int N = 1e5 + 50;
int n, m, k, a[N][3], d[N];
pii P[N];
ll seg[2][N<<2];

void build(int c, int u=1, int tl=1, int tr=k) {
        if (tl == tr) {
                seg[c][u] = (tl == 1+c*(k-1)? 0: inf);
                return;
        }
        int md = (tl+tr)>>1;
        int lc = u<<1;
        int rc = u<<1|1;
        build(c, lc, tl, md), build(c, rc, md+1, tr);
        seg[c][u] = min(seg[c][lc], seg[c][rc]);
}
void upd(int c, int id, ll x, int u=1, int tl=1, int tr=k) {
        if (id < tl || tr < id) return;
        if (tl == tr) {
                seg[c][u] = min(seg[c][u], x);
                return;
        }
        int md = (tl+tr)>>1;
        int lc = u<<1;
        int rc = u<<1|1;
        upd(c, id, x, lc, tl, md), upd(c, id, x, rc, md+1, tr);
        seg[c][u] = min(seg[c][lc], seg[c][rc]);
}
ll get(int c, int l, int r, int u=1, int tl=1, int tr=k) {
        if (r < tl || tr < l) return inf;
        if (l <= tl && tr <= r) return seg[c][u];
        int md = (tl+tr)>>1;
        int lc = u<<1;
        int rc = u<<1|1;
        return min(get(c, l, r, lc, tl, md), get(c, l, r, rc, md+1, tr));
}

void solve() {
        cin >> n >> m;
        if (n == 1) return cout << 0 << endl, void();
        for (int i = 1; i <= n; i++) {
                cin >> a[i][0] >> a[i][1] >> a[i][2] >> d[i];
                P[3*i] = {a[i][0], 3*i};
                P[3*i+1] = {a[i][1], 3*i+1};
                P[3*i+2] = {a[i][2], 3*i+2};
        }
        P[1] = {1, 0};
        P[2] = {m, 0};
        sort(P+1, P+3*n+3);
        for (int i = 1; i <= 3*n+2; i++) {
                k += (P[i].F != P[i-1].F);
                if (P[i].S) a[P[i].S/3][P[i].S%3] = k;
        }
        build(0);
        build(1);
        ll ans = inf;
        for (int i = 1; i <= n; i++) {
                ans = min(ans, get(0, a[i][0], a[i][1])+get(1, a[i][0], a[i][1])+d[i]);
                upd(0, a[i][2], get(0, a[i][0], a[i][1])+d[i]);
                upd(1, a[i][2], get(1, a[i][0], a[i][1])+d[i]);
        }
        cout << (ans >= inf? -1 : ans) << endl;
}

int main() {
        ios::sync_with_stdio(0), cin.tie(0);
        solve();
        return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 472 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 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 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 2 ms 472 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 596 KB Output is correct
24 Correct 2 ms 480 KB Output is correct
25 Correct 18 ms 2072 KB Output is correct
26 Correct 47 ms 4128 KB Output is correct
27 Runtime error 48 ms 7028 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -