# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
763855 | qwerasdfzxcl | Palembang Bridges (APIO15_bridge) | C++17 | 2059 ms | 312 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;
typedef long long ll;
ll solve2(vector<pair<int, int>> V){
if (V.empty()) return 0;
ll ret = 4e18;
vector<int> X;
for (auto &[x, y]:V) {X.push_back(x); X.push_back(y);}
for (int i=0;i<(int)X.size();i++){
for (int j=i+1;j<(int)X.size();j++){
ll val = 0;
for (auto &[x, y]:V){
val += min(abs(x-X[i]) + abs(y-X[i]), abs(x-X[j]) + abs(y-X[j]));
}
ret = min(ret, val);
}
}
return ret;
}
int main(){
int k, n;
scanf("%d %d", &k, &n);
ll ans = 0;
vector<pair<int, int>> V;
for (int i=1;i<=n;i++){
char cx, cy;
int px, py;
scanf(" %c %d %c %d", &cx, &px, &cy, &py);
if (cx==cy) {ans += abs(px-py); continue;}
if (cx=='B') swap(px, py);
V.emplace_back(px, py);
ans++;
}
if (k==2) ans += solve2(V);
printf("%lld\n", ans);
}
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... |