# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1054155 | Rojus | Palembang Bridges (APIO15_bridge) | C++14 | 0 ms | 348 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;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int k, n;
cin >> k >> n;
vector<pair<int, int>> v;
vector<int> sarasas;
set<int> s;
long long priedas=0;
for(int i=0; i<n; i++)
{
char cg, cd;
int ig, id;
cin >> cg >> ig >> cd >> id;
if(cg!=cd)
{
priedas++;
v.push_back({ig, id});
if(s.find(ig)==s.end())
{
s.insert(ig);
sarasas.push_back(ig);
}
if(s.find(id)==s.end())
{
s.insert(id);
sarasas.push_back(id);
}
}
else
{
priedas+=abs(ig-id);
}
}
sort(sarasas.begin(), sarasas.end());
if(k==1)
{
long long ats=INT_MAX;
for(int i=0; i<sarasas.size(); i++)
{
long long sum=0;
for(int j=0; j<v.size(); j++)
{
sum+=abs(v[j].first-sarasas[i])+abs(v[j].second-sarasas[i]);
}
ats=min(ats, sum);
}
ats+=priedas;
cout << ats;
}
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... |