답안 #373393

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373393 2021-03-04T12:15:00 Z BartolM Pinball (JOI14_pinball) C++17
100 / 100
320 ms 23904 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
typedef pair <pii, pii> ppp;

const int INF=0x3f3f3f3f;
const ll MAX=(ll)INF*INF;
const int N=1e5+5;
const int OFF=(1<<19);

struct Tour{
    ll T[2*OFF];
    Tour() {
        fill(T, T+2*OFF, MAX);
    }
    void update(int pos, ll x) {
        pos+=OFF; T[pos]=min(T[pos], x);
        pos/=2;
        while (pos) {
            T[pos]=min(T[pos*2], T[pos*2+1]);
            pos/=2;
        }
    }
    ll query(int a, int b, int pos=1, int lo=0, int hi=OFF) {
        if (lo>=a && hi<=b) return T[pos];
        if (lo>=b || hi<=a) return MAX;
        int mid=(lo+hi)/2;
        return min(query(a, b, pos*2, lo, mid), query(a, b, pos*2+1, mid, hi));
    }
};

int n, m;
ppp p[N];
vector <int> saz;
Tour T1, Tm;

int sazmi(int x) {
    return lower_bound(saz.begin(), saz.end(), x)-saz.begin();
}

void solve() {
    ll sol=MAX;
    T1.update(0, 0); Tm.update(m, 0);
    for (int i=0; i<n; ++i) {
        ll a1=T1.query(p[i].X.X, p[i].X.Y+1), am=Tm.query(p[i].X.X, p[i].X.Y+1);
        sol=min(sol, a1+am+p[i].Y.Y);
        T1.update(p[i].Y.X, a1+p[i].Y.Y);
        Tm.update(p[i].Y.X, am+p[i].Y.Y);
    }
    printf("%lld\n", sol>=MAX ? -1 : sol);
}

void load() {
    scanf("%d %d", &n, &m);
    for (int i=0; i<n; ++i) {
        scanf("%d %d %d %d", &p[i].X.X, &p[i].X.Y, &p[i].Y.X, &p[i].Y.Y);
        saz.pb(p[i].X.X); saz.pb(p[i].X.Y); saz.pb(p[i].Y.X);
    }
    saz.pb(1); saz.pb(m);
    sort(saz.begin(), saz.end());
    saz.erase(unique(saz.begin(), saz.end()), saz.end());
    m=sazmi(m);
    for (int i=0; i<n; ++i) {
        p[i].X.X=sazmi(p[i].X.X);
        p[i].X.Y=sazmi(p[i].X.Y);
        p[i].Y.X=sazmi(p[i].Y.X);
    }
}

int main() {
    load();
    solve();
    return 0;
}

Compilation message

pinball.cpp: In function 'void load()':
pinball.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   64 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
pinball.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   66 |         scanf("%d %d %d %d", &p[i].X.X, &p[i].X.Y, &p[i].Y.X, &p[i].Y.Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 10 ms 16748 KB Output is correct
3 Correct 10 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 10 ms 16748 KB Output is correct
6 Correct 10 ms 16748 KB Output is correct
7 Correct 12 ms 16748 KB Output is correct
8 Correct 10 ms 16748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 10 ms 16748 KB Output is correct
3 Correct 10 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 10 ms 16748 KB Output is correct
6 Correct 10 ms 16748 KB Output is correct
7 Correct 12 ms 16748 KB Output is correct
8 Correct 10 ms 16748 KB Output is correct
9 Correct 10 ms 16748 KB Output is correct
10 Correct 10 ms 16748 KB Output is correct
11 Correct 10 ms 16748 KB Output is correct
12 Correct 11 ms 16748 KB Output is correct
13 Correct 10 ms 16748 KB Output is correct
14 Correct 10 ms 16748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 10 ms 16748 KB Output is correct
3 Correct 10 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 10 ms 16748 KB Output is correct
6 Correct 10 ms 16748 KB Output is correct
7 Correct 12 ms 16748 KB Output is correct
8 Correct 10 ms 16748 KB Output is correct
9 Correct 10 ms 16748 KB Output is correct
10 Correct 10 ms 16748 KB Output is correct
11 Correct 10 ms 16748 KB Output is correct
12 Correct 11 ms 16748 KB Output is correct
13 Correct 10 ms 16748 KB Output is correct
14 Correct 10 ms 16748 KB Output is correct
15 Correct 11 ms 16748 KB Output is correct
16 Correct 10 ms 16748 KB Output is correct
17 Correct 14 ms 16896 KB Output is correct
18 Correct 14 ms 16760 KB Output is correct
19 Correct 12 ms 16876 KB Output is correct
20 Correct 12 ms 16876 KB Output is correct
21 Correct 13 ms 16768 KB Output is correct
22 Correct 12 ms 16876 KB Output is correct
23 Correct 12 ms 16896 KB Output is correct
24 Correct 12 ms 16876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16748 KB Output is correct
2 Correct 10 ms 16748 KB Output is correct
3 Correct 10 ms 16748 KB Output is correct
4 Correct 10 ms 16748 KB Output is correct
5 Correct 10 ms 16748 KB Output is correct
6 Correct 10 ms 16748 KB Output is correct
7 Correct 12 ms 16748 KB Output is correct
8 Correct 10 ms 16748 KB Output is correct
9 Correct 10 ms 16748 KB Output is correct
10 Correct 10 ms 16748 KB Output is correct
11 Correct 10 ms 16748 KB Output is correct
12 Correct 11 ms 16748 KB Output is correct
13 Correct 10 ms 16748 KB Output is correct
14 Correct 10 ms 16748 KB Output is correct
15 Correct 11 ms 16748 KB Output is correct
16 Correct 10 ms 16748 KB Output is correct
17 Correct 14 ms 16896 KB Output is correct
18 Correct 14 ms 16760 KB Output is correct
19 Correct 12 ms 16876 KB Output is correct
20 Correct 12 ms 16876 KB Output is correct
21 Correct 13 ms 16768 KB Output is correct
22 Correct 12 ms 16876 KB Output is correct
23 Correct 12 ms 16896 KB Output is correct
24 Correct 12 ms 16876 KB Output is correct
25 Correct 32 ms 17388 KB Output is correct
26 Correct 77 ms 18664 KB Output is correct
27 Correct 177 ms 21344 KB Output is correct
28 Correct 173 ms 23776 KB Output is correct
29 Correct 126 ms 20452 KB Output is correct
30 Correct 206 ms 23904 KB Output is correct
31 Correct 286 ms 23868 KB Output is correct
32 Correct 251 ms 23904 KB Output is correct
33 Correct 41 ms 18024 KB Output is correct
34 Correct 125 ms 20452 KB Output is correct
35 Correct 174 ms 23904 KB Output is correct
36 Correct 320 ms 23904 KB Output is correct
37 Correct 244 ms 23904 KB Output is correct
38 Correct 240 ms 23904 KB Output is correct