답안 #1094609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094609 2024-09-30T06:33:07 Z emptypringlescan 치료 계획 (JOI20_treatment) C++17
100 / 100
449 ms 151748 KB
#include <bits/stdc++.h>
using namespace std;
pair<pair<int,int>,pair<int,int> > arr[100005];
pair<int,int> ran[100005];
struct node{
	int s,e,m;
	node *l, *r;
	int val;
	node(int S, int E){
		s=S; e=E;
		if(s+e>=0) m=(s+e)/2;
		else m=(s+e-1)/2;
		val=100004;
		l=r=NULL;
	}
	void prop(){
		if(l==NULL){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	void update(int S, int V){
		if(s==e){
			val=V;
			return;
		}
		prop();
		if(S<=m) l->update(S,V);
		else r->update(S,V);
		val=(ran[l->val].second<=ran[r->val].second?l->val:r->val);
	}
	int query(int S, int E){
		if(S<=s&&e<=E) return val;
		if(l==NULL) return 100004;
		if(E<=m) return l->query(S,E);
		else if(S>m) return r->query(S,E);
		else{
			int a=l->query(S,m),b=r->query(m+1,E);
			return (ran[a].second<=ran[b].second?a:b);
		}
	}
} *root;
bool cmp(int a, int b){
	return ran[a].second>ran[b].second;
}
unordered_map<int,vector<int> > um;
priority_queue<pair<long long,int>,vector<pair<long long,int> >,greater<pair<long long,int> > > pq;
int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ran[100004]={2e9+5,2e9+5};
    int n,m;
    root=new node(-2e9-5,2e9+5);
    cin >> n >> m;
    for(int i=0; i<m; i++){
		int t,l,r,c;
		cin >> t >> l >> r >> c;
		arr[i]={{t,l},{r,c}};
		ran[i]={t-l,t+l};
		if(l==1){
			pq.push({c,i});
		}
		else um[t-l].push_back(i);
	}
	for(auto [i,j]:um){
		sort(um[i].begin(),um[i].end(),cmp);
		root->update(i,um[i].back());
		um[i].pop_back();
	}
	while(!pq.empty()){
		long long a=pq.top().first;
		int b=pq.top().second;
		pq.pop();
		if(arr[b].second.first==n){
			cout << a;
			return 0;
		}
		pair<int,int> qu={arr[b].first.first-arr[b].second.first-1,arr[b].first.first+arr[b].second.first+1};
		while(true){
			int x=root->query(qu.first,qu.second);
			if(x==100004||ran[x].second>qu.second) break;
			pq.push({a+arr[x].second.second,x});
			if(!um[ran[x].first].empty()){
				root->update(ran[x].first,um[ran[x].first].back());
				um[ran[x].first].pop_back();
			}
			else root->update(ran[x].first,100004);
		}
	}
	cout << -1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 148676 KB Output is correct
2 Correct 272 ms 148676 KB Output is correct
3 Correct 103 ms 15316 KB Output is correct
4 Correct 100 ms 14592 KB Output is correct
5 Correct 61 ms 8684 KB Output is correct
6 Correct 85 ms 8672 KB Output is correct
7 Correct 103 ms 24148 KB Output is correct
8 Correct 30 ms 6348 KB Output is correct
9 Correct 29 ms 8272 KB Output is correct
10 Correct 46 ms 23888 KB Output is correct
11 Correct 307 ms 144064 KB Output is correct
12 Correct 325 ms 144064 KB Output is correct
13 Correct 369 ms 144148 KB Output is correct
14 Correct 350 ms 144072 KB Output is correct
15 Correct 362 ms 141256 KB Output is correct
16 Correct 357 ms 140992 KB Output is correct
17 Correct 359 ms 140484 KB Output is correct
18 Correct 313 ms 143540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 352 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 352 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 5 ms 1116 KB Output is correct
21 Correct 4 ms 1072 KB Output is correct
22 Correct 12 ms 6236 KB Output is correct
23 Correct 10 ms 6116 KB Output is correct
24 Correct 11 ms 8544 KB Output is correct
25 Correct 15 ms 9568 KB Output is correct
26 Correct 15 ms 9816 KB Output is correct
27 Correct 13 ms 9824 KB Output is correct
28 Correct 11 ms 8544 KB Output is correct
29 Correct 14 ms 9536 KB Output is correct
30 Correct 10 ms 9816 KB Output is correct
31 Correct 10 ms 9708 KB Output is correct
32 Correct 13 ms 9956 KB Output is correct
33 Correct 12 ms 9576 KB Output is correct
34 Correct 13 ms 9320 KB Output is correct
35 Correct 12 ms 9832 KB Output is correct
36 Correct 12 ms 9572 KB Output is correct
37 Correct 12 ms 9320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 346 ms 148676 KB Output is correct
2 Correct 272 ms 148676 KB Output is correct
3 Correct 103 ms 15316 KB Output is correct
4 Correct 100 ms 14592 KB Output is correct
5 Correct 61 ms 8684 KB Output is correct
6 Correct 85 ms 8672 KB Output is correct
7 Correct 103 ms 24148 KB Output is correct
8 Correct 30 ms 6348 KB Output is correct
9 Correct 29 ms 8272 KB Output is correct
10 Correct 46 ms 23888 KB Output is correct
11 Correct 307 ms 144064 KB Output is correct
12 Correct 325 ms 144064 KB Output is correct
13 Correct 369 ms 144148 KB Output is correct
14 Correct 350 ms 144072 KB Output is correct
15 Correct 362 ms 141256 KB Output is correct
16 Correct 357 ms 140992 KB Output is correct
17 Correct 359 ms 140484 KB Output is correct
18 Correct 313 ms 143540 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 5 ms 1116 KB Output is correct
39 Correct 4 ms 1072 KB Output is correct
40 Correct 12 ms 6236 KB Output is correct
41 Correct 10 ms 6116 KB Output is correct
42 Correct 11 ms 8544 KB Output is correct
43 Correct 15 ms 9568 KB Output is correct
44 Correct 15 ms 9816 KB Output is correct
45 Correct 13 ms 9824 KB Output is correct
46 Correct 11 ms 8544 KB Output is correct
47 Correct 14 ms 9536 KB Output is correct
48 Correct 10 ms 9816 KB Output is correct
49 Correct 10 ms 9708 KB Output is correct
50 Correct 13 ms 9956 KB Output is correct
51 Correct 12 ms 9576 KB Output is correct
52 Correct 13 ms 9320 KB Output is correct
53 Correct 12 ms 9832 KB Output is correct
54 Correct 12 ms 9572 KB Output is correct
55 Correct 12 ms 9320 KB Output is correct
56 Correct 102 ms 15588 KB Output is correct
57 Correct 123 ms 22540 KB Output is correct
58 Correct 155 ms 23492 KB Output is correct
59 Correct 153 ms 24000 KB Output is correct
60 Correct 445 ms 145092 KB Output is correct
61 Correct 161 ms 23488 KB Output is correct
62 Correct 107 ms 15576 KB Output is correct
63 Correct 339 ms 148672 KB Output is correct
64 Correct 334 ms 148676 KB Output is correct
65 Correct 303 ms 91528 KB Output is correct
66 Correct 382 ms 145096 KB Output is correct
67 Correct 434 ms 147652 KB Output is correct
68 Correct 397 ms 147896 KB Output is correct
69 Correct 399 ms 147964 KB Output is correct
70 Correct 441 ms 147656 KB Output is correct
71 Correct 430 ms 148364 KB Output is correct
72 Correct 369 ms 148164 KB Output is correct
73 Correct 433 ms 147608 KB Output is correct
74 Correct 221 ms 148420 KB Output is correct
75 Correct 209 ms 147392 KB Output is correct
76 Correct 292 ms 144548 KB Output is correct
77 Correct 280 ms 150716 KB Output is correct
78 Correct 330 ms 144500 KB Output is correct
79 Correct 389 ms 148760 KB Output is correct
80 Correct 327 ms 141504 KB Output is correct
81 Correct 203 ms 148584 KB Output is correct
82 Correct 364 ms 140980 KB Output is correct
83 Correct 362 ms 141252 KB Output is correct
84 Correct 449 ms 147652 KB Output is correct
85 Correct 343 ms 139768 KB Output is correct
86 Correct 355 ms 150620 KB Output is correct
87 Correct 381 ms 148196 KB Output is correct
88 Correct 297 ms 109920 KB Output is correct
89 Correct 345 ms 149444 KB Output is correct
90 Correct 332 ms 151612 KB Output is correct
91 Correct 228 ms 148420 KB Output is correct
92 Correct 337 ms 148724 KB Output is correct
93 Correct 422 ms 148684 KB Output is correct
94 Correct 237 ms 79204 KB Output is correct
95 Correct 375 ms 150280 KB Output is correct
96 Correct 308 ms 150296 KB Output is correct
97 Correct 364 ms 150220 KB Output is correct
98 Correct 367 ms 150468 KB Output is correct
99 Correct 382 ms 150288 KB Output is correct
100 Correct 169 ms 74968 KB Output is correct
101 Correct 370 ms 151748 KB Output is correct
102 Correct 365 ms 147652 KB Output is correct
103 Correct 305 ms 148932 KB Output is correct