답안 #1087685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087685 2024-09-13T05:40:39 Z Seungni 치료 계획 (JOI20_treatment) C++17
9 / 100
85 ms 13096 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
const ll inf = 0x3f3f3f3f3f3f3f3fLL;

ll N, M, sz;
pair<ll, pair<pii, ll>> arr[100005];
ll seg[200505 * 2];

void update(int pos, ll v) {
    pos += sz;
    seg[pos] = min(seg[pos], v);
    for (; pos > 0; pos >>= 1) seg[pos >> 1] = min(seg[pos], seg[pos ^ 1]);
    return;
}

ll query(int l, int r) {
    r++;
    ll ret = inf;
    for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
        if (l & 1) ret = min(ret, seg[l++]);
        if (r & 1) ret = min(ret, seg[--r]);
    }
    return ret;
}

void subtask_1() {
    vector<ll> v;
    v.push_back(0);
    v.push_back(1), v.push_back(N);
    for (int i = 0; i < M; i++) {
        v.push_back(arr[i].second.first.first);
        v.push_back(arr[i].second.first.second);
    }
    
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    
    sz = v.size();
    
    sort(arr, arr + M, [&](pair<ll, pair<pii, ll>> a, pair<ll, pair<pii, ll>> b) {
        return a.second.first.second < b.second.first.second;
    });
    for (int i = 0; i < M; i++) {
        ll L = arr[i].second.first.first, R = arr[i].second.first.second;
        L = lower_bound(v.begin(), v.end(), L) - v.begin();
        R = lower_bound(v.begin(), v.end(), R) - v.begin();
        arr[i].second.first = {L, R};
    }
    
    vector<ll> dp(sz + 5, inf);
    memset(seg, 0x3f, sizeof(seg));
    dp[0] = 0;
    update(0, dp[0]);
    
    for (int i = 0; i < M; i++) {
        ll l = arr[i].second.first.first, r = arr[i].second.first.second, c = arr[i].second.second;
        ll idx = lower_bound(v.begin(), v.end(), v[l] - 1) - v.begin();
        dp[r] = min(dp[r], query(idx, r) + c);
        update(r, dp[r]);
    }
    
    int idx = lower_bound(v.begin(), v.end(), N) - v.begin();
    if (dp[idx] == inf) cout << -1;
    else cout << dp[idx];
    return;
}

void subtask_2() {
    ll ans = inf;
    
    sort(arr, arr + M);
    
    for (int i = 0; i < (1 << M); i++) {
        vector<int> v;
        ll cost = 0;
        for (int j = 0; j < M; j++) {
            if (i & (1 << j)) v.push_back(j), cost += arr[j].second.second;
        }
        
        vector<pair<pii, ll>> now;
        now.push_back({{1, N}, 0});
        
        for (int j: v) {
            vector<pair<pii, ll>> nxt;
            ll T = arr[j].first, L = arr[j].second.first.first, R = arr[j].second.first.second;
            for (auto &[range, t]: now) {
                ll l = range.first, r = range.second;
                l -= T - t, l = max(l, 1LL);
                r += T - t, r = min(r, N);
                if (l < L) nxt.push_back({{l, min(r, L - 1)}, T});
                if (r > R) nxt.push_back({{max(l, R + 1), r}, T});
            }
            swap(nxt, now);
        }
        
        if (now.empty()) ans = min(ans, cost);
    }
    
    if (ans == inf) cout << -1;
    else cout << ans;
    
    return;
}

