Submission #895989

#TimeUsernameProblemLanguageResultExecution timeMemory
895989AndreyWiring (IOI17_wiring)C++14
0 / 100
1043 ms10932 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; long long min_total_length(std::vector<int> r, std::vector<int> b) { long long n = r.size(),m = b.size(); vector<pair<long long,long long>> haha(n+m+1,{-1,-1}); for(long long i = 0; i < r.size(); i++) { haha[i] = {r[i],0}; } for(long long i = 0; i < m; i++) { haha[i+n] = {b[i],1}; } sort(haha.begin(),haha.end()); vector<long long> wow(n+m+1); vector<long long> wut(n+m+1); long long c = 0,sb = 0; for(long long i = 1; i <= n+m; i++) { if(i > 1 && haha[i].second != haha[i-1].second) { c = haha[i].first; sb = 0; } sb+=haha[i].first-c; wow[i] = sb; } c = haha[n+m].first,sb = 0; for(long long i = n+m; i >= 1; i--) { if(i < n+m && haha[i].second != haha[i+1].second) { c = haha[i].first; sb = 0; } sb+=c-haha[i].first; wut[i] = sb; } vector<long long> dp(n+m+1); long long l = -1; for(long long i = 1; i <= n+m; i++) { if(i != 1 && haha[i].second != haha[i-1].second) { l = i-1; } dp[i] = 1000; long long y = l; while(y >= 0 && (y == l || haha[y+1].second == haha[l].second)) { dp[i] = min(dp[i],wow[i]+wut[min(l,y+1)]+dp[y]+(haha[l+1].first-haha[l].first)*max(l-y,i-l)); y--; } } return dp[n+m]; }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:8:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(long long i = 0; i < r.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...