Submission #749784

# Submission time Handle Problem Language Result Execution time Memory
749784 2023-05-28T13:35:24 Z Dan4Life Treatment Project (JOI20_treatment) C++17
100 / 100
85 ms 6424 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){
		if(x.l-x.t==y.l-y.t) return x.l+x.t < y.l+y.t;
		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 67 ms 4172 KB Output is correct
2 Correct 52 ms 4176 KB Output is correct
3 Correct 62 ms 4944 KB Output is correct
4 Correct 61 ms 4816 KB Output is correct
5 Correct 55 ms 6424 KB Output is correct
6 Correct 52 ms 4340 KB Output is correct
7 Correct 47 ms 4216 KB Output is correct
8 Correct 37 ms 4152 KB Output is correct
9 Correct 36 ms 4172 KB Output is correct
10 Correct 37 ms 4152 KB Output is correct
11 Correct 58 ms 6416 KB Output is correct
12 Correct 58 ms 6396 KB Output is correct
13 Correct 59 ms 6404 KB Output is correct
14 Correct 57 ms 6412 KB Output is correct
15 Correct 53 ms 4200 KB Output is correct
16 Correct 54 ms 4272 KB Output is correct
17 Correct 52 ms 4308 KB Output is correct
18 Correct 56 ms 6344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 4 ms 596 KB Output is correct
21 Correct 5 ms 596 KB Output is correct
22 Correct 4 ms 468 KB Output is correct
23 Correct 4 ms 536 KB Output is correct
24 Correct 5 ms 596 KB Output is correct
25 Correct 6 ms 468 KB Output is correct
26 Correct 4 ms 468 KB Output is correct
27 Correct 4 ms 468 KB Output is correct
28 Correct 4 ms 596 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 3 ms 468 KB Output is correct
31 Correct 3 ms 468 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 3 ms 724 KB Output is correct
34 Correct 3 ms 468 KB Output is correct
35 Correct 4 ms 724 KB Output is correct
36 Correct 4 ms 724 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 4172 KB Output is correct
2 Correct 52 ms 4176 KB Output is correct
3 Correct 62 ms 4944 KB Output is correct
4 Correct 61 ms 4816 KB Output is correct
5 Correct 55 ms 6424 KB Output is correct
6 Correct 52 ms 4340 KB Output is correct
7 Correct 47 ms 4216 KB Output is correct
8 Correct 37 ms 4152 KB Output is correct
9 Correct 36 ms 4172 KB Output is correct
10 Correct 37 ms 4152 KB Output is correct
11 Correct 58 ms 6416 KB Output is correct
12 Correct 58 ms 6396 KB Output is correct
13 Correct 59 ms 6404 KB Output is correct
14 Correct 57 ms 6412 KB Output is correct
15 Correct 53 ms 4200 KB Output is correct
16 Correct 54 ms 4272 KB Output is correct
17 Correct 52 ms 4308 KB Output is correct
18 Correct 56 ms 6344 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 4 ms 596 KB Output is correct
39 Correct 5 ms 596 KB Output is correct
40 Correct 4 ms 468 KB Output is correct
41 Correct 4 ms 536 KB Output is correct
42 Correct 5 ms 596 KB Output is correct
43 Correct 6 ms 468 KB Output is correct
44 Correct 4 ms 468 KB Output is correct
45 Correct 4 ms 468 KB Output is correct
46 Correct 4 ms 596 KB Output is correct
47 Correct 4 ms 468 KB Output is correct
48 Correct 3 ms 468 KB Output is correct
49 Correct 3 ms 468 KB Output is correct
50 Correct 3 ms 724 KB Output is correct
51 Correct 3 ms 724 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 4 ms 724 KB Output is correct
54 Correct 4 ms 724 KB Output is correct
55 Correct 3 ms 468 KB Output is correct
56 Correct 62 ms 5364 KB Output is correct
57 Correct 70 ms 4824 KB Output is correct
58 Correct 70 ms 4176 KB Output is correct
59 Correct 68 ms 4232 KB Output is correct
60 Correct 71 ms 4120 KB Output is correct
61 Correct 64 ms 4220 KB Output is correct
62 Correct 62 ms 5332 KB Output is correct
63 Correct 68 ms 4216 KB Output is correct
64 Correct 69 ms 4212 KB Output is correct
65 Correct 65 ms 4180 KB Output is correct
66 Correct 67 ms 4108 KB Output is correct
67 Correct 73 ms 4336 KB Output is correct
68 Correct 75 ms 4140 KB Output is correct
69 Correct 70 ms 4168 KB Output is correct
70 Correct 77 ms 4416 KB Output is correct
71 Correct 77 ms 4192 KB Output is correct
72 Correct 69 ms 4168 KB Output is correct
73 Correct 77 ms 4348 KB Output is correct
74 Correct 43 ms 4164 KB Output is correct
75 Correct 41 ms 4184 KB Output is correct
76 Correct 67 ms 6384 KB Output is correct
77 Correct 70 ms 6328 KB Output is correct
78 Correct 62 ms 6348 KB Output is correct
79 Correct 85 ms 4248 KB Output is correct
80 Correct 57 ms 4184 KB Output is correct
81 Correct 45 ms 4176 KB Output is correct
82 Correct 53 ms 4312 KB Output is correct
83 Correct 58 ms 4376 KB Output is correct
84 Correct 74 ms 4172 KB Output is correct
85 Correct 66 ms 4104 KB Output is correct
86 Correct 60 ms 4108 KB Output is correct
87 Correct 65 ms 4204 KB Output is correct
88 Correct 64 ms 4172 KB Output is correct
89 Correct 79 ms 4220 KB Output is correct
90 Correct 65 ms 6344 KB Output is correct
91 Correct 65 ms 5344 KB Output is correct
92 Correct 64 ms 4232 KB Output is correct
93 Correct 84 ms 4244 KB Output is correct
94 Correct 63 ms 4396 KB Output is correct
95 Correct 83 ms 4172 KB Output is correct
96 Correct 67 ms 6344 KB Output is correct
97 Correct 82 ms 6360 KB Output is correct
98 Correct 68 ms 6404 KB Output is correct
99 Correct 66 ms 6412 KB Output is correct
100 Correct 66 ms 6348 KB Output is correct
101 Correct 67 ms 6344 KB Output is correct
102 Correct 63 ms 6352 KB Output is correct
103 Correct 55 ms 4572 KB Output is correct