Submission #597159

#TimeUsernameProblemLanguageResultExecution timeMemory
597159Ahmadsm2005Wiring (IOI17_wiring)C++14
13 / 100
86 ms17100 KiB
#include "bits/stdc++.h" //#include "grader.cpp" using namespace std; vector<int>edges[200001]; long long min_total_length(vector<int> r, vector<int> b) { for(int i=0;i<max(r.size(),b.size());i++) edges[i].clear(); if(r.size()<b.size()) swap(r,b); vector<pair<int,int>>STOR; set<int>VIS; int CUR=0; for(int i=0;i<r.size();i++){ while(1){ if(CUR+1==b.size()){ edges[CUR].push_back(i); VIS.insert(CUR); break; } if(abs(b[CUR]-r[i])<=abs(b[CUR+1]-r[i])){ if(VIS.find(CUR)!=VIS.end()) STOR.push_back({i,CUR}); else edges[CUR].push_back(i); VIS.insert(CUR); break; } else{ if(VIS.find(CUR)==VIS.end()){ if(!STOR.size()){ edges[CUR].push_back(i); CUR++; break; } else{ edges[CUR].push_back(STOR.back().first); STOR.pop_back(); } } } CUR++; } } while(CUR!=b.size()){ if(VIS.find(CUR)!=VIS.end()){ CUR++; continue; } edges[CUR].push_back(STOR.back().first); STOR.pop_back(); VIS.insert(CUR); } while(STOR.size()) edges[STOR.back().second].push_back(STOR.back().first),STOR.pop_back(); long long ANS=0; for(int i=0;i<b.size();i++) for(int l=0;l<edges[i].size();l++){ ANS+=abs(b[i]-r[edges[i][l]]); //cout<<b[i]<<' '<<r[edges[i][l]]<<endl; } return ANS; }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:6:14: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    6 | for(int i=0;i<max(r.size(),b.size());i++)
      |             ~^~~~~~~~~~~~~~~~~~~~~~~
wiring.cpp:13:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 | for(int i=0;i<r.size();i++){
      |             ~^~~~~~~~~
wiring.cpp:15:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 | if(CUR+1==b.size()){
      |    ~~~~~^~~~~~~~~~
wiring.cpp:44:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 | while(CUR!=b.size()){
      |       ~~~^~~~~~~~~~
wiring.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 | for(int i=0;i<b.size();i++)
      |             ~^~~~~~~~~
wiring.cpp:57:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 | for(int l=0;l<edges[i].size();l++){
      |             ~^~~~~~~~~~~~~~~~
#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...