답안 #313523

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313523 2020-10-16T07:17:10 Z alextodoran Pinball (JOI14_pinball) C++17
100 / 100
114 ms 16476 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:92:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Object>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for(int i = 0; i < objects.size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 2 ms 544 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 512 KB Output is correct
18 Correct 2 ms 544 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 640 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 9 ms 1788 KB Output is correct
26 Correct 23 ms 4084 KB Output is correct
27 Correct 66 ms 9796 KB Output is correct
28 Correct 85 ms 12260 KB Output is correct
29 Correct 49 ms 7524 KB Output is correct
30 Correct 91 ms 12260 KB Output is correct
31 Correct 101 ms 14424 KB Output is correct
32 Correct 98 ms 13748 KB Output is correct
33 Correct 19 ms 3576 KB Output is correct
34 Correct 50 ms 8420 KB Output is correct
35 Correct 89 ms 16476 KB Output is correct
36 Correct 112 ms 16472 KB Output is correct
37 Correct 104 ms 16472 KB Output is correct
38 Correct 114 ms 16472 KB Output is correct