Submission #1043342

# Submission time Handle Problem Language Result Execution time Memory
1043342 2024-08-04T08:37:00 Z TrinhKhanhDung Treatment Project (JOI20_treatment) C++14
100 / 100
253 ms 34764 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 1e5 + 5;

int N, M;
int T[MAX], L[MAX], R[MAX], C[MAX], rnk[MAX];
bool vis[MAX];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> adj1[MAX];
priority_queue<pair<int, int>> adj2[MAX];

void solve(){
    cin >> N >> M;
    vector<int> v;
    for(int i=1; i<=M; i++){
        cin >> T[i] >> L[i] >> R[i] >> C[i];
        v.push_back(T[i]);
    }
    cps(v);
    for(int i=1; i<=M; i++){
        int p = lower_bound(ALL(v), T[i]) - v.begin() + 1;
        rnk[i] = p;
        for(int k=p; k>0; k-=k&(-k)){
            adj1[k].push(make_pair(L[i] + T[i], i));
        }
        for(int k=p; k<=sz(v); k+=k&(-k)){
            adj2[k].push(make_pair(T[i] - L[i], i));
        }
    }

//    //Dijkstra
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    for(int i=1; i<=M; i++){
        if(L[i] == 1){
            pq.push(make_pair(C[i], i));
            vis[i] = true;
        }
    }

    while(sz(pq)){
        int u = pq.top().se;
        ll c = pq.top().fi;
        if(R[u] == N){
            cout << c << '\n';
            return;
        }
        pq.pop();
        int k = rnk[u];
        for(int p=k; p<=sz(v); p+=p&(-p)){
            while(sz(adj1[p])){
                int v = adj1[p].top().se;
                int tmp = adj1[p].top().fi;
                if(vis[v]){
                    adj1[p].pop();
                    continue;
                }
                if(tmp > R[u] + T[u] + 1) break;
                adj1[p].pop();
                vis[v] = true;
                pq.push(make_pair(c + C[v], v));
            }
        }
        for(int p=k; p>0; p-=p&(-p)){
            while(sz(adj2[p])){
                int v = adj2[p].top().se;
                int tmp = adj2[p].top().fi;
                if(vis[v]){
                    adj2[p].pop();
                    continue;
                }
                if(tmp < T[u] - R[u] - 1) break;
                adj2[p].pop();
                vis[v] = true;
                pq.push(make_pair(c + C[v], v));
            }
        }
    }
    cout << -1 << '\n';
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//    freopen("deggraph.inp", "r", stdin);
//    freopen("deggraph.out", "w", stdout);

    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 47 ms 14664 KB Output is correct
2 Correct 39 ms 14540 KB Output is correct
3 Correct 48 ms 14280 KB Output is correct
4 Correct 48 ms 13772 KB Output is correct
5 Correct 51 ms 15808 KB Output is correct
6 Correct 58 ms 14540 KB Output is correct
7 Correct 49 ms 14564 KB Output is correct
8 Correct 28 ms 14540 KB Output is correct
9 Correct 26 ms 14540 KB Output is correct
10 Correct 27 ms 14488 KB Output is correct
11 Correct 44 ms 16048 KB Output is correct
12 Correct 53 ms 15952 KB Output is correct
13 Correct 49 ms 15816 KB Output is correct
14 Correct 62 ms 15820 KB Output is correct
15 Correct 52 ms 14540 KB Output is correct
16 Correct 54 ms 14544 KB Output is correct
17 Correct 49 ms 13772 KB Output is correct
18 Correct 43 ms 15184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 4 ms 6572 KB Output is correct
6 Correct 3 ms 6696 KB Output is correct
7 Correct 3 ms 6560 KB Output is correct
8 Correct 3 ms 6744 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6552 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 3 ms 6692 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 3 ms 6692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 4 ms 6572 KB Output is correct
6 Correct 3 ms 6696 KB Output is correct
7 Correct 3 ms 6560 KB Output is correct
8 Correct 3 ms 6744 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6552 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 3 ms 6692 KB Output is correct
13 Correct 3 ms 6748 KB Output is correct
14 Correct 3 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 2 ms 6748 KB Output is correct
17 Correct 2 ms 6748 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 3 ms 6692 KB Output is correct
20 Correct 7 ms 7584 KB Output is correct
21 Correct 7 ms 7480 KB Output is correct
22 Correct 8 ms 7516 KB Output is correct
23 Correct 6 ms 7516 KB Output is correct
24 Correct 8 ms 7772 KB Output is correct
25 Correct 10 ms 7772 KB Output is correct
26 Correct 8 ms 7772 KB Output is correct
27 Correct 8 ms 7836 KB Output is correct
28 Correct 8 ms 7772 KB Output is correct
29 Correct 7 ms 7516 KB Output is correct
30 Correct 5 ms 7772 KB Output is correct
31 Correct 6 ms 7760 KB Output is correct
32 Correct 7 ms 7964 KB Output is correct
33 Correct 11 ms 7908 KB Output is correct
34 Correct 9 ms 7516 KB Output is correct
35 Correct 6 ms 7772 KB Output is correct
36 Correct 6 ms 8028 KB Output is correct
37 Correct 8 ms 7516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 14664 KB Output is correct
2 Correct 39 ms 14540 KB Output is correct
3 Correct 48 ms 14280 KB Output is correct
4 Correct 48 ms 13772 KB Output is correct
5 Correct 51 ms 15808 KB Output is correct
6 Correct 58 ms 14540 KB Output is correct
7 Correct 49 ms 14564 KB Output is correct
8 Correct 28 ms 14540 KB Output is correct
9 Correct 26 ms 14540 KB Output is correct
10 Correct 27 ms 14488 KB Output is correct
11 Correct 44 ms 16048 KB Output is correct
12 Correct 53 ms 15952 KB Output is correct
13 Correct 49 ms 15816 KB Output is correct
14 Correct 62 ms 15820 KB Output is correct
15 Correct 52 ms 14540 KB Output is correct
16 Correct 54 ms 14544 KB Output is correct
17 Correct 49 ms 13772 KB Output is correct
18 Correct 43 ms 15184 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 3 ms 6748 KB Output is correct
21 Correct 2 ms 6748 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 4 ms 6572 KB Output is correct
24 Correct 3 ms 6696 KB Output is correct
25 Correct 3 ms 6560 KB Output is correct
26 Correct 3 ms 6744 KB Output is correct
27 Correct 2 ms 6748 KB Output is correct
28 Correct 2 ms 6552 KB Output is correct
29 Correct 2 ms 6748 KB Output is correct
30 Correct 3 ms 6692 KB Output is correct
31 Correct 3 ms 6748 KB Output is correct
32 Correct 3 ms 6748 KB Output is correct
33 Correct 3 ms 6748 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 3 ms 6692 KB Output is correct
38 Correct 7 ms 7584 KB Output is correct
39 Correct 7 ms 7480 KB Output is correct
40 Correct 8 ms 7516 KB Output is correct
41 Correct 6 ms 7516 KB Output is correct
42 Correct 8 ms 7772 KB Output is correct
43 Correct 10 ms 7772 KB Output is correct
44 Correct 8 ms 7772 KB Output is correct
45 Correct 8 ms 7836 KB Output is correct
46 Correct 8 ms 7772 KB Output is correct
47 Correct 7 ms 7516 KB Output is correct
48 Correct 5 ms 7772 KB Output is correct
49 Correct 6 ms 7760 KB Output is correct
50 Correct 7 ms 7964 KB Output is correct
51 Correct 11 ms 7908 KB Output is correct
52 Correct 9 ms 7516 KB Output is correct
53 Correct 6 ms 7772 KB Output is correct
54 Correct 6 ms 8028 KB Output is correct
55 Correct 8 ms 7516 KB Output is correct
56 Correct 164 ms 27348 KB Output is correct
57 Correct 172 ms 27860 KB Output is correct
58 Correct 156 ms 25812 KB Output is correct
59 Correct 159 ms 26144 KB Output is correct
60 Correct 122 ms 28368 KB Output is correct
61 Correct 168 ms 25852 KB Output is correct
62 Correct 180 ms 27344 KB Output is correct
63 Correct 152 ms 29392 KB Output is correct
64 Correct 142 ms 29396 KB Output is correct
65 Correct 56 ms 14796 KB Output is correct
66 Correct 100 ms 28056 KB Output is correct
67 Correct 194 ms 31956 KB Output is correct
68 Correct 167 ms 33620 KB Output is correct
69 Correct 187 ms 34432 KB Output is correct
70 Correct 196 ms 30692 KB Output is correct
71 Correct 171 ms 31440 KB Output is correct
72 Correct 154 ms 33236 KB Output is correct
73 Correct 222 ms 31440 KB Output is correct
74 Correct 91 ms 31948 KB Output is correct
75 Correct 81 ms 32972 KB Output is correct
76 Correct 115 ms 32056 KB Output is correct
77 Correct 117 ms 33224 KB Output is correct
78 Correct 187 ms 32084 KB Output is correct
79 Correct 228 ms 31184 KB Output is correct
80 Correct 214 ms 30056 KB Output is correct
81 Correct 100 ms 31436 KB Output is correct
82 Correct 209 ms 29260 KB Output is correct
83 Correct 242 ms 33608 KB Output is correct
84 Correct 236 ms 30672 KB Output is correct
85 Correct 168 ms 31548 KB Output is correct
86 Correct 168 ms 31948 KB Output is correct
87 Correct 179 ms 32128 KB Output is correct
88 Correct 199 ms 34252 KB Output is correct
89 Correct 182 ms 32212 KB Output is correct
90 Correct 136 ms 34764 KB Output is correct
91 Correct 109 ms 31120 KB Output is correct
92 Correct 174 ms 31772 KB Output is correct
93 Correct 207 ms 31436 KB Output is correct
94 Correct 253 ms 33744 KB Output is correct
95 Correct 198 ms 31608 KB Output is correct
96 Correct 115 ms 32460 KB Output is correct
97 Correct 134 ms 33920 KB Output is correct
98 Correct 147 ms 33824 KB Output is correct
99 Correct 128 ms 34360 KB Output is correct
100 Correct 134 ms 34528 KB Output is correct
101 Correct 168 ms 33488 KB Output is correct
102 Correct 129 ms 33576 KB Output is correct
103 Correct 142 ms 31544 KB Output is correct