답안 #538173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
538173 2022-03-16T07:29:06 Z wiwiho 치료 계획 (JOI20_treatment) C++14
39 / 100
3000 ms 269800 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 1LL << 60;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

ll ifloor(ll a, ll b){
    if(b < 0) a *= -1, b *= -1;
    if(a < 0) return (a - b + 1) / b;
    else return a / b;
}

ll iceil(ll a, ll b){
    if(b < 0) a *= -1, b *= -1;
    if(a > 0) return (a + b - 1) / b;
    else return a / b;
}

struct treat{
    ll t, l, r, c;
};

int n, K, m;
vector<ll> dis;
vector<treat> a;
std::priority_queue<pll, vector<pll>, greater<>> pq;

#define lc (2 * id + 1)
#define rc (2 * id + 2)

struct SegmentTree{
    vector<set<pll>> st;

    void init(){
        st.resize(4 * m);
    }

    void add(int x, pll v, int L = 0, int R = m - 1, int id = 0){
        //cerr << "add " << v << " " << id << "\n";
        st[id].insert(v);
        if(L == R){
            return;
        }
        int M = (L + R) / 2;
        if(x <= M) add(x, v, L, M, lc);
        else add(x, v, M + 1, R, rc);
    }

    void relax(int l, int r, int mx, ll d, int L = 0, int R = m - 1, int id = 0){
        if(l <= L && R <= r){
            //cerr << "sgt relax " << l << " " << r << " " << L << " " << R << " " << id << "\n";
            //printv(st[id], cerr);
            while(!st[id].empty() && st[id].begin()->F <= mx){
                int now = st[id].begin()->S;
                if(dis[now] <= d + a[now].c){
                    st[id].erase(st[id].begin());
                    continue;
                }
                //cerr << "ok " << now << "\n";
                dis[now] = d + a[now].c;
                pq.push(mp(dis[now], now));
                st[id].erase(st[id].begin());
            }
            return;
        }
        int M = (L + R) / 2;
        if(r <= M) relax(l, r, mx, d, L, M, lc);
        else if(l > M) relax(l, r, mx, d, M + 1, R, rc);
        else{
            relax(l, r, mx, d, L, M, lc);
            relax(l, r, mx, d, M + 1, R, rc);
        }
    }

};

