제출 #60535

#제출 시각아이디문제언어결과실행 시간메모리
60535istleminPalembang Bridges (APIO15_bridge)C++14
41 / 100
2083 ms13560 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(ll i = a; i < ll(b); ++i) #define trav(a, v) for(auto& a : v) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define D(x) cerr << #x << " = " << x << endl typedef long long ll; typedef pair<ll, ll> pii; typedef vector<ll> vi; int main() { cin.sync_with_stdio(false); ll k,n; ll totDist = 0; vector<pair<ll,pii>> intervals; vector<ll> points; cin>>k>>n; rep(i,0,n){ char a,b; ll c,d; cin>>a>>c>>b>>d; if(a!=b){ intervals.push_back(make_pair(c+d,pii(c,d))); //points.push_back(c+d); }else{ totDist += abs(c-d); } } ll bestDist = 0; if(intervals.size()>1){ bestDist = 1e18; sort(all(intervals)); multiset<ll> right; multiset<ll> left; rep(i,0,intervals.size()){ if(i == 0){ left.insert(intervals[i].second.first); left.insert(intervals[i].second.second); }else{ right.insert(intervals[i].second.first); right.insert(intervals[i].second.second); } } auto it = right.begin(); advance(it, right.size()/2); ll rAt = *it; ll rSum = 0; for(auto it : right) rSum += abs(it - rAt); ll lAt = *left.begin(); ll lSum = abs(intervals[0].second.second-intervals[0].second.first); bestDist = lSum + rSum; rep(i,1,intervals.size()-1){ ll a = intervals[i].second.first; ll b = intervals[i].second.second; left.insert(a); left.insert(b); lSum += abs(lAt-a) + abs(lAt-b); right.erase(right.lower_bound(a)); right.erase(right.lower_bound(b)); rSum -= abs(rAt-a) + abs(rAt-b); auto it = left.lower_bound(lAt); ll index = distance(left.begin(),it); while(index<left.size()/2){ lSum += (index*2 + 2 - left.size())*(*(next(it)) - *it); advance(it,1); ++index; } lAt = *it; it = right.lower_bound(rAt); index = distance(right.begin(),it); while(index<right.size()/2){ rSum += (index*2 + 2 - right.size())*(*(next(it)) - *it); advance(it,1); ++index; } rAt = *it; bestDist = min(bestDist,lSum + rSum); } }else if(intervals.size()==1){ bestDist = abs(intervals[0].second.second - intervals[0].second.first); } totDist += bestDist; totDist += intervals.size(); cout<<totDist<<endl; }

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

bridge.cpp: In function 'int main()':
bridge.cpp:68:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(index<left.size()/2){
          ~~~~~^~~~~~~~~~~~~~
bridge.cpp:76:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while(index<right.size()/2){
          ~~~~~^~~~~~~~~~~~~~~
#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...