Submission #838961

#TimeUsernameProblemLanguageResultExecution timeMemory
838961drkarlicio2107Palembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; vector < pair <long long int, int> > v; long long int pos [20010][2]; int main (){ int n, k; cin >> k >> n; long long int sol=0; int ind=0; for (int i=0; i<n; i++){ long long int a, b; char x, y; cin >> x >> a >> y >> b; if (x==y){ sol+=abs (a-b); continue; } v.push_back ({a, 0}); v.push_back ({b, 1}); pos [ind][0]=a; pos [ind][1]=b; ind++; } long long int ans=1e18; for (int i=0; i<v.size(); i++){ int po=v [i].first; long long int curr=0; for (int j=0; j<ind; j++){ if (!(po<=pos [j][1] && po>=pos [j][0])) curr+=(abs (pos [j][0]-po)+abs (pos [j][1]-po)+1); else curr+=(abs (pos [j][0]-pos [j][1])+1); } ans=min (ans, curr); po=v [i].first-1; curr=0; for (int j=0; j<ind; j++){ if (!(po<=pos [j][1] && po>=pos [j][0])) curr+=(abs (pos [j][0]-po)+abs (pos [j][1]-po)+1); else curr+=(abs (pos [j][0]-pos [j][1])+1); } ans=min (ans, curr); po=v [i].first+1; curr=0; for (int j=0; j<ind; j++){ if (!(po<=pos [j][1] && po>=pos [j][0])) curr+=(abs (pos [j][0]-po)+abs (pos [j][1]-po)+1); else curr+=(abs (pos [j][0]-pos [j][1])+1); } ans=min (ans, curr); //cout << ans << endl; } cout << sol+ans << endl; return 0; }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     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...