Submission #895670

#TimeUsernameProblemLanguageResultExecution timeMemory
895670AndreyWiring (IOI17_wiring)C++14
25 / 100
22 ms5200 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n = r.size(),m = b.size(); vector<int> haha(n+m+1); for(int i = 0; i < n; i++) { haha[r[i]] = 1; } vector<int> bruh(0); int p = 0; for(int i = 1; i <= n+m; i++) { if(i == 1 || haha[i] == haha[i-1]) { p++; } else { bruh.push_back(p); p = 1; } } bruh.push_back(p); vector<long long> ans(0); vector<long long> sm(0); vector<long long> big(0); ans.push_back(bruh[0]); sm.push_back(bruh[0]); big.push_back(bruh[0]); for(int i = 1; i < bruh.size()-1; i++) { ans.push_back(bruh[i]/2); sm.push_back(bruh[i]/2); ans.push_back((bruh[i]+1)/2); big.push_back((bruh[i]+1)/2); } ans.push_back(bruh[bruh.size()-1]); sm.push_back(bruh[bruh.size()-1]); big.push_back(bruh[bruh.size()-1]); vector<pair<long long,long long>> dp(bruh.size()); for(int i = 1; i < bruh.size(); i++) { dp[i] = {min(dp[i-1].first+max(big[i-1],sm[i]),dp[i-1].second+max(sm[i-1],sm[i])),min(dp[i-1].first+max(big[i],big[i-1]),dp[i-1].second+max(big[i],sm[i-1]))}; } long long sb = 0; for(int i = 0; i < ans.size(); i++) { sb+=(ans[i]-1)*ans[i]/2; } return sb+dp[bruh.size()-1].first; }

Compilation message (stderr)

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