답안 #931105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931105 2024-02-21T08:43:35 Z parlimoos Pinball (JOI14_pinball) C++14
100 / 100
252 ms 36180 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'

const ll INF = (1ll * 1e18);

int k , n , m;
vector<arr(4)> a;
vector<int> ns;
ll seg[1200001][2];
int seginf[1200001][2] , is[300001];
int cnt = 0;

void frm(int &el){
    el = int(lb(ns.bg() , ns.end() , el) - ns.bg());
}
void buildSeg(int l = 0 , int r = cnt - 1 , int i = 1){
    seginf[i][0] = l , seginf[i][1] = r , seg[i][0] = INF , seg[i][1] = INF;
    if(r == l) is[l] = i;
    else{
        int c = (r + l - 1) >> 1;
        buildSeg(l , c , i << 1) , buildSeg(c + 1 , r , (i << 1) | 1);
    }
}
void updSeg(int md , int i , ll val){
    while(i >= 1){
        seg[i][md] = min(seg[i][md] , val);
        i >>= 1;
    }
}
ll getSeg(int l , int r , int md , int i){
    if(seginf[i][0] >= l and seginf[i][1] <= r){
        // cout << seg[0][3] << "$\n";
        return seg[i][md];
    }
    if(seginf[i][1] >= l and seginf[i][0] <= r) return min(getSeg(l , r , md , i << 1) , getSeg(l , r , md , (i << 1) | 1));
    return INF;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> k >> n;
    m = k + 2;
    ns.pb(1);
    for(int i = 0 ; i < k ; i++){
        int d[4];
        cin >> d[0] >> d[1] >> d[2] >> d[3];
        a.pb({d[0] , d[2] , d[1] , d[3]});
        ns.pb(d[0]) , ns.pb(d[1]) , ns.pb(d[2]);
        if(m <= 1000) ns.pb(min(n , d[1] + 1));
    }
    sort(ns.bg() , ns.end()) , ns.resize(int(unique(ns.bg() , ns.end()) - ns.bg()));
    cnt = (int)ns.size();
    for(int i = 0 ; i < k ; i++) frm(a[i][0]) , frm(a[i][1]) , frm(a[i][2]);
    
    buildSeg();
    updSeg(0 , is[0] , 0) , updSeg(1 , is[cnt - 1] , 0);
    ll o = INF;
    for(int i = 0 ; i < k ; i++){
        o = min(o , getSeg(a[i][0] , a[i][2] , 0 , 1) + getSeg(a[i][0] , a[i][2] , 1 , 1) + (1ll * a[i][3]));
        ll d1 = INF , d2 = INF;
        if(a[i][0] < a[i][1]) d1 = getSeg(a[i][0] , a[i][1] - 1 , 0 , 1) + (1ll * a[i][3]);
        if(a[i][1] < a[i][2]) d2 = getSeg(a[i][1] + 1 , a[i][2] , 1 , 1) + (1ll * a[i][3]);
        // cout << i << " : " << d1 << " " << d2 << "!\n";
        updSeg(0 , is[a[i][1]] , d1) , updSeg(1 , is[a[i][1]] , d2);
    }
    if(o == INF) cout << -1;
    else cout << o;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4440 KB Output is correct
25 Correct 17 ms 4824 KB Output is correct
26 Correct 47 ms 7620 KB Output is correct
27 Correct 139 ms 12836 KB Output is correct
28 Correct 126 ms 7340 KB Output is correct
29 Correct 98 ms 12228 KB Output is correct
30 Correct 172 ms 7348 KB Output is correct
31 Correct 219 ms 19816 KB Output is correct
32 Correct 200 ms 13740 KB Output is correct
33 Correct 26 ms 7380 KB Output is correct
34 Correct 93 ms 18432 KB Output is correct
35 Correct 135 ms 32304 KB Output is correct
36 Correct 252 ms 36180 KB Output is correct
37 Correct 191 ms 36020 KB Output is correct
38 Correct 187 ms 36168 KB Output is correct