제출 #549802

#제출 시각아이디문제언어결과실행 시간메모리
549802ala2Palembang Bridges (APIO15_bridge)C++14
22 / 100
205 ms2464 KiB
#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=-3,r=1000000005; int y=200; int mn=1e18; while(y--) { int mid1=l+(r-l)/3; int mid2=l+((r-l)/3)*2; mn=min(mn,f(mid1,1e18)); mn=min(mn,f(mid2,1e18)); if(f(mid2,1e18)<=f(mid1,1e18)) { l=mid1; } else r=mid2; } mn=min(mn,f(l,1e18)); cout<<min(mn,f(r,1e18))+ans<<endl; return 0; } // ___________________________________ int mn=1e18; for(int i=0;i<v.size();i++) { for(int j=i;j<v.size();j++) { mn=min(mn,f(v[i].F,v[j].F)); } } 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:38:9: warning: unused variable 'x' [-Wunused-variable]
   38 |     int x=v.size()/2;
      |         ^
bridge.cpp:63: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]
   63 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
bridge.cpp:65: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]
   65 |         for(int j=i;j<v.size();j++)
      |                     ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...