Submission #1092209

# Submission time Handle Problem Language Result Execution time Memory
1092209 2024-09-23T14:50:22 Z anhthi Treatment Project (JOI20_treatment) C++14
0 / 100
3000 ms 37372 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)

template <class X, class Y>
    inline bool maximize(X &x, Y y) {
        return (x < y ? x = y, true : false);
    }

template <class X, class Y>
    inline bool minimize(X &x, Y y) {
        return (x > y ? x = y, true : false);
    }

template <class X>
    inline void compress(vector<X> &a) {
        sort(all(a));
        a.resize(unique(all(a)) - a.begin());
    }

int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
    return l + abs((ll) rng()) % (r - l + 1);
}

const ll oo = (ll) 1e17;
const int inf = (ll) 2e9 + 7, mod = (ll) 1e9 + 7;

const int mxn = 2e5 + 5;

void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }

int n, m;

struct Treat {
    ll t, l, r, c;
    void input() {
        cin >> t >> l >> r >> c;
    }
} treat[mxn];

ll pos[mxn];
ll f[mxn];

priority_queue<pair<ll, ll>> mn1[mxn], mn2[mxn];

int main(void) {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define TASK "task"
    if (fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    cin >> n >> m;
    rep(i, m) treat[i].input();

    vector<ll> cps;
    rep(i, m) cps.pb(treat[i].t);

    compress(cps);
    int len = sz(cps);

    rep(i, m) {
        pos[i] = lower_bound(all(cps), treat[i].t) - cps.begin() + 1;
        for (int p = pos[i]; p <= n; p += p & -p) {
            mn1[p].push(mp(-(treat[i].l - treat[i].t), i));
        }
        for (int p = pos[i]; p > 0; p -= p & -p) {
            mn2[p].push(mp(-(treat[i].l + treat[i].t), i));
        }
    }

    memset(f, 0x3f, sizeof f);
    priority_queue<pair<ll, ll>> pq;
    forn(i, 1, m) if (treat[i].l == 1) {
        f[i] = treat[i].c;
        pq.push({-f[i], i});
    }

    while (!pq.empty()) {
        pair<ll, ll> top = pq.top(); pq.pop();
        int u = top.se; ll dist = -top.fi;

        if (f[u] != dist) continue;
        for (int p = pos[u]; p > 0; p -= p & -p) {
            while (!mn1[p].empty()) {
                pair<ll, ll> top = mn1[p].top();
                if (-top.fi > treat[u].r - treat[u].t + 1) break;
                if (minimize(f[top.se], dist + treat[top.se].c)) {
                    mn1[p].pop();
                    pq.push(mp(-f[top.se], top.se));
                }
            }
        }
        for (int p = pos[u]; p <= n; p += p & -p) {
            while (!mn2[p].empty()) {
                pair<ll, ll> top = mn2[p].top();
                if (-top.fi > treat[u].r + treat[u].t + 1) break;
                if (minimize(f[top.se], dist + treat[top.se].c)) {
                    mn2[p].pop();
                    pq.push(mp(-f[top.se], top.se));
                }
            }
        }
    }
    ll ans = oo;
    rep(i, m) if (treat[i].r == n)
        minimize(ans, f[i]);

    cout << (ans == oo ? -1 : ans) << '\n';

    return 0;
}

Compilation message

treatment.cpp: In function 'int main()':
treatment.cpp:85:9: warning: unused variable 'len' [-Wunused-variable]
   85 |     int len = sz(cps);
      |         ^~~
treatment.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
treatment.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 37372 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3041 ms 14428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3041 ms 14428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 37372 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -