Submission #1046345

#TimeUsernameProblemLanguageResultExecution timeMemory
1046345idasSky Walking (IOI19_walk)C++17
0 / 100
106 ms15264 KiB
#include "walk.h" #include "bits/stdc++.h" #define FOR(i, begin, end) for(int i=(begin); i<(end); i++) #define sz(x) ((int)((x).size())) #define pb push_back #define s second #define f first using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef tuple<int, int, int> tiii; const ll LINF=1e18; const int N=1e5+10; int n, m; vector<pii> ins; ll d[N]; long long min_distance(vector<int> x, vector<int> h, vector<int> l, vector<int> r, vector<int> y, int str, int g) { n=sz(x); m=sz(l); FOR(i, 0, m) { l[i]=x[l[i]]; r[i]=x[r[i]]; d[i]=LINF; } FOR(i, 0, m) { ins.pb({l[i],i}); ins.pb({r[i],i}); if(l[i]==x[0]) d[i]=min(d[i], 1LL*y[i]+r[i]-l[i]); } sort(ins.begin(), ins.end()); set<pii> st; ll ans=LINF; FOR(i, 0, 2*m) { vector<pii> now; while(i+1<2*m && ins[i+1].f==ins[i].f) { now.pb(ins[i]); i++; } now.pb(ins[i]); for(auto[pos, in] : now) { if(pos==l[in]) st.insert({y[in],in}); else st.erase({y[in],in}); } for(auto[pos, in] : now) { // cout << pos << ": "; if(pos==l[in]) continue; auto up=st.lower_bound({y[in],0}); // cout << pos << ": "; if(up!=st.end()) { ll new_up=d[in] + abs(up->f - y[in]) + r[up->s]-r[in]; d[up->s]=min(d[up->s], new_up); // cout << "u: " << up->f << " "; } auto down=st.upper_bound({y[in],0}); if(down!=st.begin()) { --down; ll new_down=d[in] + abs(down->f - y[in]) + r[down->s]-r[in]; d[down->s]=min(d[down->s], new_down); // cout << "d: " << up->f << " "; } if(r[in]==x[n-1]) { ans=min(ans, d[in]+y[in]); } } } // FOR(i, 0, m) { // cout << i << ": " << d[i] << endl; // } return ans; } /* 3 5 0 3 3 3 5 2 0 1 2 0 1 1 1 2 1 1 2 2 0 1 3 0 2 7 in1: 28 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...