Submission #52761

#TimeUsernameProblemLanguageResultExecution timeMemory
52761KieranHorganWiring (IOI17_wiring)C++17
13 / 100
167 ms17276 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; #define int long long int n, m, ans; vector<int> fullList; unordered_map<int, bool> isRed, isBlue; vector<vector<int>> segments; int calcWire(int s, int l, int r) { int res = 0; for(int i = l; i < segments[s].size(); i++) res += segments[s+1][0]-segments[s][i]; for(int i = 0; i <= r; i++) res += segments[s+1][i]-segments[s].back(); res -= min((int)segments[s].size()-l, r+1)*(segments[s+1][0]-segments[s].back()); return res; } long long min_total_length(vector<signed> r, vector<signed> b) { n = r.size(); m = b.size(); fullList.resize(n+m); merge(r.begin(), r.end(), b.begin(), b.end(), fullList.begin()); for(auto x: r) isRed[x]=1; for(auto x: b) isBlue[x]=1; for(int i = 0; i < m+n; i++) { if(i==0 || isRed[fullList[i]] != isRed[fullList[i-1]]) { segments.push_back(vector<int>(0)); segments.back().push_back(fullList[i]); } else { segments.back().push_back(fullList[i]); } } // for(auto s: segments) { // for(auto x: s) // cerr << x << " "; // cerr << endl; // } if(segments.size() == 2) return calcWire(0, 0, m-1); return -1; }

Compilation message (stderr)

wiring.cpp: In function 'long long int calcWire(long long int, long long int, long long int)':
wiring.cpp:13:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = l; i < segments[s].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...