Submission #765004

# Submission time Handle Problem Language Result Execution time Memory
765004 2023-06-24T07:22:09 Z Dan4Life Treatment Project (JOI20_treatment) C++17
100 / 100
75 ms 6672 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 bld(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);
	bld(p+1,l,mid); bld(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});
	bld();
	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 53 ms 4396 KB Output is correct
2 Correct 42 ms 4476 KB Output is correct
3 Correct 50 ms 5024 KB Output is correct
4 Correct 49 ms 5044 KB Output is correct
5 Correct 46 ms 6600 KB Output is correct
6 Correct 42 ms 4684 KB Output is correct
7 Correct 40 ms 4372 KB Output is correct
8 Correct 32 ms 4428 KB Output is correct
9 Correct 31 ms 4468 KB Output is correct
10 Correct 31 ms 4372 KB Output is correct
11 Correct 50 ms 6600 KB Output is correct
12 Correct 50 ms 6660 KB Output is correct
13 Correct 49 ms 6600 KB Output is correct
14 Correct 51 ms 6672 KB Output is correct
15 Correct 44 ms 4456 KB Output is correct
16 Correct 45 ms 4416 KB Output is correct
17 Correct 41 ms 4412 KB Output is correct
18 Correct 47 ms 6640 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 0 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 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 0 ms 332 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 0 ms 332 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 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 0 ms 332 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 728 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 4 ms 852 KB Output is correct
25 Correct 4 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 4 ms 724 KB Output is correct
28 Correct 4 ms 856 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 696 KB Output is correct
32 Correct 3 ms 852 KB Output is correct
33 Correct 3 ms 980 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 3 ms 852 KB Output is correct
36 Correct 3 ms 852 KB Output is correct
37 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 4396 KB Output is correct
2 Correct 42 ms 4476 KB Output is correct
3 Correct 50 ms 5024 KB Output is correct
4 Correct 49 ms 5044 KB Output is correct
5 Correct 46 ms 6600 KB Output is correct
6 Correct 42 ms 4684 KB Output is correct
7 Correct 40 ms 4372 KB Output is correct
8 Correct 32 ms 4428 KB Output is correct
9 Correct 31 ms 4468 KB Output is correct
10 Correct 31 ms 4372 KB Output is correct
11 Correct 50 ms 6600 KB Output is correct
12 Correct 50 ms 6660 KB Output is correct
13 Correct 49 ms 6600 KB Output is correct
14 Correct 51 ms 6672 KB Output is correct
15 Correct 44 ms 4456 KB Output is correct
16 Correct 45 ms 4416 KB Output is correct
17 Correct 41 ms 4412 KB Output is correct
18 Correct 47 ms 6640 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 0 ms 332 KB Output is correct
23 Correct 0 ms 340 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 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 0 ms 332 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 728 KB Output is correct
39 Correct 3 ms 724 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 3 ms 596 KB Output is correct
42 Correct 4 ms 852 KB Output is correct
43 Correct 4 ms 724 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 4 ms 724 KB Output is correct
46 Correct 4 ms 856 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 696 KB Output is correct
50 Correct 3 ms 852 KB Output is correct
51 Correct 3 ms 980 KB Output is correct
52 Correct 3 ms 596 KB Output is correct
53 Correct 3 ms 852 KB Output is correct
54 Correct 3 ms 852 KB Output is correct
55 Correct 3 ms 596 KB Output is correct
56 Correct 53 ms 5648 KB Output is correct
57 Correct 68 ms 5016 KB Output is correct
58 Correct 68 ms 4500 KB Output is correct
59 Correct 59 ms 4476 KB Output is correct
60 Correct 56 ms 4400 KB Output is correct
61 Correct 53 ms 4432 KB Output is correct
62 Correct 50 ms 5588 KB Output is correct
63 Correct 52 ms 4436 KB Output is correct
64 Correct 57 ms 4476 KB Output is correct
65 Correct 53 ms 4472 KB Output is correct
66 Correct 50 ms 4428 KB Output is correct
67 Correct 73 ms 4556 KB Output is correct
68 Correct 73 ms 4384 KB Output is correct
69 Correct 58 ms 4456 KB Output is correct
70 Correct 64 ms 4684 KB Output is correct
71 Correct 65 ms 4392 KB Output is correct
72 Correct 62 ms 4560 KB Output is correct
73 Correct 64 ms 4568 KB Output is correct
74 Correct 35 ms 4380 KB Output is correct
75 Correct 34 ms 4440 KB Output is correct
76 Correct 51 ms 6656 KB Output is correct
77 Correct 58 ms 6596 KB Output is correct
78 Correct 55 ms 6560 KB Output is correct
79 Correct 75 ms 4436 KB Output is correct
80 Correct 46 ms 4428 KB Output is correct
81 Correct 37 ms 4420 KB Output is correct
82 Correct 45 ms 4552 KB Output is correct
83 Correct 49 ms 4436 KB Output is correct
84 Correct 65 ms 4320 KB Output is correct
85 Correct 56 ms 4228 KB Output is correct
86 Correct 56 ms 4456 KB Output is correct
87 Correct 71 ms 4344 KB Output is correct
88 Correct 54 ms 4320 KB Output is correct
89 Correct 53 ms 4272 KB Output is correct
90 Correct 59 ms 6444 KB Output is correct
91 Correct 56 ms 5432 KB Output is correct
92 Correct 54 ms 4300 KB Output is correct
93 Correct 68 ms 4264 KB Output is correct
94 Correct 51 ms 4568 KB Output is correct
95 Correct 71 ms 4324 KB Output is correct
96 Correct 59 ms 6548 KB Output is correct
97 Correct 57 ms 6452 KB Output is correct
98 Correct 55 ms 6548 KB Output is correct
99 Correct 57 ms 6452 KB Output is correct
100 Correct 53 ms 6480 KB Output is correct
101 Correct 56 ms 6512 KB Output is correct
102 Correct 54 ms 6484 KB Output is correct
103 Correct 45 ms 4700 KB Output is correct