이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll k, n, b, d;
char a, c;
vector<ll> v;
vector<pair<ll, ll>> p;
long long res, mn=LLONG_MAX;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>k>>n;
if (k==1)
{
for (int i=0; i<n; i++)
{
cin>>a>>b>>c>>d;
if (a==c)
{
res+=abs(b-d);
continue;
}
v.push_back(b);
v.push_back(d);
res++;
}
sort(v.begin(), v.end());
int md=v[v.size()/2];
for (auto x:v) res+=abs(x-md);
cout<<res;
}
else
{
for (int i=0; i<n; i++)
{
cin>>a>>b>>c>>d;
if (a==c)
{
res+=abs(b-d);
continue;
}
p.push_back({min(b, d), max(b, d)});
res++;
}
sort(p.begin(), p.end());
for (int i=0; i<(int)p.size()-1; i++)
{
ll tmp=0;
int ed=i, st=i+1;
vector<int> t1, t2;
for (int j=0; j<=ed; j++) t1.push_back(p[j].first), t1.push_back(p[j].second);
for (int j=st; j<p.size(); j++) t2.push_back(p[j].first), t2.push_back(p[j].second);
ll md1=t1[(int)t1.size()/2], md2=t2[(int)t2.size()/2];
for (auto x:t1) tmp+=abs(x-md1);
for (auto x:t2) tmp+=abs(x-md2);
mn=min(mn, tmp);
}
cout<<res+mn;
}
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'int main()':
bridge.cpp:56:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int j=st; j<p.size(); j++) t2.push_back(p[j].first), t2.push_back(p[j].second);
| ~^~~~~~~~~| # | 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... |