Submission #920053

#TimeUsernameProblemLanguageResultExecution timeMemory
920053AiperiiiPalembang Bridges (APIO15_bridge)C++14
22 / 100
100 ms9064 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int k,n; cin>>k>>n; vector <char> t1(n),t2(n); vector <int> x(n),y(n); for(int i=0;i<n;i++){ cin>>t1[i]>>x[i]>>t2[i]>>y[i]; } int ans=0,sum=0; vector <int> v,pr; for(int j=0;j<n;j++){ if(t1[j]==t2[j])ans+=abs(x[j]-y[j]); else{ ans++; v.pb(x[j]);v.pb(y[j]); } } sort(all(v)); for(int i=0;i<v.size();i++){ sum+=v[i]; pr.pb(sum); } int mn=1e18; for(int i=0;i<n;i++){ int res=ans; auto it=upper_bound(all(v),x[i]); if(it!=v.end()){ int pos=it-v.begin(); int cnt=v.size()-pos; pos--; int d=pr.back(); if(pos>=0)d-=pr[pos]; res+=d-cnt*x[i]; } if(it!=v.begin()){ it--; int pos=it-v.begin(); int d=pr[pos];pos++; res+=pos*x[i]-d; } mn=min(mn,res); } for(int i=0;i<n;i++){ int res=ans; auto it=upper_bound(all(v),y[i]); if(it!=v.end()){ int pos=it-v.begin(); int cnt=v.size()-pos; pos--; int d=pr.back(); if(pos>=0)d-=pr[pos]; res+=d-cnt*y[i]; } if(it!=v.begin()){ it--; int pos=it-v.begin(); int d=pr[pos];pos++; res+=pos*y[i]-d; } mn=min(mn,res); } cout<<mn<<"\n"; } /* 1 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:29:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |    for(int i=0;i<v.size();i++){
      |                ~^~~~~~~~~
#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...