Submission #61673

#TimeUsernameProblemLanguageResultExecution timeMemory
61673KHUSRAVWiring (IOI17_wiring)C++14
0 / 100
1026 ms263168 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std ; long long min_total_length(vector<int> r , vector<int> b){ long long used[100001] , ans = 0 , u1[100001] , u2[100001]; vector<pair<int , pair<int , int > > > v ; for(int i = 0 ; i <= 100000 ; i++) u1[i] = u2[i] = 0; if(r.size() > b.size()) swap(r , b); for(int i = 0 ; i < r.size() ; i ++){ for(int j = 0 ; j < b.size() ; j ++){ v.push_back({abs(r[i] - b[j]) , {i , j}}); u1[i] ++ ; u2[j] ++ ; ans = ans + abs(r[i] - b[j]); } } sort(v.begin() , v.end()); reverse(v.begin() , v.end()); for(int i = 0 ; i < v.size() ; i++){ if(u1[v[i].second.first] > 1 && u2[v[i].second.second] > 1){ ans = ans - v[i].first; u1[v[i].second.first] --; u2[v[i].second.second] --; } else{ //cout << r[v[i].second.first] <<" - "<<b[v[i].second.second] <<'\n'; } } return ans ; }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:13:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < r.size() ; i ++){
                     ~~^~~~~~~~~~
wiring.cpp:14:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0 ; j < b.size() ; j ++){
                         ~~^~~~~~~~~~
wiring.cpp:25:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0 ; i < v.size() ; i++){
                     ~~^~~~~~~~~~
wiring.cpp:6:15: warning: unused variable 'used' [-Wunused-variable]
     long long used[100001] , ans = 0 , u1[100001] , u2[100001];
               ^~~~
#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...