Submission #764993

# Submission time Handle Problem Language Result Execution time Memory
764993 2023-06-24T07:17:50 Z Dan4Life Treatment Project (JOI20_treatment) C++17
100 / 100
85 ms 10312 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxM = (int)1e5+2;
const ll LINF = (ll)1e18;
using pii = pair<ll,int>;
 
ll n, m, dis[mxM], seg[mxM*2];
struct Project{ int t, l, r, c; } a[mxM];
priority_queue<pii,vector<pii>,greater<pii>> pq;
 
void build(int p=0, int l=0, int r=m-1){
	if(l==r){ seg[p] = a[l].l+a[l].t; return; }
	int mid = (l+r)/2; int rp = p+2*(mid-l+1);
	build(p+1,l,mid); build(rp,mid+1,r);
	seg[p] = min(seg[p+1],seg[rp]);
}
 
void query(int i, int j, ll k, int p=0, int l=0, int r=m-1){
	if(i<a[l].l-a[l].t or j < seg[p]) return;
	if(l==r){
		if(dis[l]==LINF) dis[l] = k+a[l].c, pq.push({dis[l],l});
		seg[p]=LINF; return;
	}
	int mid = (l+r)/2; int rp = p+2*(mid-l+1);
	query(i,j,k,p+1,l,mid); query(i,j,k,rp,mid+1,r);
	seg[p] = min(seg[p+1],seg[rp]);
}
 
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m; 
	for(int i = 0; i < m; i++) 
		cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
	sort(a,a+m,[&](Project x, Project y){ return x.l-x.t < y.l-y.t; });
	fill(dis,dis+m,LINF); fill(seg,seg+2*m,LINF);
	for(int i = 0; i < m; i++) if(a[i].l==1) 
		dis[i]=a[i].c, pq.push({a[i].c,i}); 
	build();
	while(!pq.empty()){
		auto [D,s] = pq.top(); pq.pop();
		query(a[s].r-a[s].t+1, a[s].r+a[s].t+1, D);
	}
	ll ans = LINF;
	for(int i = 0; i < m; i++) 
		if(a[i].r==n) ans=min(ans,dis[i]);
	cout << (ans==LINF?-1:ans);
}
# Verdict Execution time Memory Grader output
1 Correct 60 ms 7428 KB Output is correct
2 Correct 45 ms 7392 KB Output is correct
3 Correct 54 ms 6996 KB Output is correct
4 Correct 53 ms 7068 KB Output is correct
5 Correct 71 ms 9408 KB Output is correct
6 Correct 55 ms 7536 KB Output is correct
7 Correct 45 ms 7324 KB Output is correct
8 Correct 41 ms 7304 KB Output is correct
9 Correct 51 ms 7256 KB Output is correct
10 Correct 33 ms 7284 KB Output is correct
11 Correct 53 ms 9560 KB Output is correct
12 Correct 66 ms 9500 KB Output is correct
13 Correct 51 ms 9460 KB Output is correct
14 Correct 60 ms 9436 KB Output is correct
15 Correct 51 ms 7416 KB Output is correct
16 Correct 48 ms 7268 KB Output is correct
17 Correct 55 ms 6568 KB Output is correct
18 Correct 48 ms 8744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 3 ms 688 KB Output is correct
24 Correct 4 ms 856 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 3 ms 732 KB Output is correct
27 Correct 3 ms 676 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 4 ms 724 KB Output is correct
30 Correct 2 ms 724 KB Output is correct
31 Correct 3 ms 716 KB Output is correct
32 Correct 4 ms 856 KB Output is correct
33 Correct 4 ms 852 KB Output is correct
34 Correct 3 ms 724 KB Output is correct
35 Correct 3 ms 856 KB Output is correct
36 Correct 3 ms 852 KB Output is correct
37 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 7428 KB Output is correct
2 Correct 45 ms 7392 KB Output is correct
3 Correct 54 ms 6996 KB Output is correct
4 Correct 53 ms 7068 KB Output is correct
5 Correct 71 ms 9408 KB Output is correct
6 Correct 55 ms 7536 KB Output is correct
7 Correct 45 ms 7324 KB Output is correct
8 Correct 41 ms 7304 KB Output is correct
9 Correct 51 ms 7256 KB Output is correct
10 Correct 33 ms 7284 KB Output is correct
11 Correct 53 ms 9560 KB Output is correct
12 Correct 66 ms 9500 KB Output is correct
13 Correct 51 ms 9460 KB Output is correct
14 Correct 60 ms 9436 KB Output is correct
15 Correct 51 ms 7416 KB Output is correct
16 Correct 48 ms 7268 KB Output is correct
17 Correct 55 ms 6568 KB Output is correct
18 Correct 48 ms 8744 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 3 ms 724 KB Output is correct
39 Correct 3 ms 724 KB Output is correct
40 Correct 3 ms 724 KB Output is correct
41 Correct 3 ms 688 KB Output is correct
42 Correct 4 ms 856 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 3 ms 732 KB Output is correct
45 Correct 3 ms 676 KB Output is correct
46 Correct 4 ms 852 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 2 ms 724 KB Output is correct
49 Correct 3 ms 716 KB Output is correct
50 Correct 4 ms 856 KB Output is correct
51 Correct 4 ms 852 KB Output is correct
52 Correct 3 ms 724 KB Output is correct
53 Correct 3 ms 856 KB Output is correct
54 Correct 3 ms 852 KB Output is correct
55 Correct 2 ms 596 KB Output is correct
56 Correct 55 ms 7832 KB Output is correct
57 Correct 55 ms 7760 KB Output is correct
58 Correct 57 ms 6536 KB Output is correct
59 Correct 57 ms 6928 KB Output is correct
60 Correct 63 ms 7668 KB Output is correct
61 Correct 60 ms 6544 KB Output is correct
62 Correct 54 ms 7836 KB Output is correct
63 Correct 59 ms 7340 KB Output is correct
64 Correct 59 ms 7312 KB Output is correct
65 Correct 61 ms 7572 KB Output is correct
66 Correct 52 ms 7548 KB Output is correct
67 Correct 72 ms 8168 KB Output is correct
68 Correct 80 ms 8016 KB Output is correct
69 Correct 81 ms 8032 KB Output is correct
70 Correct 65 ms 8300 KB Output is correct
71 Correct 66 ms 8016 KB Output is correct
72 Correct 59 ms 8060 KB Output is correct
73 Correct 85 ms 8208 KB Output is correct
74 Correct 37 ms 8068 KB Output is correct
75 Correct 36 ms 8088 KB Output is correct
76 Correct 55 ms 9932 KB Output is correct
77 Correct 63 ms 10312 KB Output is correct
78 Correct 57 ms 9896 KB Output is correct
79 Correct 70 ms 8148 KB Output is correct
80 Correct 48 ms 7704 KB Output is correct
81 Correct 39 ms 8040 KB Output is correct
82 Correct 47 ms 7064 KB Output is correct
83 Correct 63 ms 7276 KB Output is correct
84 Correct 69 ms 7344 KB Output is correct
85 Correct 84 ms 8064 KB Output is correct
86 Correct 70 ms 8084 KB Output is correct
87 Correct 63 ms 8016 KB Output is correct
88 Correct 66 ms 8044 KB Output is correct
89 Correct 71 ms 8016 KB Output is correct
90 Correct 80 ms 10184 KB Output is correct
91 Correct 57 ms 9156 KB Output is correct
92 Correct 57 ms 8100 KB Output is correct
93 Correct 72 ms 8016 KB Output is correct
94 Correct 75 ms 8240 KB Output is correct
95 Correct 77 ms 7988 KB Output is correct
96 Correct 62 ms 10256 KB Output is correct
97 Correct 65 ms 10304 KB Output is correct
98 Correct 66 ms 10268 KB Output is correct
99 Correct 67 ms 10312 KB Output is correct
100 Correct 63 ms 10180 KB Output is correct
101 Correct 64 ms 10288 KB Output is correct
102 Correct 58 ms 10292 KB Output is correct
103 Correct 53 ms 8428 KB Output is correct