void solve() {
    cin >> N >> M;
    
    int sub_task1 = 1, sub_task2 = (M <= 16);
    
    for (int i = 0; i < M; i++) {
        ll T, L, R, C;
        cin >> T >> L >> R >> C;
        if (T != 1) sub_task1 = 0;
        arr[i] = {T, {{L, R}, C}};
    }
    
    if (sub_task1) {
        subtask_1();
        return;
    }
    
    if (sub_task2) {
        subtask_2();
        return;
    }
    
    return;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 13096 KB Output is correct
2 Correct 61 ms 13000 KB Output is correct
3 Correct 54 ms 10700 KB Output is correct
4 Correct 67 ms 10624 KB Output is correct
5 Correct 37 ms 11468 KB Output is correct
6 Correct 40 ms 11464 KB Output is correct
7 Correct 42 ms 11464 KB Output is correct
8 Correct 39 ms 11356 KB Output is correct
9 Correct 40 ms 11476 KB Output is correct
10 Correct 44 ms 11464 KB Output is correct
11 Correct 85 ms 12744 KB Output is correct
12 Correct 78 ms 12488 KB Output is correct
13 Correct 77 ms 12996 KB Output is correct
14 Correct 72 ms 12864 KB Output is correct
15 Correct 72 ms 13000 KB Output is correct
16 Correct 66 ms 13000 KB Output is correct
17 Correct 62 ms 12216 KB Output is correct
18 Correct 73 ms 11968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 22 ms 476 KB Output is correct
3 Correct 22 ms 348 KB Output is correct
4 Correct 48 ms 344 KB Output is correct
5 Correct 42 ms 344 KB Output is correct
6 Correct 21 ms 344 KB Output is correct
7 Correct 36 ms 344 KB Output is correct
8 Correct 44 ms 600 KB Output is correct
9 Correct 31 ms 592 KB Output is correct
10 Correct 43 ms 348 KB Output is correct
11 Correct 50 ms 348 KB Output is correct
12 Correct 31 ms 348 KB Output is correct
13 Correct 24 ms 344 KB Output is correct
14 Correct 21 ms 348 KB Output is correct
15 Correct 23 ms 480 KB Output is correct
16 Correct 35 ms 348 KB Output is correct
17 Correct 48 ms 452 KB Output is correct
18 Correct 21 ms 344 KB Output is correct
19 Correct 37 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 22 ms 476 KB Output is correct
3 Correct 22 ms 348 KB Output is correct
4 Correct 48 ms 344 KB Output is correct
5 Correct 42 ms 344 KB Output is correct
6 Correct 21 ms 344 KB Output is correct
7 Correct 36 ms 344 KB Output is correct
8 Correct 44 ms 600 KB Output is correct
9 Correct 31 ms 592 KB Output is correct
10 Correct 43 ms 348 KB Output is correct
11 Correct 50 ms 348 KB Output is correct
12 Correct 31 ms 348 KB Output is correct
13 Correct 24 ms 344 KB Output is correct
14 Correct 21 ms 348 KB Output is correct
15 Correct 23 ms 480 KB Output is correct
16 Correct 35 ms 348 KB Output is correct
17 Correct 48 ms 452 KB Output is correct
18 Correct 21 ms 344 KB Output is correct
19 Correct 37 ms 348 KB Output is correct
20 Incorrect 2 ms 608 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 13096 KB Output is correct
2 Correct 61 ms 13000 KB Output is correct
3 Correct 54 ms 10700 KB Output is correct
4 Correct 67 ms 10624 KB Output is correct
5 Correct 37 ms 11468 KB Output is correct
6 Correct 40 ms 11464 KB Output is correct
7 Correct 42 ms 11464 KB Output is correct
8 Correct 39 ms 11356 KB Output is correct
9 Correct 40 ms 11476 KB Output is correct
10 Correct 44 ms 11464 KB Output is correct
11 Correct 85 ms 12744 KB Output is correct
12 Correct 78 ms 12488 KB Output is correct
13 Correct 77 ms 12996 KB Output is correct
14 Correct 72 ms 12864 KB Output is correct
15 Correct 72 ms 13000 KB Output is correct
16 Correct 66 ms 13000 KB Output is correct
17 Correct 62 ms 12216 KB Output is correct
18 Correct 73 ms 11968 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 22 ms 476 KB Output is correct
21 Correct 22 ms 348 KB Output is correct
22 Correct 48 ms 344 KB Output is correct
23 Correct 42 ms 344 KB Output is correct
24 Correct 21 ms 344 KB Output is correct
25 Correct 36 ms 344 KB Output is correct
26 Correct 44 ms 600 KB Output is correct
27 Correct 31 ms 592 KB Output is correct
28 Correct 43 ms 348 KB Output is correct
29 Correct 50 ms 348 KB Output is correct
30 Correct 31 ms 348 KB Output is correct
31 Correct 24 ms 344 KB Output is correct
32 Correct 21 ms 348 KB Output is correct
33 Correct 23 ms 480 KB Output is correct
34 Correct 35 ms 348 KB Output is correct
35 Correct 48 ms 452 KB Output is correct
36 Correct 21 ms 344 KB Output is correct
37 Correct 37 ms 348 KB Output is correct
38 Incorrect 2 ms 608 KB Output isn't correct
39 Halted 0 ms 0 KB -