답안 #152597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152597 2019-09-08T14:16:40 Z karma Pinball (JOI14_pinball) C++14
100 / 100
442 ms 32620 KB
#include<bits/stdc++.h>
#define pb      emplace_back
#define mp      make_pair
#define fi      first
#define se      second
#define ll      long long

using namespace std;

const int N = int(3e5) + 7;
const ll inf = (ll)1e18;

struct TDevice {
    int l, r, pos;
    ll cost;
} d[N];
ll st[N << 2][2], res, f[2];
int n, m, l[N << 2], h[N << 2];
vector<int> v;

void Build(int x, int low, int high) {
    l[x] = low, h[x] = high;
    st[x][0] = st[x][1] = inf;
    if(l[x] == h[x]) return;
    int mid = (low + high) >> 1;
    Build(x << 1, low, mid);
    Build(x << 1 | 1, mid + 1, high);
}

void Update(int x, int pos, ll cost, bool type) {
    if(l[x] > pos || h[x] < pos) return;
    if(l[x] == h[x]) {
       st[x][type] = min(st[x][type], cost);
       return;
    }
    Update(x << 1, pos, cost, type);
    Update(x << 1 | 1, pos, cost, type);
    st[x][type] = min(st[x << 1][type], st[x << 1 | 1][type]);
}

ll Query(int x, int low, int high, bool type) {
    if(l[x] > high || h[x] < low) return inf;
    if(l[x] >= low && h[x] <= high) return st[x][type];
    return min(Query(x << 1, low, high, type), Query(x << 1 | 1, low, high, type));
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> m >> n;
    for(int i = 0; i < m; ++i) {
        cin >> d[i].l >> d[i].r >> d[i].pos >> d[i].cost;
        v.pb(d[i].l), v.pb(d[i].r), v.pb(d[i].pos);
    }
    v.pb(1), v.pb(n); res = inf;
    sort(v.begin(), v.end());
    Build(1, 1, int(v.size()));
    for(int i = 0; i < m; ++i) {
        d[i].l = lower_bound(v.begin(), v.end(), d[i].l) - v.begin() + 1;
        d[i].r = lower_bound(v.begin(), v.end(), d[i].r) - v.begin() + 1;
        d[i].pos = lower_bound(v.begin(), v.end(), d[i].pos) - v.begin() + 1;
        if(v[d[i].r - 1] == n) f[1] = 0;
        else f[1] = Query(1, d[i].l, d[i].r, 1);
        if(v[d[i].l - 1] == 1) f[0] = 0;
        else f[0] = Query(1, d[i].l, d[i].r, 0);
        //cout << f[1] << ' ' << f[0] << '\n';
        res = min(res, f[0] + f[1] + d[i].cost);
        Update(1, d[i].pos, f[0] + d[i].cost, 0);
        Update(1, d[i].pos, f[1] + d[i].cost, 1);
    }
    if(res == inf) res = -1;
    cout << res;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
pinball.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 4 ms 636 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 4 ms 632 KB Output is correct
20 Correct 4 ms 632 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 4 ms 636 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 4 ms 632 KB Output is correct
20 Correct 4 ms 632 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 4 ms 632 KB Output is correct
24 Correct 4 ms 632 KB Output is correct
25 Correct 27 ms 2684 KB Output is correct
26 Correct 81 ms 8436 KB Output is correct
27 Correct 259 ms 17776 KB Output is correct
28 Correct 343 ms 32488 KB Output is correct
29 Correct 185 ms 16620 KB Output is correct
30 Correct 406 ms 32588 KB Output is correct
31 Correct 442 ms 32620 KB Output is correct
32 Correct 406 ms 32488 KB Output is correct
33 Correct 46 ms 4984 KB Output is correct
34 Correct 172 ms 16420 KB Output is correct
35 Correct 253 ms 32488 KB Output is correct
36 Correct 401 ms 32492 KB Output is correct
37 Correct 342 ms 32616 KB Output is correct
38 Correct 335 ms 32616 KB Output is correct