# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
295318 |
2020-09-09T15:35:04 Z |
최은수(#5799) |
치료 계획 (JOI20_treatment) |
C++17 |
|
1696 ms |
209904 KB |
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
const int mx=100010;
struct query
{
int t,l,r,c;
};
vector<pi>adj[mx*20];
ll dis[mx*20];
inline void dijk(int n,int s)
{
fill(dis,dis+n,INF);
priority_queue<pl,vector<pl>,greater<pl> >pq;
pq.ep(dis[s]=0,s);
while(!pq.empty())
{
int x=pq.top().se;
ll w=pq.top().fi;
pq.pop();
if(dis[x]!=w)
continue;
for(pi&t:adj[x])
if(dis[t.fi]>w+t.se)
pq.ep(dis[t.fi]=w+t.se,t.fi);
}
return;
}
int nct;
int nd[mx*4];
vector<query>qv;
void con(int n,int s,int e,const vector<int>&v)
{
if(s==e)
{
nd[n]=v[s];
return;
}
nd[n]=nct++;
int m=s+(e-s)/2;
con(n*2,s,m,v);
con(n*2+1,m+1,e,v);
adj[nd[n]].eb(nd[n*2],s==m?qv[v[s]].c:0);
adj[nd[n]].eb(nd[n*2+1],m+1==e?qv[v[e]].c:0);
return;
}
void put(int n,int s,int e,int S,int E,int st)
{
if(s>E||S>e)
return;
if(S<=s&&e<=E)
{
adj[st].eb(nd[n],s==e?qv[nd[n]].c:0);
return;
}
int m=s+(e-s)/2;
put(n*2,s,m,S,E,st);
put(n*2+1,m+1,e,S,E,st);
return;
}
void dnc(const vector<int>&v,int s,int e)
{
if(s==e)
return;
int m=s+(e-s)/2;
dnc(v,s,m);
dnc(v,m+1,e);
vector<int>lv,rv;
for(int i=s;i<=m;i++)
lv.eb(v[i]);
for(int i=m;i++<e;)
rv.eb(v[i]);
sort(all(lv),[&](const int&x,const int&y){return qv[x].l-qv[x].t<qv[y].l-qv[y].t;});
sort(all(rv),[&](const int&x,const int&y){return qv[x].l+qv[x].t<qv[y].l+qv[y].t;});
{
int lmx=(int)lv.size()-1;
con(1,0,lmx,lv);
for(int&t:rv)
{
int sc=-1,ec=lmx;
int cval=qv[t].r-qv[t].t+1;
while(sc<ec)
{
int mc=sc+(ec-sc+1)/2;
if(cval>=qv[lv[mc]].l-qv[lv[mc]].t)
sc=mc;
else
ec=mc-1;
}
if(sc>=0)
put(1,0,lmx,0,sc,t);
}
}
{
int rmx=(int)rv.size()-1;
con(1,0,rmx,rv);
for(int&t:lv)
{
int sc=-1,ec=rmx;
int cval=qv[t].r+qv[t].t+1;
while(sc<ec)
{
int mc=sc+(ec-sc+1)/2;
if(cval>=qv[rv[mc]].l+qv[rv[mc]].t)
sc=mc;
else
ec=mc-1;
}
if(sc>=0)
put(1,0,rmx,0,sc,t);
}
}
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
qv.resize(m);
for(auto&t:qv)
cin>>t.t>>t.l>>t.r>>t.c;
for(int i=0;i<m;i++)
{
if(qv[i].l==1)
adj[m+1].eb(i,qv[i].c);
if(qv[i].r==n)
adj[i].eb(m,0);
}
nct=m+2;
vector<int>cv(m);
for(int i=0;i<m;i++)
cv[i]=i;
sort(all(cv),[&](const int&x,const int&y){return qv[x].t<qv[y].t;});
dnc(cv,0,m-1);
dijk(nct,m+1);
if(dis[m]==INF)
dis[m]=-1;
cout<<dis[m]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1215 ms |
187560 KB |
Output is correct |
2 |
Correct |
1085 ms |
187816 KB |
Output is correct |
3 |
Correct |
1218 ms |
178892 KB |
Output is correct |
4 |
Correct |
1248 ms |
183656 KB |
Output is correct |
5 |
Correct |
1126 ms |
181668 KB |
Output is correct |
6 |
Correct |
1033 ms |
171304 KB |
Output is correct |
7 |
Correct |
823 ms |
160796 KB |
Output is correct |
8 |
Correct |
818 ms |
178600 KB |
Output is correct |
9 |
Correct |
771 ms |
169896 KB |
Output is correct |
10 |
Correct |
679 ms |
160284 KB |
Output is correct |
11 |
Correct |
1159 ms |
169356 KB |
Output is correct |
12 |
Correct |
1188 ms |
169064 KB |
Output is correct |
13 |
Correct |
1404 ms |
190328 KB |
Output is correct |
14 |
Correct |
1425 ms |
190532 KB |
Output is correct |
15 |
Correct |
1389 ms |
188236 KB |
Output is correct |
16 |
Correct |
1397 ms |
188004 KB |
Output is correct |
17 |
Correct |
1450 ms |
188172 KB |
Output is correct |
18 |
Correct |
1275 ms |
171532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47352 KB |
Output is correct |
2 |
Correct |
37 ms |
47272 KB |
Output is correct |
3 |
Correct |
33 ms |
47352 KB |
Output is correct |
4 |
Correct |
41 ms |
47352 KB |
Output is correct |
5 |
Correct |
34 ms |
47352 KB |
Output is correct |
6 |
Correct |
39 ms |
47352 KB |
Output is correct |
7 |
Correct |
32 ms |
47352 KB |
Output is correct |
8 |
Correct |
34 ms |
47264 KB |
Output is correct |
9 |
Correct |
32 ms |
47336 KB |
Output is correct |
10 |
Correct |
41 ms |
47352 KB |
Output is correct |
11 |
Correct |
33 ms |
47352 KB |
Output is correct |
12 |
Correct |
35 ms |
47288 KB |
Output is correct |
13 |
Correct |
34 ms |
47352 KB |
Output is correct |
14 |
Correct |
39 ms |
47360 KB |
Output is correct |
15 |
Correct |
34 ms |
47352 KB |
Output is correct |
16 |
Correct |
38 ms |
47352 KB |
Output is correct |
17 |
Correct |
44 ms |
47360 KB |
Output is correct |
18 |
Correct |
32 ms |
47360 KB |
Output is correct |
19 |
Correct |
33 ms |
47304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
47352 KB |
Output is correct |
2 |
Correct |
37 ms |
47272 KB |
Output is correct |
3 |
Correct |
33 ms |
47352 KB |
Output is correct |
4 |
Correct |
41 ms |
47352 KB |
Output is correct |
5 |
Correct |
34 ms |
47352 KB |
Output is correct |
6 |
Correct |
39 ms |
47352 KB |
Output is correct |
7 |
Correct |
32 ms |
47352 KB |
Output is correct |
8 |
Correct |
34 ms |
47264 KB |
Output is correct |
9 |
Correct |
32 ms |
47336 KB |
Output is correct |
10 |
Correct |
41 ms |
47352 KB |
Output is correct |
11 |
Correct |
33 ms |
47352 KB |
Output is correct |
12 |
Correct |
35 ms |
47288 KB |
Output is correct |
13 |
Correct |
34 ms |
47352 KB |
Output is correct |
14 |
Correct |
39 ms |
47360 KB |
Output is correct |
15 |
Correct |
34 ms |
47352 KB |
Output is correct |
16 |
Correct |
38 ms |
47352 KB |
Output is correct |
17 |
Correct |
44 ms |
47360 KB |
Output is correct |
18 |
Correct |
32 ms |
47360 KB |
Output is correct |
19 |
Correct |
33 ms |
47304 KB |
Output is correct |
20 |
Correct |
66 ms |
51092 KB |
Output is correct |
21 |
Correct |
67 ms |
51064 KB |
Output is correct |
22 |
Correct |
55 ms |
50300 KB |
Output is correct |
23 |
Correct |
57 ms |
50188 KB |
Output is correct |
24 |
Correct |
68 ms |
51960 KB |
Output is correct |
25 |
Correct |
68 ms |
51576 KB |
Output is correct |
26 |
Correct |
64 ms |
51320 KB |
Output is correct |
27 |
Correct |
59 ms |
51192 KB |
Output is correct |
28 |
Correct |
75 ms |
51960 KB |
Output is correct |
29 |
Correct |
70 ms |
51512 KB |
Output is correct |
30 |
Correct |
63 ms |
51320 KB |
Output is correct |
31 |
Correct |
59 ms |
51196 KB |
Output is correct |
32 |
Correct |
75 ms |
52312 KB |
Output is correct |
33 |
Correct |
78 ms |
51708 KB |
Output is correct |
34 |
Correct |
70 ms |
51832 KB |
Output is correct |
35 |
Correct |
75 ms |
52344 KB |
Output is correct |
36 |
Correct |
66 ms |
51704 KB |
Output is correct |
37 |
Correct |
70 ms |
51832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1215 ms |
187560 KB |
Output is correct |
2 |
Correct |
1085 ms |
187816 KB |
Output is correct |
3 |
Correct |
1218 ms |
178892 KB |
Output is correct |
4 |
Correct |
1248 ms |
183656 KB |
Output is correct |
5 |
Correct |
1126 ms |
181668 KB |
Output is correct |
6 |
Correct |
1033 ms |
171304 KB |
Output is correct |
7 |
Correct |
823 ms |
160796 KB |
Output is correct |
8 |
Correct |
818 ms |
178600 KB |
Output is correct |
9 |
Correct |
771 ms |
169896 KB |
Output is correct |
10 |
Correct |
679 ms |
160284 KB |
Output is correct |
11 |
Correct |
1159 ms |
169356 KB |
Output is correct |
12 |
Correct |
1188 ms |
169064 KB |
Output is correct |
13 |
Correct |
1404 ms |
190328 KB |
Output is correct |
14 |
Correct |
1425 ms |
190532 KB |
Output is correct |
15 |
Correct |
1389 ms |
188236 KB |
Output is correct |
16 |
Correct |
1397 ms |
188004 KB |
Output is correct |
17 |
Correct |
1450 ms |
188172 KB |
Output is correct |
18 |
Correct |
1275 ms |
171532 KB |
Output is correct |
19 |
Correct |
32 ms |
47352 KB |
Output is correct |
20 |
Correct |
37 ms |
47272 KB |
Output is correct |
21 |
Correct |
33 ms |
47352 KB |
Output is correct |
22 |
Correct |
41 ms |
47352 KB |
Output is correct |
23 |
Correct |
34 ms |
47352 KB |
Output is correct |
24 |
Correct |
39 ms |
47352 KB |
Output is correct |
25 |
Correct |
32 ms |
47352 KB |
Output is correct |
26 |
Correct |
34 ms |
47264 KB |
Output is correct |
27 |
Correct |
32 ms |
47336 KB |
Output is correct |
28 |
Correct |
41 ms |
47352 KB |
Output is correct |
29 |
Correct |
33 ms |
47352 KB |
Output is correct |
30 |
Correct |
35 ms |
47288 KB |
Output is correct |
31 |
Correct |
34 ms |
47352 KB |
Output is correct |
32 |
Correct |
39 ms |
47360 KB |
Output is correct |
33 |
Correct |
34 ms |
47352 KB |
Output is correct |
34 |
Correct |
38 ms |
47352 KB |
Output is correct |
35 |
Correct |
44 ms |
47360 KB |
Output is correct |
36 |
Correct |
32 ms |
47360 KB |
Output is correct |
37 |
Correct |
33 ms |
47304 KB |
Output is correct |
38 |
Correct |
66 ms |
51092 KB |
Output is correct |
39 |
Correct |
67 ms |
51064 KB |
Output is correct |
40 |
Correct |
55 ms |
50300 KB |
Output is correct |
41 |
Correct |
57 ms |
50188 KB |
Output is correct |
42 |
Correct |
68 ms |
51960 KB |
Output is correct |
43 |
Correct |
68 ms |
51576 KB |
Output is correct |
44 |
Correct |
64 ms |
51320 KB |
Output is correct |
45 |
Correct |
59 ms |
51192 KB |
Output is correct |
46 |
Correct |
75 ms |
51960 KB |
Output is correct |
47 |
Correct |
70 ms |
51512 KB |
Output is correct |
48 |
Correct |
63 ms |
51320 KB |
Output is correct |
49 |
Correct |
59 ms |
51196 KB |
Output is correct |
50 |
Correct |
75 ms |
52312 KB |
Output is correct |
51 |
Correct |
78 ms |
51708 KB |
Output is correct |
52 |
Correct |
70 ms |
51832 KB |
Output is correct |
53 |
Correct |
75 ms |
52344 KB |
Output is correct |
54 |
Correct |
66 ms |
51704 KB |
Output is correct |
55 |
Correct |
70 ms |
51832 KB |
Output is correct |
56 |
Correct |
1074 ms |
148880 KB |
Output is correct |
57 |
Correct |
1060 ms |
149060 KB |
Output is correct |
58 |
Correct |
935 ms |
144848 KB |
Output is correct |
59 |
Correct |
948 ms |
144732 KB |
Output is correct |
60 |
Correct |
743 ms |
122036 KB |
Output is correct |
61 |
Correct |
1155 ms |
144524 KB |
Output is correct |
62 |
Correct |
1111 ms |
149184 KB |
Output is correct |
63 |
Correct |
520 ms |
112264 KB |
Output is correct |
64 |
Correct |
520 ms |
112068 KB |
Output is correct |
65 |
Correct |
1455 ms |
188492 KB |
Output is correct |
66 |
Correct |
707 ms |
122024 KB |
Output is correct |
67 |
Correct |
1447 ms |
181592 KB |
Output is correct |
68 |
Correct |
1357 ms |
175924 KB |
Output is correct |
69 |
Correct |
1107 ms |
174240 KB |
Output is correct |
70 |
Correct |
1570 ms |
182988 KB |
Output is correct |
71 |
Correct |
1208 ms |
178692 KB |
Output is correct |
72 |
Correct |
1084 ms |
172828 KB |
Output is correct |
73 |
Correct |
1455 ms |
182908 KB |
Output is correct |
74 |
Correct |
971 ms |
178640 KB |
Output is correct |
75 |
Correct |
831 ms |
170920 KB |
Output is correct |
76 |
Correct |
1473 ms |
181156 KB |
Output is correct |
77 |
Correct |
1696 ms |
209904 KB |
Output is correct |
78 |
Correct |
1524 ms |
190652 KB |
Output is correct |
79 |
Correct |
1534 ms |
181992 KB |
Output is correct |
80 |
Correct |
1515 ms |
188432 KB |
Output is correct |
81 |
Correct |
1123 ms |
181732 KB |
Output is correct |
82 |
Correct |
1592 ms |
189192 KB |
Output is correct |
83 |
Correct |
1515 ms |
189332 KB |
Output is correct |
84 |
Correct |
1467 ms |
182568 KB |
Output is correct |
85 |
Correct |
1167 ms |
180388 KB |
Output is correct |
86 |
Correct |
1192 ms |
179672 KB |
Output is correct |
87 |
Correct |
1246 ms |
180396 KB |
Output is correct |
88 |
Correct |
1100 ms |
162860 KB |
Output is correct |
89 |
Correct |
1200 ms |
180392 KB |
Output is correct |
90 |
Correct |
1465 ms |
186776 KB |
Output is correct |
91 |
Correct |
1359 ms |
182824 KB |
Output is correct |
92 |
Correct |
1277 ms |
181772 KB |
Output is correct |
93 |
Correct |
1417 ms |
181928 KB |
Output is correct |
94 |
Correct |
1378 ms |
185856 KB |
Output is correct |
95 |
Correct |
1342 ms |
178472 KB |
Output is correct |
96 |
Correct |
1436 ms |
187944 KB |
Output is correct |
97 |
Correct |
1467 ms |
182708 KB |
Output is correct |
98 |
Correct |
1450 ms |
183452 KB |
Output is correct |
99 |
Correct |
1501 ms |
183640 KB |
Output is correct |
100 |
Correct |
1416 ms |
178724 KB |
Output is correct |
101 |
Correct |
1472 ms |
181900 KB |
Output is correct |
102 |
Correct |
1186 ms |
157524 KB |
Output is correct |
103 |
Correct |
1243 ms |
182184 KB |
Output is correct |