답안 #817100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817100 2023-08-09T09:27:38 Z Cookie Pinball (JOI14_pinball) C++14
100 / 100
204 ms 13088 KB
#include<bits/stdc++.h>
#include<fstream>
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const int base = 74;
const ll mod = 1e9 + 7, inf = 1e17, mxv = 1005, mxn = 5e5 + 5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int m, n;
vt<ll>comp;
ll st[4 * mxn + 1], a[mxn + 1], b[mxn + 1], c[mxn + 1], d[mxn + 1], dpl[mxn + 1], dpr[mxn + 1];
int findl(ll x){
    return(lower_bound(comp.begin(), comp.end(), x) - comp.begin());

}
int findr(int x){
    return(upper_bound(comp.begin(), comp.end(), x) - comp.begin() - 1);
}
void upd(int nd, int l, int r, int id, ll v){
    if(id < l || id > r)return;
    if(l == r){
        st[nd] = min(st[nd], v);
        return;
    }
    int mid = (l + r) >> 1;
    upd(nd << 1, l, mid, id, v); upd(nd << 1 | 1, mid + 1, r, id, v);
    st[nd] = min(st[nd << 1], st[nd << 1 | 1]);
}
ll get(int nd, int l, int r, int ql, int qr){
    if(ql > r | qr < l)return(inf);
    if(ql <= l && qr >= r)return(st[nd]);
    int mid = (l + r) >> 1;
    return(min(get(nd << 1, l, mid, ql, qr), get(nd << 1 | 1, mid + 1, r, ql, qr)));
}
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> m >> n;
    for(int i = 1; i <= m; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        comp.pb(c[i]);
    }
    sort(comp.begin(), comp.end());
    for(int i = 1; i <= 4 * sz(comp); i++)st[i] = inf;
    for(int i = 1; i <= m; i++){
        if(a[i] == 1){
            dpl[i] = d[i];
        }else{
            dpl[i] = min(inf, get(1, 0, sz(comp) - 1, findl(a[i]), findr(b[i]))) + d[i];
        }
        if(dpl[i] != inf){
            upd(1, 0, sz(comp) - 1, findl(c[i]), dpl[i]);
        }
        
    }
    for(int i = 1; i <= 4 * sz(comp); i++)st[i] = inf;
    for(int i = 1; i <= m; i++){
        if(b[i] == n){
            dpr[i] = d[i];
        }else{
            dpr[i] = min(inf, get(1, 0, sz(comp) - 1, findl(a[i]), findr(b[i])) + d[i]);
        }
        if(dpr[i] != inf){
            upd(1, 0, sz(comp) - 1, findl(c[i]), dpr[i]);
        }
    }
    ll ans = inf;
    for(int i = 1; i <= m; i++){
        if(dpl[i] != inf && dpr[i] != inf){
            ans = min(ans, dpl[i] + dpr[i] - d[i]);
        }
    }
    cout << ((ans == inf) ? -1 : ans);
    return(0);
}

Compilation message

pinball.cpp: In function 'long long int get(int, int, int, int, int)':
pinball.cpp:45:11: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
   45 |     if(ql > r | qr < l)return(inf);
      |        ~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 332 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 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 332 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 416 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 332 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 416 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 2 ms 476 KB Output is correct
25 Correct 14 ms 1640 KB Output is correct
26 Correct 38 ms 3484 KB Output is correct
27 Correct 118 ms 8992 KB Output is correct
28 Correct 178 ms 12952 KB Output is correct
29 Correct 80 ms 6664 KB Output is correct
30 Correct 204 ms 12952 KB Output is correct
31 Correct 177 ms 13088 KB Output is correct
32 Correct 171 ms 12908 KB Output is correct
33 Correct 21 ms 2808 KB Output is correct
34 Correct 79 ms 6656 KB Output is correct
35 Correct 106 ms 13000 KB Output is correct
36 Correct 180 ms 12932 KB Output is correct
37 Correct 157 ms 12924 KB Output is correct
38 Correct 137 ms 12876 KB Output is correct