답안 #1083180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083180 2024-09-02T17:18:40 Z isaachew 치료 계획 (JOI20_treatment) C++17
100 / 100
1746 ms 175984 KB
#include <bits/stdc++.h>
/*
 A project at L and R are necessary
 Projects "chain"
 Turn the projects into a graph?
 
 35 points - Dijkstra from left project to right project
 */
struct project{
    long long l,r,t,c;
};

struct segtree{
	int size;
    std::vector<std::vector<int>> value;
    std::vector<int> left,right;
    std::vector<int> isleaf;
	segtree(){}
    void init(int n){
		size=n;
        value.push_back(std::vector<int>());
        isleaf.push_back(1);
        left.push_back(0);right.push_back(0);
    }
    void update(long long l,long long r,int v,long long nl,long long nr,int ni){
        //std::cout<<"update "<<nl<<' '<<nr<<' '<<ni<<' '<<left[ni]<<' '<<right[ni]<<'\n';
        if(r<=nl||l>=nr)return;
        if(l<=nl&&r>=nr){
            value[ni].push_back(v);
            return;
        }
        long long nm=(nl+nr)/2;
        if(isleaf[ni]){
            left[ni]=value.size();
            value.push_back(std::vector<int>());
            isleaf.push_back(1);left.push_back(0);right.push_back(0);
            right[ni]=value.size();
            value.push_back(std::vector<int>());
            isleaf.push_back(1);left.push_back(0);right.push_back(0);
            isleaf[ni]=0;
        }
        update(l,r,v,nl,nm,left[ni]);
        update(l,r,v,nm,nr,right[ni]);
    }
	void update(long long l,long long r,int v){update(l,r,v,0,size,0);}
    void query(long long pos,int from,bool neg,std::vector<int>& vec,long long nl,long long nr,int ni){
        while(!value[ni].empty()&&(neg?value[ni].back()>from:value[ni].back()<from)){
            vec.push_back(value[ni].back());
            value[ni].pop_back();
        }
        if(!isleaf[ni]){
            long long nm=(nl+nr)/2;
            if(pos<nm){
                query(pos,from,neg,vec,nl,nm,left[ni]);
            }else{
                query(pos,from,neg,vec,nm,nr,right[ni]);
            }
        }
    }
	void query(long long pos,int from,bool neg,std::vector<int>& vec){query(pos,from,neg,vec,0,size,0);}
};

