# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
542623 |
2022-03-27T08:17:56 Z |
jamezzz |
Sky Walking (IOI19_walk) |
C++17 |
|
1801 ms |
380276 KB |
#include "walk.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll,int> li;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));
#define mod 1000000007
inline int add(int a,int b){
int r=a+b;
while(r>=mod)r-=mod;
while(r<0)r+=mod;
return r;
}
inline int mult(int a,int b){
return (int)(((ll)(a*b))%mod);
}
inline int rd(){
int x=0;
char ch=getchar_unlocked();
while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
x=(x<<3)+(x<<1)+(ch&15);
ch=getchar_unlocked();
}
return x;
}
#define maxn 100005
int n,m,par[maxn];
vector<int> b[maxn];
map<ll,int> id;
int cnt;
ll dist[10*maxn];
vii AL[10*maxn];
priority_queue<li,vector<li>,greater<li>> pq;
int getid(int x,int y){
ll h=(ll)x*1e9+y;
if(!id.count(h))id[h]=cnt++;
return id[h];
}
int fp(int i){
return (par[i]==i)?i:par[i]=fp(par[i]);
}
ll min_distance(vi x,vi h,vi l,vi r,vi y,int s,int g){
n=sz(x);m=sz(l);
vector<ii> v1,v2;
for(int i=0;i<n;++i)v1.pb({h[i],i});
for(int i=0;i<m;++i)v2.pb({y[i],i});
sort(all(v1));sort(all(v2));
for(int i=0;i<=n;++i)par[i]=i;
int ptr=0;
for(int i=0;i<m;++i){
while(ptr!=n&&v1[ptr].fi<v2[i].fi){
int j=v1[ptr].se;
if(j!=0)par[j-1]=j;
++ptr;
}
int j=v2[i].se;
int pv=-1,cur=l[j];
while(cur<=r[j]){
b[cur].pb(v2[i].fi);
if(pv!=-1){
int u=getid(x[pv],v2[i].fi);
int v=getid(x[cur],v2[i].fi);
int w=x[cur]-x[pv];
AL[u].pb({v,w});
AL[v].pb({u,w});
}
pv=cur;
cur=fp(cur)+1;
}
}
for(int i=0;i<n;++i){
b[i].pb(0);
disc(b[i]);
for(int j=1;j<sz(b[i]);++j){
int u=getid(x[i],b[i][j-1]);
int v=getid(x[i],b[i][j]);
int w=b[i][j]-b[i][j-1];
AL[u].pb({v,w});
AL[v].pb({u,w});
}
}
for(int i=0;i<cnt;++i)dist[i]=LINF;
int src=getid(x[s],0);
dist[src]=0;pq.push({0,src});
while(!pq.empty()){
auto[d,u]=pq.top();
pq.pop();
if(d>dist[u])continue;
for(auto[v,w]:AL[u]){
if(dist[v]>dist[u]+w){
dist[v]=dist[u]+w;
pq.push({dist[v],v});
}
}
}
ll ans=dist[getid(x[g],0)];
return (ans==LINF)?-1:ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
26068 KB |
Output is correct |
2 |
Correct |
16 ms |
26056 KB |
Output is correct |
3 |
Incorrect |
16 ms |
26136 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
26088 KB |
Output is correct |
2 |
Correct |
13 ms |
26068 KB |
Output is correct |
3 |
Correct |
1352 ms |
133996 KB |
Output is correct |
4 |
Correct |
1217 ms |
142120 KB |
Output is correct |
5 |
Correct |
877 ms |
127800 KB |
Output is correct |
6 |
Correct |
761 ms |
116276 KB |
Output is correct |
7 |
Correct |
896 ms |
127992 KB |
Output is correct |
8 |
Correct |
1801 ms |
164648 KB |
Output is correct |
9 |
Correct |
966 ms |
125208 KB |
Output is correct |
10 |
Runtime error |
1416 ms |
380276 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
32836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
32836 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
26068 KB |
Output is correct |
2 |
Correct |
16 ms |
26056 KB |
Output is correct |
3 |
Incorrect |
16 ms |
26136 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |