Submission #749130

# Submission time Handle Problem Language Result Execution time Memory
749130 2023-05-27T11:39:43 Z Dan4Life Treatment Project (JOI20_treatment) C++17
100 / 100
96 ms 12076 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
const int mxM = (int)1e5+10;
const int LINF = (int)1e18;
using pii = pair<int,int>;

vector<pii> v;
int n, m, ans=LINF, dis[mxM];
struct Project{ int t, l, r, c; } a[mxM];
priority_queue<pii,vector<pii>,greater<pii>> pq;
int segTree[mxM*2];

void upd(int x, int p=0, int l=0, int r=m-1){
	if(l==r){ segTree[p] = a[l].l+a[l].t; return; }
	int mid = (l+r)/2; int rp = p+2*(mid-l+1);
	if(x<=mid) upd(x,p+1,l,mid);
	else upd(x,rp,mid+1,r);
	segTree[p] = min(segTree[p+1],segTree[rp]);
}

void query(int i, int j, int k, int p=0, int l=0, int r=m-1){
	if(i<a[l].l-a[l].t or j < segTree[p]) return;
	if(l==r){
		if(dis[l]==LINF) dis[l] = k+a[l].c, pq.push({dis[l],l});
		segTree[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);
	segTree[p] = min(segTree[p+1],segTree[rp]);
}

int dijkstra(vector<pii> v){
	fill(dis,dis+m,LINF);
	for(auto [u,w] : v) dis[u]=w, pq.push({w,u});
	for(int i = 0; i < m; i++) upd(i);
	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);
	}
	int d = LINF;
	for(int i = 0; i < m; i++) 
		if(a[i].r==n) d=min(d,dis[i]);
	return d;
}

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	fill(segTree,segTree+2*m,LINF);
	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;
	});
	for(int i = 0; i < m; i++) 
		if(a[i].l==1) v.pb({i,a[i].c});
	ans = dijkstra(v); cout << (ans==LINF?-1:ans);
}
# Verdict Execution time Memory Grader output
1 Correct 80 ms 9056 KB Output is correct
2 Correct 66 ms 8984 KB Output is correct
3 Correct 80 ms 9468 KB Output is correct
4 Correct 72 ms 9548 KB Output is correct
5 Correct 69 ms 11080 KB Output is correct
6 Correct 64 ms 9060 KB Output is correct
7 Correct 60 ms 8892 KB Output is correct
8 Correct 50 ms 8904 KB Output is correct
9 Correct 52 ms 8884 KB Output is correct
10 Correct 52 ms 8796 KB Output is correct
11 Correct 71 ms 11108 KB Output is correct
12 Correct 80 ms 11048 KB Output is correct
13 Correct 77 ms 11076 KB Output is correct
14 Correct 78 ms 11088 KB Output is correct
15 Correct 71 ms 8912 KB Output is correct
16 Correct 67 ms 8892 KB Output is correct
17 Correct 63 ms 8076 KB Output is correct
18 Correct 72 ms 10312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 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 0 ms 336 KB Output is correct
12 Correct 0 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 1 ms 336 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 336 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 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 0 ms 336 KB Output is correct
12 Correct 0 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 1 ms 336 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 4 ms 796 KB Output is correct
21 Correct 5 ms 864 KB Output is correct
22 Correct 4 ms 692 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 5 ms 860 KB Output is correct
25 Correct 5 ms 724 KB Output is correct
26 Correct 4 ms 700 KB Output is correct
27 Correct 4 ms 724 KB Output is correct
28 Correct 4 ms 852 KB Output is correct
29 Correct 5 ms 696 KB Output is correct
30 Correct 4 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 4 ms 980 KB Output is correct
33 Correct 4 ms 980 KB Output is correct
34 Correct 4 ms 736 KB Output is correct
35 Correct 4 ms 904 KB Output is correct
36 Correct 3 ms 852 KB Output is correct
37 Correct 4 ms 664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 9056 KB Output is correct
2 Correct 66 ms 8984 KB Output is correct
3 Correct 80 ms 9468 KB Output is correct
4 Correct 72 ms 9548 KB Output is correct
5 Correct 69 ms 11080 KB Output is correct
6 Correct 64 ms 9060 KB Output is correct
7 Correct 60 ms 8892 KB Output is correct
8 Correct 50 ms 8904 KB Output is correct
9 Correct 52 ms 8884 KB Output is correct
10 Correct 52 ms 8796 KB Output is correct
11 Correct 71 ms 11108 KB Output is correct
12 Correct 80 ms 11048 KB Output is correct
13 Correct 77 ms 11076 KB Output is correct
14 Correct 78 ms 11088 KB Output is correct
15 Correct 71 ms 8912 KB Output is correct
16 Correct 67 ms 8892 KB Output is correct
17 Correct 63 ms 8076 KB Output is correct
18 Correct 72 ms 10312 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 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 0 ms 336 KB Output is correct
30 Correct 0 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 1 ms 336 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 4 ms 796 KB Output is correct
39 Correct 5 ms 864 KB Output is correct
40 Correct 4 ms 692 KB Output is correct
41 Correct 4 ms 724 KB Output is correct
42 Correct 5 ms 860 KB Output is correct
43 Correct 5 ms 724 KB Output is correct
44 Correct 4 ms 700 KB Output is correct
45 Correct 4 ms 724 KB Output is correct
46 Correct 4 ms 852 KB Output is correct
47 Correct 5 ms 696 KB Output is correct
48 Correct 4 ms 724 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 4 ms 980 KB Output is correct
51 Correct 4 ms 980 KB Output is correct
52 Correct 4 ms 736 KB Output is correct
53 Correct 4 ms 904 KB Output is correct
54 Correct 3 ms 852 KB Output is correct
55 Correct 4 ms 664 KB Output is correct
56 Correct 74 ms 10120 KB Output is correct
57 Correct 78 ms 10220 KB Output is correct
58 Correct 74 ms 8124 KB Output is correct
59 Correct 79 ms 8528 KB Output is correct
60 Correct 82 ms 9124 KB Output is correct
61 Correct 80 ms 8084 KB Output is correct
62 Correct 76 ms 10196 KB Output is correct
63 Correct 80 ms 9000 KB Output is correct
64 Correct 78 ms 8976 KB Output is correct
65 Correct 77 ms 9036 KB Output is correct
66 Correct 76 ms 9304 KB Output is correct
67 Correct 87 ms 9792 KB Output is correct
68 Correct 92 ms 9568 KB Output is correct
69 Correct 82 ms 9660 KB Output is correct
70 Correct 86 ms 9792 KB Output is correct
71 Correct 88 ms 9644 KB Output is correct
72 Correct 82 ms 9616 KB Output is correct
73 Correct 92 ms 9780 KB Output is correct
74 Correct 59 ms 9540 KB Output is correct
75 Correct 56 ms 9580 KB Output is correct
76 Correct 81 ms 11492 KB Output is correct
77 Correct 82 ms 11840 KB Output is correct
78 Correct 74 ms 11496 KB Output is correct
79 Correct 93 ms 9676 KB Output is correct
80 Correct 70 ms 9320 KB Output is correct
81 Correct 60 ms 9600 KB Output is correct
82 Correct 68 ms 8648 KB Output is correct
83 Correct 70 ms 8896 KB Output is correct
84 Correct 94 ms 8908 KB Output is correct
85 Correct 80 ms 9636 KB Output is correct
86 Correct 74 ms 9776 KB Output is correct
87 Correct 78 ms 9612 KB Output is correct
88 Correct 76 ms 9676 KB Output is correct
89 Correct 74 ms 9580 KB Output is correct
90 Correct 79 ms 11844 KB Output is correct
91 Correct 78 ms 10752 KB Output is correct
92 Correct 79 ms 9656 KB Output is correct
93 Correct 96 ms 9688 KB Output is correct
94 Correct 77 ms 9852 KB Output is correct
95 Correct 89 ms 9564 KB Output is correct
96 Correct 82 ms 11836 KB Output is correct
97 Correct 85 ms 11860 KB Output is correct
98 Correct 84 ms 11848 KB Output is correct
99 Correct 89 ms 11856 KB Output is correct
100 Correct 85 ms 12076 KB Output is correct
101 Correct 94 ms 11856 KB Output is correct
102 Correct 81 ms 11840 KB Output is correct
103 Correct 69 ms 10044 KB Output is correct