제출 #914953

#제출 시각아이디문제언어결과실행 시간메모리
91495312345678Palembang Bridges (APIO15_bridge)C++17
22 / 100
33 ms5592 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5; #define ll long long ll k, n, b, d, cnt; char a, c; vector<ll> v, l; vector<pair<ll, ll>> p(nx); ll res, ans=LLONG_MAX; ll cal(int b1, int b2) { ll tmp=0; for (int i=0; i<cnt; i++) tmp+=min(abs(p[i].first-b1)+abs(p[i].second-b1), abs(p[i].first-b2)+abs(p[i].second-b2))+1; //cout<<"here "<<p[i].first<<' '<<p[i].second<<' '<<tmp<<'\n'; return tmp; } 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); else p[cnt++]={b, d}, l.push_back(b), l.push_back(d); } for (int i=0; i<l.size(); i++) for (int j=i+1; j<l.size(); j++) ans=min(ans, res+cal(l[i], l[j])); //cout<<res<<' '<<l[i]<<' '<<l[j]<<' '<<cal(l[i], l[j])<<'\n'; cout<<ans; } } /* 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */

컴파일 시 표준 에러 (stderr) 메시지

bridge.cpp: In function 'int main()':
bridge.cpp:53:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int i=0; i<l.size(); i++) for (int j=i+1; j<l.size(); j++) ans=min(ans, res+cal(l[i], l[j])); //cout<<res<<' '<<l[i]<<' '<<l[j]<<' '<<cal(l[i], l[j])<<'\n';
      |                       ~^~~~~~~~~
bridge.cpp:53:57: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int i=0; i<l.size(); i++) for (int j=i+1; j<l.size(); j++) ans=min(ans, res+cal(l[i], l[j])); //cout<<res<<' '<<l[i]<<' '<<l[j]<<' '<<cal(l[i], l[j])<<'\n';
      |                                                        ~^~~~~~~~~
#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...