# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
185582 | dndhk | Palembang Bridges (APIO15_bridge) | C++14 | 5 ms | 504 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>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 100000;
int N, K;
ll ans = 0;
vector<pll> vt;
vector<pll> v;
void solve1(){
ll sidx = 0, scnt = 0;
for(int i=0; i<vt.size(); i++){
v.pb({vt[i].first, 1});
v.pb({vt[i].second, -1});
sidx+=vt[i].first;
scnt--;
}
sort(v.begin(), v.end());
ll sum = -1;
for(int i=0; i<v.size(); i++){
//cout<<v[i].first<<" "<<2LL * (sidx+scnt*v[i].first)+ans<<endl;
if(sum==-1 || sum>sidx+scnt*v[i].first){
sum = sidx + scnt*v[i].first;
}
if(v[i].second==1){
sidx-=v[i].first;
scnt++;
}else{
scnt++;
sidx-=v[i].second;
}
}
if(sum!=-1) ans += 2LL * sum;
}
int main(){
scanf("%d%d", &K, &N);
for(int i=0; i<N; i++){
getchar();
char c1, c2;
int a, b;
scanf("%c %d %c %d", &c1, &a, &c2, &b);
if(c1==c2){
ans+=(ll)(max(a, b) - min(a, b));
}else{
ans += (ll)(max(a, b) - min(a, b) + 1);
vt.pb({(ll)min(a, b), (ll)max(a, b)});
}
}
if(K==1){
solve1();
}
cout<<ans;
return 0;
}
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... |