답안 #142813

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142813 2019-08-11T08:34:04 Z alextodoran Pinball (JOI14_pinball) C++14
100 / 100
119 ms 16600 KB
#include <bits/stdc++.h>

#define M_MAX 100002
#define N_MAX 300002
#define ll long long

using namespace std;

const ll INF = 100000000000000001;

struct Device
{
    int l, r;
    int hole;
    ll cost;
};

int n, m;

Device devices[M_MAX];

struct Object
{
    int pos;
    char type;
    int index;
};
bool operator < (const Object &a, const Object &b)
{
    return a.pos < b.pos;
}

vector <Object> objects;

ll dpL[M_MAX], dpR[M_MAX];

ll aibL[N_MAX], aibR[N_MAX];

void updateL (int pos, ll val)
{
    for(int i = pos; i >= 1; i -= i&(-i))
        aibL[i] = min(aibL[i], val);
}

void updateR (int pos, ll val)
{
    for(int i = pos; i <= n; i += i&(-i))
        aibR[i] = min(aibR[i], val);
}

ll queryL (int pos)
{
    ll ans = INF;
    for(int i = pos; i <= n; i += i&(-i))
        ans = min(ans, aibL[i]);
    return ans;
}

ll queryR (int pos)
{
    ll ans = INF;
    for(int i = pos; i >= 1; i -= i&(-i))
        ans = min(ans, aibR[i]);
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> m >> n;
    bool okL = false, okR = false;
    for(int i = 1; i <= m; i++)
    {
        cin >> devices[i].l >> devices[i].r >> devices[i].hole >> devices[i].cost;
        if(devices[i].l == 1)
            okL = true;
        if(devices[i].r == n)
            okR = true;
        objects.push_back(Object{devices[i].l, 'L', i});
        objects.push_back(Object{devices[i].r, 'R', i});
        objects.push_back(Object{devices[i].hole, 'H', i});
    }
    if(okL == false || okR == false)
    {
        cout << "-1\n";
        return 0;
    }
    sort(objects.begin(), objects.end());
    int pos = 1;
    for(int i = 0; i < objects.size(); i++)
    {
        if(i > 0 && objects[i].pos > objects[i - 1].pos)
            pos++;
        if(objects[i].type == 'L')
            devices[objects[i].index].l = pos;
        if(objects[i].type == 'R')
            devices[objects[i].index].r = pos;
        if(objects[i].type == 'H')
            devices[objects[i].index].hole = pos;
    }
    n = pos;
    for(int i = 0; i <= m; i++)
        dpL[i] = dpR[i] = INF;
    for(int i = 1; i <= m; i++)
    {
        if(devices[i].l == 1)
            dpL[i] = devices[i].cost;
        if(devices[i].r == n)
            dpR[i] = devices[i].cost;
    }
    for(int i = 1; i <= n; i++)
        aibL[i] = aibR[i] = INF;
    ll ans = INF;
    for(int i = 1; i <= m; i++)
    {
        if(dpL[i] == INF)
            dpL[i] = min(INF, queryL(devices[i].l) + devices[i].cost);
        if(dpR[i] == INF)
            dpR[i] = min(INF, queryR(devices[i].r) + devices[i].cost);
        updateL(devices[i].hole, dpL[i]);
        updateR(devices[i].hole, dpR[i]);
        ans = min(ans, dpL[i] + dpR[i] - devices[i].cost);
    }
    cout << ans << "\n";
    return 0;
}

Compilation message

pinball.cpp: In function 'int main()':
pinball.cpp:93:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < objects.size(); i++)
                    ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 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 3 ms 380 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 3 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 3 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 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 3 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 3 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 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 2 ms 376 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 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 3 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 3 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 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 2 ms 376 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 11 ms 1908 KB Output is correct
26 Correct 29 ms 4076 KB Output is correct
27 Correct 83 ms 9828 KB Output is correct
28 Correct 101 ms 12256 KB Output is correct
29 Correct 58 ms 7652 KB Output is correct
30 Correct 108 ms 12228 KB Output is correct
31 Correct 115 ms 14396 KB Output is correct
32 Correct 114 ms 13788 KB Output is correct
33 Correct 21 ms 3692 KB Output is correct
34 Correct 59 ms 8420 KB Output is correct
35 Correct 106 ms 16600 KB Output is correct
36 Correct 119 ms 16528 KB Output is correct
37 Correct 118 ms 16500 KB Output is correct
38 Correct 116 ms 16568 KB Output is correct