int main(){
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    int n,m;
    std::cin>>n>>m;
    std::vector<project> projs;
    segtree pasts;//stores left - time
    segtree futures;//stores left - time
    for(int i=0;i<m;i++){
        int a,b,c,d;
        project pr;
        std::cin>>a>>b>>c>>d;
        pr.t=a;pr.l=b;pr.r=c;pr.c=d;
        projs.push_back(pr);
    }
    
    std::sort(projs.begin(),projs.end(),[&](project a,project b){return a.t<b.t;});
    std::set<int> plist;
    std::map<int,int> places;
    for(int i=m;i--;){
        plist.insert(projs[i].l-projs[i].t-1);
		plist.insert(projs[i].r-projs[i].t+1);
    }
    for(int i=0;i<m;i++){
        plist.insert(projs[i].l+projs[i].t-1);
        plist.insert(projs[i].r+projs[i].t+1);
    }
	int j=0;
    for(int i:plist){
		places[i]=j++;
		
    }
	pasts.init(plist.size());
	futures.init(plist.size());
	for(int i=m;i--;){
		pasts.update(places[projs[i].l-projs[i].t-1],places[projs[i].r-projs[i].t+1],i);
	}
	for(int i=0;i<m;i++){
		futures.update(places[projs[i].l+projs[i].t-1],places[projs[i].r+projs[i].t+1],i);
	}
    std::vector<long long> dists(m,1e18);
    std::priority_queue<std::pair<long long,int>> dijkstra;
    for(int i=0;i<m;i++){
        if(projs[i].l==1){
            dijkstra.push({-projs[i].c,i});
        }
    }
    while(!dijkstra.empty()){
        std::pair<long long,int> cur=dijkstra.top();
        dijkstra.pop();
        if(dists[cur.second]<=-cur.first)continue;
        dists[cur.second]=-cur.first;
        int i=cur.second;
        std::vector<int> eds;
        pasts.query(places[(projs[i].r-projs[i].t)+1]-1,i,0,eds);
        futures.query(places[(projs[i].r+projs[i].t)+1]-1,i,1,eds);
        //std::cout<<"pasts\n";
        for(int i:eds){
            //std::cout<<i<<" from "<<cur.second<<'\n';
            dijkstra.push({cur.first-projs[i].c,i});
        }
        //std::cout<<"futures\n";
        
    }
    long long result=1e18;
    for(int i=0;i<m;i++){
        if(projs[i].r==n){
            //std::cout<<i<<'\n';
            result=std::min(result,dists[i]);
        }
    }
    std::cout<<(result==1e18?-1:result)<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 708 ms 114320 KB Output is correct
2 Correct 573 ms 114212 KB Output is correct
3 Correct 891 ms 54832 KB Output is correct
4 Correct 956 ms 54876 KB Output is correct
5 Correct 146 ms 17992 KB Output is correct
6 Correct 158 ms 11704 KB Output is correct
7 Correct 223 ms 19644 KB Output is correct
8 Correct 58 ms 8892 KB Output is correct
9 Correct 84 ms 9392 KB Output is correct
10 Correct 112 ms 14040 KB Output is correct
11 Correct 1293 ms 143200 KB Output is correct
12 Correct 1652 ms 175984 KB Output is correct
13 Correct 1563 ms 155744 KB Output is correct
14 Correct 1593 ms 155624 KB Output is correct
15 Correct 1000 ms 124884 KB Output is correct
16 Correct 971 ms 125064 KB Output is correct
17 Correct 1043 ms 124080 KB Output is correct
18 Correct 1591 ms 142232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 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 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 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 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 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 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 28 ms 4888 KB Output is correct
21 Correct 22 ms 4884 KB Output is correct
22 Correct 17 ms 5268 KB Output is correct
23 Correct 16 ms 5272 KB Output is correct
24 Correct 30 ms 7172 KB Output is correct
25 Correct 39 ms 5520 KB Output is correct
26 Correct 19 ms 5476 KB Output is correct
27 Correct 20 ms 4912 KB Output is correct
28 Correct 29 ms 6552 KB Output is correct
29 Correct 21 ms 4704 KB Output is correct
30 Correct 20 ms 4504 KB Output is correct
31 Correct 11 ms 4120 KB Output is correct
32 Correct 34 ms 7208 KB Output is correct
33 Correct 35 ms 7568 KB Output is correct
34 Correct 25 ms 6040 KB Output is correct
35 Correct 51 ms 7124 KB Output is correct
36 Correct 49 ms 7564 KB Output is correct
37 Correct 35 ms 6040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 708 ms 114320 KB Output is correct
2 Correct 573 ms 114212 KB Output is correct
3 Correct 891 ms 54832 KB Output is correct
4 Correct 956 ms 54876 KB Output is correct
5 Correct 146 ms 17992 KB Output is correct
6 Correct 158 ms 11704 KB Output is correct
7 Correct 223 ms 19644 KB Output is correct
8 Correct 58 ms 8892 KB Output is correct
9 Correct 84 ms 9392 KB Output is correct
10 Correct 112 ms 14040 KB Output is correct
11 Correct 1293 ms 143200 KB Output is correct
12 Correct 1652 ms 175984 KB Output is correct
13 Correct 1563 ms 155744 KB Output is correct
14 Correct 1593 ms 155624 KB Output is correct
15 Correct 1000 ms 124884 KB Output is correct
16 Correct 971 ms 125064 KB Output is correct
17 Correct 1043 ms 124080 KB Output is correct
18 Correct 1591 ms 142232 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 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 452 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 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 1 ms 344 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 28 ms 4888 KB Output is correct
39 Correct 22 ms 4884 KB Output is correct
40 Correct 17 ms 5268 KB Output is correct
41 Correct 16 ms 5272 KB Output is correct
42 Correct 30 ms 7172 KB Output is correct
43 Correct 39 ms 5520 KB Output is correct
44 Correct 19 ms 5476 KB Output is correct
45 Correct 20 ms 4912 KB Output is correct
46 Correct 29 ms 6552 KB Output is correct
47 Correct 21 ms 4704 KB Output is correct
48 Correct 20 ms 4504 KB Output is correct
49 Correct 11 ms 4120 KB Output is correct
50 Correct 34 ms 7208 KB Output is correct
51 Correct 35 ms 7568 KB Output is correct
52 Correct 25 ms 6040 KB Output is correct
53 Correct 51 ms 7124 KB Output is correct
54 Correct 49 ms 7564 KB Output is correct
55 Correct 35 ms 6040 KB Output is correct
56 Correct 781 ms 102548 KB Output is correct
57 Correct 834 ms 89480 KB Output is correct
58 Correct 556 ms 57952 KB Output is correct
59 Correct 492 ms 58408 KB Output is correct
60 Correct 541 ms 93532 KB Output is correct
61 Correct 513 ms 58032 KB Output is correct
62 Correct 792 ms 102548 KB Output is correct
63 Correct 373 ms 87720 KB Output is correct
64 Correct 390 ms 87972 KB Output is correct
65 Correct 441 ms 63912 KB Output is correct
66 Correct 485 ms 93568 KB Output is correct
67 Correct 1155 ms 107344 KB Output is correct
68 Correct 924 ms 102416 KB Output is correct
69 Correct 673 ms 96916 KB Output is correct
70 Correct 1205 ms 108496 KB Output is correct
71 Correct 903 ms 101284 KB Output is correct
72 Correct 616 ms 94888 KB Output is correct
73 Correct 1064 ms 90172 KB Output is correct
74 Correct 455 ms 83788 KB Output is correct
75 Correct 349 ms 77224 KB Output is correct
76 Correct 1720 ms 169608 KB Output is correct
77 Correct 1567 ms 150964 KB Output is correct
78 Correct 1498 ms 151696 KB Output is correct
79 Correct 1094 ms 104100 KB Output is correct
80 Correct 946 ms 121760 KB Output is correct
81 Correct 695 ms 102592 KB Output is correct
82 Correct 1266 ms 125468 KB Output is correct
83 Correct 1254 ms 124428 KB Output is correct
84 Correct 1098 ms 103500 KB Output is correct
85 Correct 612 ms 96628 KB Output is correct
86 Correct 615 ms 95976 KB Output is correct
87 Correct 670 ms 100004 KB Output is correct
88 Correct 482 ms 83312 KB Output is correct
89 Correct 568 ms 95768 KB Output is correct
90 Correct 934 ms 104200 KB Output is correct
91 Correct 962 ms 115108 KB Output is correct
92 Correct 874 ms 102760 KB Output is correct
93 Correct 1055 ms 103744 KB Output is correct
94 Correct 846 ms 89544 KB Output is correct
95 Correct 918 ms 103640 KB Output is correct
96 Correct 885 ms 106416 KB Output is correct
97 Correct 1698 ms 150048 KB Output is correct
98 Correct 1644 ms 150004 KB Output is correct
99 Correct 1746 ms 149920 KB Output is correct
100 Correct 1451 ms 134564 KB Output is correct
101 Correct 1665 ms 150740 KB Output is correct
102 Correct 1698 ms 151584 KB Output is correct
103 Correct 575 ms 96932 KB Output is correct