답안 #1087594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087594 2024-09-13T02:17:50 Z Seungni 치료 계획 (JOI20_treatment) C++17
4 / 100
89 ms 12372 KB
#include <bits/stdc++.h>

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

ll N, M, sz;
pair<ll, pair<pii, ll>> arr[100005];
ll dp[200505];
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 solve() {
    cin >> N >> M;
    vector<ll> v;
    v.push_back(0);
    v.push_back(1), v.push_back(N);
    
    for (int i = 0; i < M; i++) {
        ll T, L, R, C;
        cin >> T >> L >> R >> C;
        v.push_back(L), v.push_back(R);
        arr[i] = {T, {{L, R}, C}};
    }
    
    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};
    }
    
    memset(dp, 0x3f, sizeof(dp));
    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;
}

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 67 ms 12372 KB Output is correct
2 Correct 58 ms 12240 KB Output is correct
3 Correct 55 ms 11200 KB Output is correct
4 Correct 55 ms 11204 KB Output is correct
5 Correct 37 ms 12232 KB Output is correct
6 Correct 43 ms 12232 KB Output is correct
7 Correct 55 ms 12232 KB Output is correct
8 Correct 38 ms 12232 KB Output is correct
9 Correct 39 ms 12276 KB Output is correct
10 Correct 42 ms 12232 KB Output is correct
11 Correct 78 ms 12228 KB Output is correct
12 Correct 89 ms 12116 KB Output is correct
13 Correct 72 ms 12084 KB Output is correct
14 Correct 69 ms 12236 KB Output is correct
15 Correct 71 ms 12228 KB Output is correct
16 Correct 65 ms 12236 KB Output is correct
17 Correct 66 ms 11464 KB Output is correct
18 Correct 74 ms 11528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Incorrect 2 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Incorrect 2 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 12372 KB Output is correct
2 Correct 58 ms 12240 KB Output is correct
3 Correct 55 ms 11200 KB Output is correct
4 Correct 55 ms 11204 KB Output is correct
5 Correct 37 ms 12232 KB Output is correct
6 Correct 43 ms 12232 KB Output is correct
7 Correct 55 ms 12232 KB Output is correct
8 Correct 38 ms 12232 KB Output is correct
9 Correct 39 ms 12276 KB Output is correct
10 Correct 42 ms 12232 KB Output is correct
11 Correct 78 ms 12228 KB Output is correct
12 Correct 89 ms 12116 KB Output is correct
13 Correct 72 ms 12084 KB Output is correct
14 Correct 69 ms 12236 KB Output is correct
15 Correct 71 ms 12228 KB Output is correct
16 Correct 65 ms 12236 KB Output is correct
17 Correct 66 ms 11464 KB Output is correct
18 Correct 74 ms 11528 KB Output is correct
19 Correct 3 ms 5120 KB Output is correct
20 Incorrect 2 ms 4956 KB Output isn't correct
21 Halted 0 ms 0 KB -