# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1095187 | dpsaveslives | Palembang Bridges (APIO15_bridge) | C++17 | 36 ms | 4552 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 ll long long
#define f first
#define s second
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int K,N; cin >> K >> N;
if(K == 2){
cout << 0 << "\n";
return 0;
}
ll ans = 0;
vector<int> vec;
vector<pair<int,int>> dif;
for(int i = 0;i<N;++i){
char p1,p2; int s,t; cin >> p1 >> s >> p2 >> t;
if(p1 != p2){
vec.push_back(s); vec.push_back(t);
dif.push_back({s,t});
}
else{
ans += abs(s-t);
}
}
if(!vec.size()){
cout << ans << "\n";
return 0;
}
sort(vec.begin(),vec.end());
int med = vec[vec.size()/2];
for(int i = 0;i<dif.size();++i){
ans += abs(dif[i].f-med)+abs(dif[i].s-med)+1;
}
cout << ans << "\n";
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... |