제출 #585527

#제출 시각아이디문제언어결과실행 시간메모리
585527karriganPalembang Bridges (APIO15_bridge)C++14
22 / 100
46 ms5940 KiB
#include<bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr); using namespace std; struct line{ char x,z; long long y,t; }a[100009]; struct lena{ long long y,t; }b[100009]; long long pf[100009]; vector<long long>c; bool cmp(const lena &p, const lena &q){ return p.y+p.t<q.y+q.t; } int main() { fastio int k,n; cin>>k>>n; int cnt=0; long long ans=0; for (int i=1;i<=n;i++){ cin>>a[i].x>>a[i].y>>a[i].z>>a[i].t; if (a[i].x!=a[i].z){ b[++cnt]={a[i].y,a[i].t}; c.push_back(a[i].y); c.push_back(a[i].t); ans++; } else { ans+=abs(a[i].y-a[i].t); } } if (k==1){ sort(c.begin(),c.end()); int d=(int)c.size(); d/=2; for (int i=0;i<(int)c.size();i++){ if (c[i]<=c[d]){ ans=ans+c[d]-c[i]; } else ans=ans+c[i]-c[d]; } cout<<ans; } else { sort(b+1,b+1+cnt,cmp); for (int i=1;i<n;i++){ vector<long long>d; for (int j=1;j<=i;j++){ d.push_back(b[j].y); d.push_back(b[j].t); } sort(d.begin(),d.end()); int r=(int)d.size(); r/=2; for (auto v:d){ pf[i]+=abs(d[r]-v); } } long long cal=1e16; for (int i=n;i>1;i--){ vector<long long>d; for (int j=n;j>=i;j--){ d.push_back(b[j].y); d.push_back(b[j].t); } sort(d.begin(),d.end()); int r=(int)d.size(); long long gm=0; r/=2; for (auto v:d){ gm+=abs(d[r]-v); } cal=min(cal,gm+pf[i-1]+ans); } cout<<cal; } }
#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...