답안 #749773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
749773 2023-05-28T13:20:28 Z Dan4Life 치료 계획 (JOI20_treatment) C++17
100 / 100
106 ms 7868 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 upd(int x, 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);
	if(x<=mid) upd(x,p+1,l,mid);
	else upd(x,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]);
}

int32_t 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}); 
	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);
	}
	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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 4160 KB Output is correct
2 Correct 84 ms 5620 KB Output is correct
3 Correct 78 ms 6420 KB Output is correct
4 Correct 75 ms 6260 KB Output is correct
5 Correct 68 ms 7740 KB Output is correct
6 Correct 72 ms 5796 KB Output is correct
7 Correct 68 ms 5636 KB Output is correct
8 Correct 53 ms 5644 KB Output is correct
9 Correct 59 ms 5552 KB Output is correct
10 Correct 53 ms 5576 KB Output is correct
11 Correct 80 ms 7800 KB Output is correct
12 Correct 79 ms 7720 KB Output is correct
13 Correct 79 ms 7752 KB Output is correct
14 Correct 71 ms 7728 KB Output is correct
15 Correct 64 ms 5652 KB Output is correct
16 Correct 65 ms 5580 KB Output is correct
17 Correct 64 ms 5664 KB Output is correct
18 Correct 71 ms 7760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 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 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 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 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 340 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 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 4 ms 700 KB Output is correct
21 Correct 4 ms 724 KB Output is correct
22 Correct 5 ms 724 KB Output is correct
23 Correct 4 ms 596 KB Output is correct
24 Correct 4 ms 852 KB Output is correct
25 Correct 5 ms 724 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 4 ms 692 KB Output is correct
28 Correct 5 ms 852 KB Output is correct
29 Correct 4 ms 704 KB Output is correct
30 Correct 3 ms 724 KB Output is correct
31 Correct 3 ms 724 KB Output is correct
32 Correct 4 ms 832 KB Output is correct
33 Correct 5 ms 852 KB Output is correct
34 Correct 4 ms 600 KB Output is correct
35 Correct 4 ms 852 KB Output is correct
36 Correct 4 ms 852 KB Output is correct
37 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 4160 KB Output is correct
2 Correct 84 ms 5620 KB Output is correct
3 Correct 78 ms 6420 KB Output is correct
4 Correct 75 ms 6260 KB Output is correct
5 Correct 68 ms 7740 KB Output is correct
6 Correct 72 ms 5796 KB Output is correct
7 Correct 68 ms 5636 KB Output is correct
8 Correct 53 ms 5644 KB Output is correct
9 Correct 59 ms 5552 KB Output is correct
10 Correct 53 ms 5576 KB Output is correct
11 Correct 80 ms 7800 KB Output is correct
12 Correct 79 ms 7720 KB Output is correct
13 Correct 79 ms 7752 KB Output is correct
14 Correct 71 ms 7728 KB Output is correct
15 Correct 64 ms 5652 KB Output is correct
16 Correct 65 ms 5580 KB Output is correct
17 Correct 64 ms 5664 KB Output is correct
18 Correct 71 ms 7760 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 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 328 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 340 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 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 4 ms 700 KB Output is correct
39 Correct 4 ms 724 KB Output is correct
40 Correct 5 ms 724 KB Output is correct
41 Correct 4 ms 596 KB Output is correct
42 Correct 4 ms 852 KB Output is correct
43 Correct 5 ms 724 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 4 ms 692 KB Output is correct
46 Correct 5 ms 852 KB Output is correct
47 Correct 4 ms 704 KB Output is correct
48 Correct 3 ms 724 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 4 ms 832 KB Output is correct
51 Correct 5 ms 852 KB Output is correct
52 Correct 4 ms 600 KB Output is correct
53 Correct 4 ms 852 KB Output is correct
54 Correct 4 ms 852 KB Output is correct
55 Correct 3 ms 596 KB Output is correct
56 Correct 71 ms 6804 KB Output is correct
57 Correct 79 ms 6348 KB Output is correct
58 Correct 81 ms 5548 KB Output is correct
59 Correct 81 ms 5576 KB Output is correct
60 Correct 85 ms 5708 KB Output is correct
61 Correct 99 ms 5580 KB Output is correct
62 Correct 82 ms 6796 KB Output is correct
63 Correct 85 ms 5564 KB Output is correct
64 Correct 106 ms 5740 KB Output is correct
65 Correct 80 ms 5648 KB Output is correct
66 Correct 75 ms 5636 KB Output is correct
67 Correct 86 ms 5760 KB Output is correct
68 Correct 87 ms 5632 KB Output is correct
69 Correct 91 ms 5548 KB Output is correct
70 Correct 91 ms 5776 KB Output is correct
71 Correct 88 ms 5560 KB Output is correct
72 Correct 91 ms 5632 KB Output is correct
73 Correct 90 ms 5708 KB Output is correct
74 Correct 62 ms 5588 KB Output is correct
75 Correct 58 ms 5608 KB Output is correct
76 Correct 79 ms 7764 KB Output is correct
77 Correct 88 ms 7752 KB Output is correct
78 Correct 88 ms 7816 KB Output is correct
79 Correct 92 ms 5648 KB Output is correct
80 Correct 67 ms 5620 KB Output is correct
81 Correct 65 ms 5572 KB Output is correct
82 Correct 77 ms 5832 KB Output is correct
83 Correct 77 ms 5756 KB Output is correct
84 Correct 98 ms 5576 KB Output is correct
85 Correct 84 ms 5624 KB Output is correct
86 Correct 74 ms 5672 KB Output is correct
87 Correct 77 ms 5628 KB Output is correct
88 Correct 83 ms 5712 KB Output is correct
89 Correct 81 ms 5620 KB Output is correct
90 Correct 97 ms 7756 KB Output is correct
91 Correct 75 ms 6772 KB Output is correct
92 Correct 77 ms 5548 KB Output is correct
93 Correct 100 ms 5696 KB Output is correct
94 Correct 77 ms 5828 KB Output is correct
95 Correct 93 ms 5576 KB Output is correct
96 Correct 87 ms 7800 KB Output is correct
97 Correct 84 ms 7752 KB Output is correct
98 Correct 81 ms 7852 KB Output is correct
99 Correct 84 ms 7764 KB Output is correct
100 Correct 83 ms 7736 KB Output is correct
101 Correct 84 ms 7868 KB Output is correct
102 Correct 79 ms 7784 KB Output is correct
103 Correct 71 ms 5976 KB Output is correct