이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
using namespace std;
vector<pair<int,int>>v;
int f(int x,int y)
{
int g=0;
for(int i=0;i<v.size();i++)
{
g+=min( abs(v[i].F-x )+abs(v[i].S-x) ,abs(v[i].F-y )+abs(v[i].S-y));
}
return g;
}
signed main()
{
int n,k;
cin>>k>>n;
int ans=0;
for(int i=0;i<n;i++)
{
char x,y;
int a,b;
cin>>x>>a>>y>>b;
if(x==y)
{
ans+=abs(a-b);
}
else v.pb({a,b}),ans++;
}
if(k==1){
sort(v.B,v.E);
int x=v.size()/2;
int l=0,r=v.size()-1;
int y=200;
int mn=1e18;
while(y--)
{
int mid1=l+(r-l)/3;
int mid2=l+((r-l)/3)*2;
if(mid1<0||mid2>v.size()-1)
{
while(1)
{
}
}
if(0){
mn=min(mn,f(v[mid1].F,1e18));
mn=min(mn,f(v[mid2].F,1e18));
}
if(f(v[mid2].F,1e18)<=f(v[mid1].F,1e18))
{
l=mid1;
}
else
r=mid2;
}
if(0){
for(int i=0;i<4,i<v.size();i++)
mn=min(mn,f( v[i].F ,1e18));
for(int i=v.size()-1;i>=0,v.size()-i<=5;i--)
mn=min(mn,f( v[i].F ,1e18));
}
cout<<mn+ans<<endl;
return 0;
}
// ___________________________________
int mn=1e18;
for(int i=0;i<v.size();i++)
{
for(int j=0;j<v.size();j++)
{
mn=min(mn,f(v[i].S,v[j].S));
mn=min(mn,f(v[i].F,v[j].F));
mn=min(mn,f(v[i].S,v[j].F));
mn=min(mn,f(v[i].F,v[j].S));
//cout<<" "<<f(v[i].S,v[j].S)<<" "<<v[i].S<<" "<<v[j].S<<endl;
}
}
cout<<mn+ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
bridge.cpp: In function 'long long int f(long long int, long long int)':
bridge.cpp:13:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
bridge.cpp: In function 'int main()':
bridge.cpp:46:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | if(mid1<0||mid2>v.size()-1)
| ~~~~^~~~~~~~~~~
bridge.cpp:67:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(int i=0;i<4,i<v.size();i++)
| ~^~~~~~~~~
bridge.cpp:67:18: warning: left operand of comma operator has no effect [-Wunused-value]
67 | for(int i=0;i<4,i<v.size();i++)
| ~^~
bridge.cpp:69:27: warning: left operand of comma operator has no effect [-Wunused-value]
69 | for(int i=v.size()-1;i>=0,v.size()-i<=5;i--)
| ~^~~
bridge.cpp:38:9: warning: unused variable 'x' [-Wunused-variable]
38 | int x=v.size()/2;
| ^
bridge.cpp:77:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
bridge.cpp:79:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int j=0;j<v.size();j++)
| ~^~~~~~~~~
# | 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... |