int main(){
    StarBurstStream

    cin >> n >> K;
    a.resize(K + 1);
    dis.resize(K + 1, MAX);

    vector<int> tmp;

    SegmentTree st1, st2;

    for(int i = 1; i <= K; i++){
        cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
        tmp.eb(a[i].t);
    }
    lsort(tmp);
    uni(tmp);
    m = tmp.size();
    st1.init(); st2.init();

    for(int i = 1; i <= K; i++){
        int x = lower_bound(iter(tmp), a[i].t) - tmp.begin();
        st1.add(x, mp(-(a[i].t - a[i].l), i));
        st2.add(x, mp(a[i].t + a[i].l, i));
    }

    for(int i = 1; i <= K; i++){
        if(a[i].l == 1){
            dis[i] = a[i].c;
            pq.push(mp(a[i].c, i));
        }
    }
    
    while(!pq.empty()){
        int now = pq.top().S;
        ll d = pq.top().F;
        pq.pop();
        if(d != dis[now]) continue;
        int x = lower_bound(iter(tmp), a[now].t) - tmp.begin();
        //cerr << "relax1 " << now << "\n";
        st1.relax(0, x, -(a[now].t - a[now].r - 1), d);
        //cerr << "relax2 " << now << "\n";
        st2.relax(x, m - 1, a[now].r + a[now].t + 1, d);
    }

    ll ans = MAX;
    for(int i = 1; i <= K; i++){
        if(a[i].r == n){
            ans = min(ans, dis[i]);
        }
    }
    if(ans == MAX) ans = -1;
    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 19872 KB Output is correct
2 Correct 135 ms 19756 KB Output is correct
3 Correct 131 ms 19940 KB Output is correct
4 Correct 110 ms 19460 KB Output is correct
5 Correct 110 ms 21820 KB Output is correct
6 Correct 104 ms 19832 KB Output is correct
7 Correct 90 ms 19664 KB Output is correct
8 Correct 95 ms 19660 KB Output is correct
9 Correct 88 ms 19660 KB Output is correct
10 Correct 92 ms 19648 KB Output is correct
11 Correct 141 ms 21976 KB Output is correct
12 Correct 173 ms 21852 KB Output is correct
13 Correct 178 ms 21800 KB Output is correct
14 Correct 163 ms 21836 KB Output is correct
15 Correct 174 ms 19612 KB Output is correct
16 Correct 158 ms 19652 KB Output is correct
17 Correct 136 ms 18900 KB Output is correct
18 Correct 159 ms 21152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 44 ms 9348 KB Output is correct
21 Correct 39 ms 9432 KB Output is correct
22 Correct 31 ms 7116 KB Output is correct
23 Correct 45 ms 7260 KB Output is correct
24 Correct 53 ms 11144 KB Output is correct
25 Correct 43 ms 10992 KB Output is correct
26 Correct 33 ms 10880 KB Output is correct
27 Correct 42 ms 10928 KB Output is correct
28 Correct 64 ms 11048 KB Output is correct
29 Correct 47 ms 10964 KB Output is correct
30 Correct 29 ms 10964 KB Output is correct
31 Correct 30 ms 10832 KB Output is correct
32 Correct 54 ms 11196 KB Output is correct
33 Correct 41 ms 11168 KB Output is correct
34 Correct 38 ms 9804 KB Output is correct
35 Correct 55 ms 11152 KB Output is correct
36 Correct 42 ms 11116 KB Output is correct
37 Correct 49 ms 9792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 19872 KB Output is correct
2 Correct 135 ms 19756 KB Output is correct
3 Correct 131 ms 19940 KB Output is correct
4 Correct 110 ms 19460 KB Output is correct
5 Correct 110 ms 21820 KB Output is correct
6 Correct 104 ms 19832 KB Output is correct
7 Correct 90 ms 19664 KB Output is correct
8 Correct 95 ms 19660 KB Output is correct
9 Correct 88 ms 19660 KB Output is correct
10 Correct 92 ms 19648 KB Output is correct
11 Correct 141 ms 21976 KB Output is correct
12 Correct 173 ms 21852 KB Output is correct
13 Correct 178 ms 21800 KB Output is correct
14 Correct 163 ms 21836 KB Output is correct
15 Correct 174 ms 19612 KB Output is correct
16 Correct 158 ms 19652 KB Output is correct
17 Correct 136 ms 18900 KB Output is correct
18 Correct 159 ms 21152 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 316 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 44 ms 9348 KB Output is correct
39 Correct 39 ms 9432 KB Output is correct
40 Correct 31 ms 7116 KB Output is correct
41 Correct 45 ms 7260 KB Output is correct
42 Correct 53 ms 11144 KB Output is correct
43 Correct 43 ms 10992 KB Output is correct
44 Correct 33 ms 10880 KB Output is correct
45 Correct 42 ms 10928 KB Output is correct
46 Correct 64 ms 11048 KB Output is correct
47 Correct 47 ms 10964 KB Output is correct
48 Correct 29 ms 10964 KB Output is correct
49 Correct 30 ms 10832 KB Output is correct
50 Correct 54 ms 11196 KB Output is correct
51 Correct 41 ms 11168 KB Output is correct
52 Correct 38 ms 9804 KB Output is correct
53 Correct 55 ms 11152 KB Output is correct
54 Correct 42 ms 11116 KB Output is correct
55 Correct 49 ms 9792 KB Output is correct
56 Correct 2166 ms 236100 KB Output is correct
57 Correct 2109 ms 236496 KB Output is correct
58 Correct 1878 ms 234740 KB Output is correct
59 Correct 1859 ms 235180 KB Output is correct
60 Correct 1684 ms 191656 KB Output is correct
61 Correct 1905 ms 234700 KB Output is correct
62 Correct 2140 ms 236172 KB Output is correct
63 Correct 1855 ms 266968 KB Output is correct
64 Correct 1741 ms 266904 KB Output is correct
65 Correct 257 ms 32964 KB Output is correct
66 Correct 1761 ms 191724 KB Output is correct
67 Correct 2293 ms 267668 KB Output is correct
68 Correct 1491 ms 267536 KB Output is correct
69 Correct 1254 ms 262676 KB Output is correct
70 Correct 2574 ms 267852 KB Output is correct
71 Correct 1900 ms 267612 KB Output is correct
72 Correct 1335 ms 267512 KB Output is correct
73 Correct 2779 ms 267740 KB Output is correct
74 Correct 1777 ms 267604 KB Output is correct
75 Correct 1270 ms 267572 KB Output is correct
76 Correct 2825 ms 246744 KB Output is correct
77 Correct 2897 ms 269800 KB Output is correct
78 Execution timed out 3033 ms 246564 KB Time limit exceeded
79 Halted 0 ms 0 KB -