# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
762323 |
2023-06-21T10:16:43 Z |
aihay |
Sky Walking (IOI19_walk) |
C++14 |
|
2041 ms |
538052 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define F first
#define S second
#define PB push_back
#define FR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR(i,n) FR(i,0,n)
#define SZ(x) int(x.size())
const LL MAAX=1e18;
const int MOD=1e9+7;
const int MAX=1e9;
int n,m,s,g,x[100010],h[100010],l[100010],r[100010],y[100010],idxx;
pair<int,int> srtb[100010];
pair<int,pair<int,int>> srts[100010];
LL cst[1000010];
vector<int> v[2000010];
map<pair<int,int>,int> mp;
pair<int,int> inter[2000010];
LL dijk(){
for(int i=0;i<idxx;i++)
cst[i]=MAAX;
priority_queue<pair<LL,int>> pq;
pq.push({0,1});
while(pq.size()){
LL cost=-pq.top().F;
int idx=pq.top().S;
pq.pop();
if(cost>cst[idx])
continue;
cst[idx]=cost;
if(idx==2)
break;
for(int i=0;i<v[idx].size();i++){
int x1=inter[idx].F,x2=inter[v[idx][i]].F;
int y1=inter[idx].S,y2=inter[v[idx][i]].S;
LL ncst=cost+abs(x2-x1)+abs(y2-y1);
int nidx=v[idx][i];
if(ncst<cst[nidx]){
cst[nidx]=ncst;
pq.push({-ncst,nidx});
}
}
}
if(cst[2]==MAAX)
cst[2]=-1;
return cst[2];
}
map<int,vector<int>> vec;
LL min_distance(vector<int> X,vector<int> H,vector<int> L,vector<int> R,vector<int> Y,int S,int G){
n=X.size();
m=L.size();
s=S,g=G;
for(int i=0;i<n;i++){
x[i]=X[i];
h[i]=H[i];
vec[x[i]].PB(0);
srtb[i]={-h[i],x[i]};
}
sort(srtb,srtb+n);
idxx++;
mp[{x[s],0}]=idxx++;
inter[1]={x[s],0};
mp[{x[g],0}]=idxx++;
inter[2]={x[g],0};
for(int i=0;i<n;i++){
srtb[i].F*=-1;
if(mp[{x[i],0}]==0){
mp[{x[i],0}]=idxx++;
inter[idxx-1]={x[i],0};
}
}
for(int i=0;i<m;i++){
l[i]=L[i];
r[i]=R[i];
y[i]=Y[i];
if(r[i]-l[i]>200)
srts[i]={-y[i],{x[l[i]],x[r[i]]}};
else{
srts[i]={1,{-1,-1}};
int lst=-1;
for(int j=l[i];j<=r[i];j++){
if(h[j]<y[i])
continue;
int xx=mp[{x[j],y[i]}];
if(xx==0){
mp[{x[j],y[i]}]=xx=idxx++;
inter[idxx-1]={x[j],y[i]};
vec[x[j]].PB(y[i]);
}
if(~lst){
v[lst].PB(xx);
v[xx].PB(lst);
}
lst=xx;
}
}
}
sort(srts,srts+m);
set<int> curst;
int idx=0;
for(int i=0;i<m;i++){
if(srts[i].F==1)
break;
srts[i].F=-srts[i].F;
while(idx<n&&srtb[idx].F>=srts[i].F)
curst.insert(srtb[idx++].S);
int lst=-1;
for(set<int>::iterator j=curst.lower_bound(srts[i].S.F);j!=curst.end()&&(*j)<=srts[i].S.S;j++){
int xx=mp[{(*j),srts[i].F}];
if(xx==0){
mp[{(*j),srts[i].F}]=xx=idxx++;
inter[idxx-1]={(*j),srts[i].F};
vec[(*j)].PB(srts[i].F);
}
if(~lst){
v[lst].PB(xx);
v[xx].PB(lst);
}
lst=xx;
}
}
for(int i=0;i<n;i++){
sort(vec[x[i]].begin(),vec[x[i]].end());
for(int j=1;j<vec[x[i]].size();j++){
v[mp[{x[i],vec[x[i]][j]}]].PB(mp[{x[i],vec[x[i]][j-1]}]);
v[mp[{x[i],vec[x[i]][j-1]}]].PB(mp[{x[i],vec[x[i]][j]}]);
}
}
return dijk();
}
Compilation message
walk.cpp: In function 'LL dijk()':
walk.cpp:35:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i=0;i<v[idx].size();i++){
| ~^~~~~~~~~~~~~~
walk.cpp: In function 'LL min_distance(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, int, int)':
walk.cpp:126:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
126 | for(int j=1;j<vec[x[i]].size();j++){
| ~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
47316 KB |
Output is correct |
2 |
Correct |
21 ms |
47216 KB |
Output is correct |
3 |
Correct |
21 ms |
47300 KB |
Output is correct |
4 |
Correct |
21 ms |
47272 KB |
Output is correct |
5 |
Correct |
22 ms |
47328 KB |
Output is correct |
6 |
Correct |
23 ms |
47388 KB |
Output is correct |
7 |
Correct |
22 ms |
47328 KB |
Output is correct |
8 |
Correct |
24 ms |
47316 KB |
Output is correct |
9 |
Correct |
22 ms |
47248 KB |
Output is correct |
10 |
Correct |
22 ms |
47316 KB |
Output is correct |
11 |
Correct |
23 ms |
47212 KB |
Output is correct |
12 |
Correct |
26 ms |
47320 KB |
Output is correct |
13 |
Correct |
23 ms |
47236 KB |
Output is correct |
14 |
Correct |
22 ms |
47316 KB |
Output is correct |
15 |
Correct |
24 ms |
47284 KB |
Output is correct |
16 |
Correct |
23 ms |
47224 KB |
Output is correct |
17 |
Correct |
24 ms |
47420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
47180 KB |
Output is correct |
2 |
Correct |
23 ms |
47268 KB |
Output is correct |
3 |
Correct |
1072 ms |
135848 KB |
Output is correct |
4 |
Correct |
1486 ms |
157204 KB |
Output is correct |
5 |
Correct |
1115 ms |
148340 KB |
Output is correct |
6 |
Correct |
1000 ms |
139520 KB |
Output is correct |
7 |
Correct |
1114 ms |
148444 KB |
Output is correct |
8 |
Correct |
1339 ms |
158512 KB |
Output is correct |
9 |
Correct |
1237 ms |
140508 KB |
Output is correct |
10 |
Correct |
2041 ms |
191216 KB |
Output is correct |
11 |
Correct |
682 ms |
102952 KB |
Output is correct |
12 |
Correct |
553 ms |
99884 KB |
Output is correct |
13 |
Correct |
1767 ms |
177820 KB |
Output is correct |
14 |
Correct |
476 ms |
102960 KB |
Output is correct |
15 |
Correct |
540 ms |
104620 KB |
Output is correct |
16 |
Correct |
615 ms |
102752 KB |
Output is correct |
17 |
Correct |
605 ms |
97556 KB |
Output is correct |
18 |
Correct |
421 ms |
99872 KB |
Output is correct |
19 |
Correct |
47 ms |
50096 KB |
Output is correct |
20 |
Correct |
227 ms |
75140 KB |
Output is correct |
21 |
Correct |
585 ms |
93524 KB |
Output is correct |
22 |
Correct |
578 ms |
99728 KB |
Output is correct |
23 |
Correct |
659 ms |
112400 KB |
Output is correct |
24 |
Correct |
561 ms |
102660 KB |
Output is correct |
25 |
Correct |
552 ms |
96584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
58824 KB |
Output is correct |
2 |
Runtime error |
1465 ms |
538052 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
58824 KB |
Output is correct |
2 |
Runtime error |
1465 ms |
538052 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
47316 KB |
Output is correct |
2 |
Correct |
21 ms |
47216 KB |
Output is correct |
3 |
Correct |
21 ms |
47300 KB |
Output is correct |
4 |
Correct |
21 ms |
47272 KB |
Output is correct |
5 |
Correct |
22 ms |
47328 KB |
Output is correct |
6 |
Correct |
23 ms |
47388 KB |
Output is correct |
7 |
Correct |
22 ms |
47328 KB |
Output is correct |
8 |
Correct |
24 ms |
47316 KB |
Output is correct |
9 |
Correct |
22 ms |
47248 KB |
Output is correct |
10 |
Correct |
22 ms |
47316 KB |
Output is correct |
11 |
Correct |
23 ms |
47212 KB |
Output is correct |
12 |
Correct |
26 ms |
47320 KB |
Output is correct |
13 |
Correct |
23 ms |
47236 KB |
Output is correct |
14 |
Correct |
22 ms |
47316 KB |
Output is correct |
15 |
Correct |
24 ms |
47284 KB |
Output is correct |
16 |
Correct |
23 ms |
47224 KB |
Output is correct |
17 |
Correct |
24 ms |
47420 KB |
Output is correct |
18 |
Correct |
28 ms |
47180 KB |
Output is correct |
19 |
Correct |
23 ms |
47268 KB |
Output is correct |
20 |
Correct |
1072 ms |
135848 KB |
Output is correct |
21 |
Correct |
1486 ms |
157204 KB |
Output is correct |
22 |
Correct |
1115 ms |
148340 KB |
Output is correct |
23 |
Correct |
1000 ms |
139520 KB |
Output is correct |
24 |
Correct |
1114 ms |
148444 KB |
Output is correct |
25 |
Correct |
1339 ms |
158512 KB |
Output is correct |
26 |
Correct |
1237 ms |
140508 KB |
Output is correct |
27 |
Correct |
2041 ms |
191216 KB |
Output is correct |
28 |
Correct |
682 ms |
102952 KB |
Output is correct |
29 |
Correct |
553 ms |
99884 KB |
Output is correct |
30 |
Correct |
1767 ms |
177820 KB |
Output is correct |
31 |
Correct |
476 ms |
102960 KB |
Output is correct |
32 |
Correct |
540 ms |
104620 KB |
Output is correct |
33 |
Correct |
615 ms |
102752 KB |
Output is correct |
34 |
Correct |
605 ms |
97556 KB |
Output is correct |
35 |
Correct |
421 ms |
99872 KB |
Output is correct |
36 |
Correct |
47 ms |
50096 KB |
Output is correct |
37 |
Correct |
227 ms |
75140 KB |
Output is correct |
38 |
Correct |
585 ms |
93524 KB |
Output is correct |
39 |
Correct |
578 ms |
99728 KB |
Output is correct |
40 |
Correct |
659 ms |
112400 KB |
Output is correct |
41 |
Correct |
561 ms |
102660 KB |
Output is correct |
42 |
Correct |
552 ms |
96584 KB |
Output is correct |
43 |
Correct |
124 ms |
58824 KB |
Output is correct |
44 |
Runtime error |
1465 ms |
538052 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |