Submission #675001

# Submission time Handle Problem Language Result Execution time Memory
675001 2022-12-26T18:40:41 Z urosk Treatment Project (JOI20_treatment) C++14
39 / 100
3000 ms 218968 KB
#include "bits/stdc++.h"
#define here cerr<<"===========================================\n"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-finline")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fno-stack-protector")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-funroll-loops")

#pragma GCC target("abm")
#pragma GCC target("avx")
#pragma GCC target("mmx")
#pragma GCC target("popcnt")
#pragma GCC target("sse")
#pragma GCC target("sse2")
#pragma GCC target("sse3")
#pragma GCC target("sse4")
#pragma GCC target("ssse3")
#pragma GCC target("tune=native")
#define dbg(x) cerr<<#x<<": "<<x<<endl;
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;}

#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);

using namespace std;
//using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
    x+=y;
    if(x<0){
        x%=mod;
        x+=mod;
    }else{
        if(x>=mod) x%=mod;
    }
    return x;
}
ll mul(ll a,ll b){
	ll ans = (a*b)%mod;
	if(ans<0) ans+=mod;
	return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
    return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 100005
#define maxx 400025
ll n,m;
struct tupl{
    ll t,l,r,c;
} a[maxn];
ll tsz = 1,tsz2 = 1;
set<pair<int,int> > t[4*maxn];
set<pair<int,int> > t2[4*maxn];
void upd(ll v,ll tl,ll tr,ll i,pll p,bool f){
    if(f) t[v].insert(p);
    else t[v].erase(p);
    if(tl==tr) return;
    ll mid = (tl+tr)/2;
    if(i<=mid) upd(2*v,tl,mid,i,p,f);
    else upd(2*v+1,mid+1,tr,i,p,f);
}
void upd2(ll v,ll tl,ll tr,ll i,pll p,bool f){
    if(f) t2[v].insert(p);
    else t2[v].erase(p);
    if(tl==tr) return;
    ll mid = (tl+tr)/2;
    if(i<=mid) upd2(2*v,tl,mid,i,p,f);
    else upd2(2*v+1,mid+1,tr,i,p,f);
}
set<ll> s;
void get(ll v,ll tl,ll tr,ll l,ll r,ll x){
    if(l>r) return;
    if(tl==l&&tr==r){
        auto it = t[v].begin();
        while(it!=t[v].end()&&(*it).fi<=x){
            s.insert((*it).sc);
            it++;
        }
        return;
    }
    ll mid = (tl+tr)/2;
    get(2*v,tl,mid,l,min(mid,r),x);
    get(2*v+1,mid+1,tr,max(mid+1,l),r,x);
}
void get2(ll v,ll tl,ll tr,ll l,ll r,ll x){
    if(l>r) return;
    if(tl==l&&tr==r){
        auto it = t2[v].begin();
        while(it!=t2[v].end()&&(*it).fi<=x){
            s.insert((*it).sc);
            it++;
        }
        return;
    }
    ll mid = (tl+tr)/2;
    get2(2*v,tl,mid,l,min(mid,r),x);
    get2(2*v+1,mid+1,tr,max(mid+1,l),r,x);
}
ll d[maxn];
set<ll> st;
map<ll,ll> mp;
ll it = 0;
void tc(){
    cin >> m >> n;
    for(ll i = 1;i<=n;i++) cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
    for(ll i = 1;i<=n;i++) a[i].l--;
    for(ll i = 1;i<=n;i++) st.insert(a[i].t);
    for(ll x : st) mp[x] = ++it;
    ll mxt = it;
    for(ll i = 1;i<=n;i++){
        if(a[i].l==0) continue;
        upd(1,1,mxt,mp[a[i].t],{a[i].l+a[i].t,i},1);
        upd2(1,1,mxt,mp[a[i].t],{a[i].l-a[i].t,i},1);
    }
    for(ll i = 1;i<=n;i++) d[i] = llinf;
    priority_queue<pll> pq;
    for(ll i = 1;i<=n;i++){
        if(a[i].l==0){
            d[i] = a[i].c;
            pq.push({-d[i],i});
        }
    }
    while(sz(pq)){
        pll p = pq.top();
        ll i = p.sc;
        pq.pop();
        if(-p.fi!=d[i]) continue;
        s.clear();
        get(1,1,mxt,mp[a[i].t],mxt,a[i].r+a[i].t);
        get2(1,1,mxt,1,mp[a[i].t],a[i].r-a[i].t);
        for(ll j : s){
            if(j==i) continue;
            d[j] = d[i] + a[j].c;
            upd(1,1,mxt,mp[a[j].t],{a[j].l+a[j].t,j},0);
            upd2(1,1,mxt,mp[a[j].t],{a[j].l-a[j].t,j},0);
            pq.push({-d[j],j});
        }
    }
    ll ans = llinf;
    for(ll i = 1;i<=n;i++) if(a[i].r==m) ans = min(ans,d[i]);
    if(ans==llinf) ans = -1;
    cout<<ans<<endl;
}
int main(){
	daj_mi_malo_vremena
    int t; t = 1;
    while(t--){
        tc();
    }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 162 ms 51280 KB Output is correct
2 Correct 124 ms 51184 KB Output is correct
3 Correct 120 ms 49888 KB Output is correct
4 Correct 127 ms 49876 KB Output is correct
5 Correct 137 ms 53260 KB Output is correct
6 Correct 120 ms 51412 KB Output is correct
7 Correct 107 ms 51192 KB Output is correct
8 Correct 96 ms 51040 KB Output is correct
9 Correct 92 ms 51112 KB Output is correct
10 Correct 76 ms 51148 KB Output is correct
11 Correct 234 ms 56652 KB Output is correct
12 Correct 222 ms 54468 KB Output is correct
13 Correct 198 ms 53316 KB Output is correct
14 Correct 182 ms 53324 KB Output is correct
15 Correct 162 ms 51172 KB Output is correct
16 Correct 170 ms 51264 KB Output is correct
17 Correct 202 ms 51148 KB Output is correct
18 Correct 219 ms 55724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 37844 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 18 ms 37832 KB Output is correct
4 Correct 20 ms 37964 KB Output is correct
5 Correct 17 ms 37832 KB Output is correct
6 Correct 19 ms 37972 KB Output is correct
7 Correct 18 ms 37900 KB Output is correct
8 Correct 17 ms 37844 KB Output is correct
9 Correct 18 ms 37912 KB Output is correct
10 Correct 17 ms 37844 KB Output is correct
11 Correct 17 ms 37820 KB Output is correct
12 Correct 18 ms 37804 KB Output is correct
13 Correct 18 ms 37844 KB Output is correct
14 Correct 18 ms 37828 KB Output is correct
15 Correct 18 ms 37884 KB Output is correct
16 Correct 17 ms 37844 KB Output is correct
17 Correct 18 ms 37872 KB Output is correct
18 Correct 17 ms 37912 KB Output is correct
19 Correct 18 ms 37828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 37844 KB Output is correct
2 Correct 21 ms 37844 KB Output is correct
3 Correct 18 ms 37832 KB Output is correct
4 Correct 20 ms 37964 KB Output is correct
5 Correct 17 ms 37832 KB Output is correct
6 Correct 19 ms 37972 KB Output is correct
7 Correct 18 ms 37900 KB Output is correct
8 Correct 17 ms 37844 KB Output is correct
9 Correct 18 ms 37912 KB Output is correct
10 Correct 17 ms 37844 KB Output is correct
11 Correct 17 ms 37820 KB Output is correct
12 Correct 18 ms 37804 KB Output is correct
13 Correct 18 ms 37844 KB Output is correct
14 Correct 18 ms 37828 KB Output is correct
15 Correct 18 ms 37884 KB Output is correct
16 Correct 17 ms 37844 KB Output is correct
17 Correct 18 ms 37872 KB Output is correct
18 Correct 17 ms 37912 KB Output is correct
19 Correct 18 ms 37828 KB Output is correct
20 Correct 45 ms 42668 KB Output is correct
21 Correct 46 ms 42708 KB Output is correct
22 Correct 52 ms 42752 KB Output is correct
23 Correct 47 ms 42780 KB Output is correct
24 Correct 56 ms 44196 KB Output is correct
25 Correct 58 ms 44716 KB Output is correct
26 Correct 55 ms 44876 KB Output is correct
27 Correct 53 ms 44840 KB Output is correct
28 Correct 55 ms 43892 KB Output is correct
29 Correct 59 ms 44792 KB Output is correct
30 Correct 45 ms 44788 KB Output is correct
31 Correct 46 ms 44876 KB Output is correct
32 Correct 69 ms 45048 KB Output is correct
33 Correct 74 ms 45008 KB Output is correct
34 Correct 71 ms 44280 KB Output is correct
35 Correct 78 ms 45084 KB Output is correct
36 Correct 72 ms 45104 KB Output is correct
37 Correct 63 ms 44364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 51280 KB Output is correct
2 Correct 124 ms 51184 KB Output is correct
3 Correct 120 ms 49888 KB Output is correct
4 Correct 127 ms 49876 KB Output is correct
5 Correct 137 ms 53260 KB Output is correct
6 Correct 120 ms 51412 KB Output is correct
7 Correct 107 ms 51192 KB Output is correct
8 Correct 96 ms 51040 KB Output is correct
9 Correct 92 ms 51112 KB Output is correct
10 Correct 76 ms 51148 KB Output is correct
11 Correct 234 ms 56652 KB Output is correct
12 Correct 222 ms 54468 KB Output is correct
13 Correct 198 ms 53316 KB Output is correct
14 Correct 182 ms 53324 KB Output is correct
15 Correct 162 ms 51172 KB Output is correct
16 Correct 170 ms 51264 KB Output is correct
17 Correct 202 ms 51148 KB Output is correct
18 Correct 219 ms 55724 KB Output is correct
19 Correct 17 ms 37844 KB Output is correct
20 Correct 21 ms 37844 KB Output is correct
21 Correct 18 ms 37832 KB Output is correct
22 Correct 20 ms 37964 KB Output is correct
23 Correct 17 ms 37832 KB Output is correct
24 Correct 19 ms 37972 KB Output is correct
25 Correct 18 ms 37900 KB Output is correct
26 Correct 17 ms 37844 KB Output is correct
27 Correct 18 ms 37912 KB Output is correct
28 Correct 17 ms 37844 KB Output is correct
29 Correct 17 ms 37820 KB Output is correct
30 Correct 18 ms 37804 KB Output is correct
31 Correct 18 ms 37844 KB Output is correct
32 Correct 18 ms 37828 KB Output is correct
33 Correct 18 ms 37884 KB Output is correct
34 Correct 17 ms 37844 KB Output is correct
35 Correct 18 ms 37872 KB Output is correct
36 Correct 17 ms 37912 KB Output is correct
37 Correct 18 ms 37828 KB Output is correct
38 Correct 45 ms 42668 KB Output is correct
39 Correct 46 ms 42708 KB Output is correct
40 Correct 52 ms 42752 KB Output is correct
41 Correct 47 ms 42780 KB Output is correct
42 Correct 56 ms 44196 KB Output is correct
43 Correct 58 ms 44716 KB Output is correct
44 Correct 55 ms 44876 KB Output is correct
45 Correct 53 ms 44840 KB Output is correct
46 Correct 55 ms 43892 KB Output is correct
47 Correct 59 ms 44792 KB Output is correct
48 Correct 45 ms 44788 KB Output is correct
49 Correct 46 ms 44876 KB Output is correct
50 Correct 69 ms 45048 KB Output is correct
51 Correct 74 ms 45008 KB Output is correct
52 Correct 71 ms 44280 KB Output is correct
53 Correct 78 ms 45084 KB Output is correct
54 Correct 72 ms 45104 KB Output is correct
55 Correct 63 ms 44364 KB Output is correct
56 Correct 1445 ms 166012 KB Output is correct
57 Correct 1379 ms 165412 KB Output is correct
58 Correct 1636 ms 203376 KB Output is correct
59 Correct 1574 ms 203548 KB Output is correct
60 Correct 1555 ms 177796 KB Output is correct
61 Correct 1623 ms 203464 KB Output is correct
62 Correct 1441 ms 165928 KB Output is correct
63 Correct 1486 ms 218944 KB Output is correct
64 Correct 1502 ms 218968 KB Output is correct
65 Correct 239 ms 60576 KB Output is correct
66 Correct 1487 ms 177784 KB Output is correct
67 Correct 2295 ms 217392 KB Output is correct
68 Correct 1834 ms 218672 KB Output is correct
69 Correct 1605 ms 216776 KB Output is correct
70 Correct 2559 ms 217884 KB Output is correct
71 Correct 2013 ms 218908 KB Output is correct
72 Correct 1475 ms 218848 KB Output is correct
73 Correct 2656 ms 217796 KB Output is correct
74 Correct 1245 ms 218784 KB Output is correct
75 Correct 1107 ms 218888 KB Output is correct
76 Execution timed out 3098 ms 213076 KB Time limit exceeded
77 Halted 0 ms 0 KB -