# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
670935 | Dan4Life | Palembang Bridges (APIO15_bridge) | C++17 | 2 ms | 368 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
using ll = long long;
using pii = pair<int,int>;
#define all(a) a.begin(),a.end()
#define sz(a) (int)a.size()
const int maxn = (int)1e5+10;
const ll LINF = (ll)1e18;
vector<int> v;
vector<pii> segments;
deque<pii> bef,dur,aft;
int t, n, sum_bef, sum_dur, sum_aft;
int32_t main() {
cin >> t >> n; int tot = 0, sum = 0, ans=LINF;
for(int i = 0; i < n; i++){
char a, c; int b, d;
cin >> a >> b >> c >> d;
if(a==c) tot+=abs(b-d);
else{
if(b>d) swap(b,d); tot++;
segments.pb({b,d});
v.pb(b), v.pb(d);
}
}
v.pb(0), v.pb(1000000000);
sort(all(v));sort(all(segments));
v.erase(unique(all(v)), v.end());
for(auto u : segments) aft.pb(u), sum_aft+=u.fi+u.se;
for(auto u : v){
while(!aft.empty() and aft[0].fi<=u){
dur.pb(aft[0]);
sum_dur+=aft[0].se-aft[0].fi;
sum_aft-=aft[0].fi+aft[0].se;
aft.pop_front();
}
while(!dur.empty() and dur[0].se<u){
bef.pb(dur[0]);
sum_bef+=-dur[0].se-dur[0].fi;
sum_dur-=dur[0].se-dur[0].se;
dur.pop_front();
}
ans = min(ans, (sz(bef)-sz(aft))*2*u+sum_bef+sum_dur+sum_aft);
}
cout << ans+tot;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |