답안 #216310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
216310 2020-03-27T05:08:27 Z model_code 치료 계획 (JOI20_treatment) C++17
100 / 100
242 ms 34020 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SIZE 1024*128
#define INF 1000000001
#define INFL 1000000000000000LL
struct T{
    int x,y,i;
    bool operator<(const T&q)const{
        if(x!=q.x)return x<q.x;
        if(y!=q.y)return y<q.y;
        return i<q.i;        
    }
};
struct segtree{
    vector<pair<int,int>>seg[SIZE*2];
    int sz,cx[SIZE],pt[SIZE*2];
    void init(int n){
        sz=1;
        while(sz<n)sz*=2;
        for(int i=0;i<sz*2;i++)seg[i].clear();
        for(int i=0;i<sz;i++)cx[i]=INF;
        for(int i=0;i<sz*2;i++)pt[i]=0;
    }
    void put(vector<T>q){
        for(int i=0;i<q.size();i++){
            cx[i]=q[i].x;
            seg[i+sz-1].push_back(pair<int,int>(q[i].y,q[i].i));
        }       
    }
    void build(int l,int r,int k){
        if(l==r)return;
        build(l,(l+r-1)/2,k*2+1);
        build((l+r+1)/2,r,k*2+2);
        seg[k].resize(seg[k*2+1].size()+seg[k*2+2].size());
        merge(seg[k*2+1].begin(),seg[k*2+1].end(),seg[k*2+2].begin(),seg[k*2+2].end(),seg[k].begin());
    }
    void query(int x,int y,int l,int r,int k,vector<int>&res){
        if(cx[r]<=x){
            while(pt[k]<seg[k].size()&&seg[k][pt[k]].first<=y){
                res.push_back(seg[k][pt[k]].second);
                pt[k]++;
            }
            return;
        }
        if(x<cx[l])return;
        query(x,y,l,(l+r-1)/2,k*2+1,res);
        query(x,y,(l+r+1)/2,r,k*2+2,res);
    }
};
int main(void){
    int n,m;
    ll ans=INFL;
    scanf("%d%d",&n,&m);
    vector<int>t(m),l(m),r(m);
    vector<ll>c(m),d(m);
    vector<T>p(m);
    vector<bool>pushed(m);
    static segtree seg;
    seg.init(m);
    for(int i=0;i<m;i++){
        scanf("%d%d%d%lld",&t[i],&l[i],&r[i],&c[i]);
        p[i]=(T{l[i]-t[i],l[i]+t[i],i});
    }
    sort(p.begin(),p.end());
    seg.put(p);
    seg.build(0,seg.sz-1,0);
    priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >dik;
    for(int i=0;i<m;i++){
        pushed[i]=false;
        d[i]=INFL;
        if(l[i]==1){
            d[i]=c[i];
            dik.push(pair<ll,int>(c[i],i));
            pushed[i]=true;
        }
    }
    while(!dik.empty()){
        int v=dik.top().second;
        ll dis=dik.top().first;
        dik.pop();
        vector<int>lis;
        lis.clear();
        seg.query(r[v]+1-t[v],r[v]+1+t[v],0,seg.sz-1,0,lis);
        for(int i=0;i<lis.size();i++){
            int u=lis[i];
            if(!pushed[u]){
                d[u]=dis+c[u];
                dik.push(pair<ll,int>(d[u],u));
                pushed[u]=true;
            }
        }
    }
    for(int i=0;i<m;i++){
        if(r[i]==n)ans=min(ans,d[i]);
    }
    if(ans==INFL)printf("-1\n");
    else printf("%lld\n",ans);
}

Compilation message

