제출 #1332596

#제출 시각아이디문제언어결과실행 시간메모리
1332596SzymonKrzywda치료 계획 (JOI20_treatment)C++20
0 / 100
3093 ms4472 KiB
#include <iostream>
#include <vector>
#include <algorithm>

#define int ll

using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define ff first
#define ss second

const int MAXM = 1e5 + 7;
ll dp[MAXM];


bool inter(int a, int b, int d, int a2, int b2, int d2) {
    int r = abs(d - d2);
    if (b > b2) {
        swap(a, a2);
        swap(b, b2);
    }
    b -= r;
    return (b + 1) >= a2;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, m, a, b, c, d;
    cin >> n >> m;

    vector<pair<pii, pii>> tab;
    for (int i = 0; i < m; i++) {
        cin >> a >> b >> c >> d;
        tab.push_back({{c, b}, {a, d}});
    }
    sort(tab.begin(), tab.end());


    ll ans = 1e18;

    for (int i = 0; i < m; i++) {
        int l = tab[i].ff.ss;
        int r = tab[i].ff.ff;
        int t = tab[i].ss.ff;
        int c = tab[i].ss.ss;
        dp[i] = 1e18;
        if (l == 1) {
            dp[i] = c;
            //cout << l << ' ' << r << ' ' << t << ' ' << c << ' ' << dp[i] << '\n';
            continue;
        }

        for (int j = 0; j < i; j++) {
            if (inter(l, r, t, tab[j].ff.ss, tab[j].ff.ff, tab[j].ss.ff)) {
                dp[i] = min(dp[i], dp[j] + c);
               // cout << "OH: " << l << ' ' << r << ' ' << t << ' ' << c << ": " << tab[j].ff.ss << ' ' << tab[j].ff.ff << ' ' << tab[j].ss.ff << ' ' << dp[j] + c << '\n';
            }
        }
       // cout << l << ' ' << r << ' ' << t << ' ' << c << ' ' << dp[i] << '\n';

        if (r == n) ans = min(ans, dp[i]);
        
    }
    if (ans == 1e18) ans = -1;
    cout << ans << '\n';





    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...