Submission #1095187

#TimeUsernameProblemLanguageResultExecution timeMemory
1095187dpsaveslivesPalembang Bridges (APIO15_bridge)C++17
22 / 100
36 ms4552 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int K,N; cin >> K >> N; if(K == 2){ cout << 0 << "\n"; return 0; } ll ans = 0; vector<int> vec; vector<pair<int,int>> dif; for(int i = 0;i<N;++i){ char p1,p2; int s,t; cin >> p1 >> s >> p2 >> t; if(p1 != p2){ vec.push_back(s); vec.push_back(t); dif.push_back({s,t}); } else{ ans += abs(s-t); } } if(!vec.size()){ cout << ans << "\n"; return 0; } sort(vec.begin(),vec.end()); int med = vec[vec.size()/2]; for(int i = 0;i<dif.size();++i){ ans += abs(dif[i].f-med)+abs(dif[i].s-med)+1; } cout << ans << "\n"; return 0; }

Compilation message (stderr)

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