code1.cpp: In member function 'void segtree::put(std::vector<T>)':
code1.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<q.size();i++){
                     ~^~~~~~~~~
code1.cpp: In member function 'void segtree::query(int, int, int, int, int, std::vector<int>&)':
code1.cpp:40:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(pt[k]<seg[k].size()&&seg[k][pt[k]].first<=y){
                   ~~~~~^~~~~~~~~~~~~~
code1.cpp: In function 'int main()':
code1.cpp:85:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<lis.size();i++){
                     ~^~~~~~~~~~~
code1.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
code1.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%lld",&t[i],&l[i],&r[i],&c[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 30436 KB Output is correct
2 Correct 113 ms 30180 KB Output is correct
3 Correct 138 ms 31588 KB Output is correct
4 Correct 143 ms 31332 KB Output is correct
5 Correct 159 ms 33632 KB Output is correct
6 Correct 131 ms 30796 KB Output is correct
7 Correct 129 ms 30664 KB Output is correct
8 Correct 110 ms 30180 KB Output is correct
9 Correct 107 ms 29924 KB Output is correct
10 Correct 98 ms 29924 KB Output is correct
11 Correct 165 ms 33564 KB Output is correct
12 Correct 174 ms 33764 KB Output is correct
13 Correct 197 ms 33124 KB Output is correct
14 Correct 187 ms 33120 KB Output is correct
15 Correct 153 ms 30816 KB Output is correct
16 Correct 153 ms 30796 KB Output is correct
17 Correct 144 ms 30688 KB Output is correct
18 Correct 157 ms 33380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6528 KB Output is correct
2 Correct 8 ms 6528 KB Output is correct
3 Correct 8 ms 6528 KB Output is correct
4 Correct 8 ms 6528 KB Output is correct
5 Correct 9 ms 6528 KB Output is correct
6 Correct 8 ms 6528 KB Output is correct
7 Correct 8 ms 6528 KB Output is correct
8 Correct 8 ms 6528 KB Output is correct
9 Correct 8 ms 6528 KB Output is correct
10 Correct 8 ms 6528 KB Output is correct
11 Correct 8 ms 6528 KB Output is correct
12 Correct 10 ms 6528 KB Output is correct
13 Correct 8 ms 6528 KB Output is correct
14 Correct 9 ms 6528 KB Output is correct
15 Correct 8 ms 6528 KB Output is correct
16 Correct 8 ms 6528 KB Output is correct
17 Correct 8 ms 6528 KB Output is correct
18 Correct 8 ms 6528 KB Output is correct
19 Correct 8 ms 6528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6528 KB Output is correct
2 Correct 8 ms 6528 KB Output is correct
3 Correct 8 ms 6528 KB Output is correct
4 Correct 8 ms 6528 KB Output is correct
5 Correct 9 ms 6528 KB Output is correct
6 Correct 8 ms 6528 KB Output is correct
7 Correct 8 ms 6528 KB Output is correct
8 Correct 8 ms 6528 KB Output is correct
9 Correct 8 ms 6528 KB Output is correct
10 Correct 8 ms 6528 KB Output is correct
11 Correct 8 ms 6528 KB Output is correct
12 Correct 10 ms 6528 KB Output is correct
13 Correct 8 ms 6528 KB Output is correct
14 Correct 9 ms 6528 KB Output is correct
15 Correct 8 ms 6528 KB Output is correct
16 Correct 8 ms 6528 KB Output is correct
17 Correct 8 ms 6528 KB Output is correct
18 Correct 8 ms 6528 KB Output is correct
19 Correct 8 ms 6528 KB Output is correct
20 Correct 14 ms 7552 KB Output is correct
21 Correct 14 ms 7552 KB Output is correct
22 Correct 15 ms 7552 KB Output is correct
23 Correct 14 ms 7552 KB Output is correct
24 Correct 16 ms 7680 KB Output is correct
25 Correct 16 ms 7552 KB Output is correct
26 Correct 15 ms 7552 KB Output is correct
27 Correct 14 ms 7552 KB Output is correct
28 Correct 16 ms 7680 KB Output is correct
29 Correct 16 ms 7552 KB Output is correct
30 Correct 13 ms 7552 KB Output is correct
31 Correct 13 ms 7552 KB Output is correct
32 Correct 15 ms 7788 KB Output is correct
33 Correct 15 ms 7680 KB Output is correct
34 Correct 15 ms 7552 KB Output is correct
35 Correct 16 ms 7808 KB Output is correct
36 Correct 15 ms 7808 KB Output is correct
37 Correct 20 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 30436 KB Output is correct
2 Correct 113 ms 30180 KB Output is correct
3 Correct 138 ms 31588 KB Output is correct
4 Correct 143 ms 31332 KB Output is correct
5 Correct 159 ms 33632 KB Output is correct
6 Correct 131 ms 30796 KB Output is correct
7 Correct 129 ms 30664 KB Output is correct
8 Correct 110 ms 30180 KB Output is correct
9 Correct 107 ms 29924 KB Output is correct
10 Correct 98 ms 29924 KB Output is correct
11 Correct 165 ms 33564 KB Output is correct
12 Correct 174 ms 33764 KB Output is correct
13 Correct 197 ms 33124 KB Output is correct
14 Correct 187 ms 33120 KB Output is correct
15 Correct 153 ms 30816 KB Output is correct
16 Correct 153 ms 30796 KB Output is correct
17 Correct 144 ms 30688 KB Output is correct
18 Correct 157 ms 33380 KB Output is correct
19 Correct 8 ms 6528 KB Output is correct
20 Correct 8 ms 6528 KB Output is correct
21 Correct 8 ms 6528 KB Output is correct
22 Correct 8 ms 6528 KB Output is correct
23 Correct 9 ms 6528 KB Output is correct
24 Correct 8 ms 6528 KB Output is correct
25 Correct 8 ms 6528 KB Output is correct
26 Correct 8 ms 6528 KB Output is correct
27 Correct 8 ms 6528 KB Output is correct
28 Correct 8 ms 6528 KB Output is correct
29 Correct 8 ms 6528 KB Output is correct
30 Correct 10 ms 6528 KB Output is correct
31 Correct 8 ms 6528 KB Output is correct
32 Correct 9 ms 6528 KB Output is correct
33 Correct 8 ms 6528 KB Output is correct
34 Correct 8 ms 6528 KB Output is correct
35 Correct 8 ms 6528 KB Output is correct
36 Correct 8 ms 6528 KB Output is correct
37 Correct 8 ms 6528 KB Output is correct
38 Correct 14 ms 7552 KB Output is correct
39 Correct 14 ms 7552 KB Output is correct
40 Correct 15 ms 7552 KB Output is correct
41 Correct 14 ms 7552 KB Output is correct
42 Correct 16 ms 7680 KB Output is correct
43 Correct 16 ms 7552 KB Output is correct
44 Correct 15 ms 7552 KB Output is correct
45 Correct 14 ms 7552 KB Output is correct
46 Correct 16 ms 7680 KB Output is correct
47 Correct 16 ms 7552 KB Output is correct
48 Correct 13 ms 7552 KB Output is correct
49 Correct 13 ms 7552 KB Output is correct
50 Correct 15 ms 7788 KB Output is correct
51 Correct 15 ms 7680 KB Output is correct
52 Correct 15 ms 7552 KB Output is correct
53 Correct 16 ms 7808 KB Output is correct
54 Correct 15 ms 7808 KB Output is correct
55 Correct 20 ms 7552 KB Output is correct
56 Correct 171 ms 31456 KB Output is correct
57 Correct 154 ms 31712 KB Output is correct
58 Correct 136 ms 30432 KB Output is correct
59 Correct 137 ms 30408 KB Output is correct
60 Correct 180 ms 30824 KB Output is correct
61 Correct 137 ms 30472 KB Output is correct
62 Correct 148 ms 31588 KB Output is correct
63 Correct 138 ms 30816 KB Output is correct
64 Correct 132 ms 30816 KB Output is correct
65 Correct 147 ms 30436 KB Output is correct
66 Correct 155 ms 29924 KB Output is correct
67 Correct 207 ms 30052 KB Output is correct
68 Correct 212 ms 30052 KB Output is correct
69 Correct 169 ms 30048 KB Output is correct
70 Correct 210 ms 30176 KB Output is correct
71 Correct 206 ms 30052 KB Output is correct
72 Correct 168 ms 30180 KB Output is correct
73 Correct 210 ms 30176 KB Output is correct
74 Correct 115 ms 29924 KB Output is correct
75 Correct 110 ms 29924 KB Output is correct
76 Correct 176 ms 33636 KB Output is correct
77 Correct 198 ms 33632 KB Output is correct
78 Correct 205 ms 33248 KB Output is correct
79 Correct 213 ms 30052 KB Output is correct
80 Correct 170 ms 30820 KB Output is correct
81 Correct 123 ms 29920 KB Output is correct
82 Correct 180 ms 30816 KB Output is correct
83 Correct 176 ms 30564 KB Output is correct
84 Correct 209 ms 30048 KB Output is correct
85 Correct 183 ms 30432 KB Output is correct
86 Correct 155 ms 30304 KB Output is correct
87 Correct 180 ms 30180 KB Output is correct
88 Correct 181 ms 30436 KB Output is correct
89 Correct 168 ms 30412 KB Output is correct
90 Correct 222 ms 33380 KB Output is correct
91 Correct 208 ms 31976 KB Output is correct
92 Correct 165 ms 30048 KB Output is correct
93 Correct 214 ms 30048 KB Output is correct
94 Correct 170 ms 30436 KB Output is correct
95 Correct 242 ms 30036 KB Output is correct
96 Correct 223 ms 33636 KB Output is correct
97 Correct 227 ms 33652 KB Output is correct
98 Correct 240 ms 33652 KB Output is correct
99 Correct 203 ms 33504 KB Output is correct
100 Correct 179 ms 33632 KB Output is correct
101 Correct 215 ms 33636 KB Output is correct
102 Correct 181 ms 34020 KB Output is correct
103 Correct 168 ms 30560 KB Output is correct