Submission #917693

# Submission time Handle Problem Language Result Execution time Memory
917693 2024-01-28T15:08:17 Z LOLOLO Treatment Project (JOI20_treatment) C++17
0 / 100
3000 ms 19396 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] == 0) {
            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 == 1e16)
        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];
        l[i]--;
    }

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

            if (t[i] <= t[j]) {
                int d = abs(t[i] - t[j]);
                int L = l[i] + d, R = r[i] - d;
                if (max(L, l[j]) <= min(R, r[j])) {
                    ed[i].pb(j);
                    ed[j].pb(i);
                    //cout << " bruh\n";
                }
            }
        }
    }

    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 Execution timed out 3060 ms 19396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Incorrect 4 ms 14992 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 4 ms 14992 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3060 ms 19396 KB Time limit exceeded
2 Halted 0 ms 0 KB -