Submission #970249

#TimeUsernameProblemLanguageResultExecution timeMemory
970249CSQ31Wiring (IOI17_wiring)C++17
13 / 100
29 ms6948 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; typedef long long int ll; ll min_total_length(vector<int> R,vector<int> B) { vector<array<int,2>>a; for(int x:R)a.push_back({x,0}); for(int x:B)a.push_back({x,1}); sort(a.begin(),a.end()); vector<vector<int>>b; int n = a.size(); for(int i=0;i<n;i++){ int j = i; b.push_back({a[i][0]}); while(j+1<n && a[j][1] == a[j+1][1]){ j++; b.back().push_back(a[j][0]); } i = j; } if(b.size() == 2){ ll ans = 0; for(int i=0;i<b[0].size();i++)ans += b[0].back() - b[0][i]; for(int i=0;i<b[1].size();i++)ans += b[1][i] - b[1][0]; int mx = max(b[0].size(),b[1].size()); ans += mx * 1LL * (b[1][0] - b[0].back()); return ans; } return 0; }

Compilation message (stderr)

wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:24:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int i=0;i<b[0].size();i++)ans += b[0].back() - b[0][i];
      |               ~^~~~~~~~~~~~
wiring.cpp:25:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int i=0;i<b[1].size();i++)ans += b[1][i] - b[1][0];
      |               ~^~~~~~~~~~~~
#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...