Submission #917740

# Submission time Handle Problem Language Result Execution time Memory
917740 2024-01-28T17:03:41 Z LOLOLO Treatment Project (JOI20_treatment) C++17
0 / 100
1821 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())

const int N = 3e5 + 10;
const int lim = 1e7 + 10;
int t[N], l[N], r[N];
int n, m;
ll dp[N], c[N];

vector <int> ed[N];

ll run() {
    set <pair <ll, ll>> save;
    for (int i = 1; i <= m; i++) {
        if (l[i] == 1) {
            save.insert({c[i], i});
            dp[i] = min(dp[i], c[i]);
        }
    }

    while (sz(save)) {
        auto t = *(save.begin());
        save.erase(t);
        if (dp[t.s] < t.f)
            continue;

        for (auto x : ed[t.s]) {
            if (dp[x] > t.f + c[x]) {
                dp[x] = t.f + c[x];
                save.insert({dp[x], x});
            }
        }
    }

    ll ans = 1e16;
    for (int i = 1; i <= m; i++) {
        if (r[i] == n)
            ans = min(ans, dp[i]);
    }

    if (ans > 1e14)
        return -1;

    return ans;
}

ll solve() {
    mem(dp, 0x3f);
    cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        cin >> t[i] >> l[i] >> r[i] >> c[i];
    }

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= m; j++) {
            if (i == j)
                continue;

            if (abs(t[i] - t[j]) <= r[i] - l[j] + 1) {
                ed[i].pb(j);
                ed[j].pb(i);
            }
        }
    }

    return run();
}

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

    int t = 1;
    //cin >> t;

    while (t--) {
        //solve();
        cout << solve() << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1821 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Incorrect 5 ms 14940 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Incorrect 5 ms 14940 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1821 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -