Submission #1035368

#TimeUsernameProblemLanguageResultExecution timeMemory
10353680npataWiring (IOI17_wiring)C++17
0 / 100
1093 ms12040 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define vec vector #define int long long const int INF = 1e18; long long min_total_length(std::vector<int32_t> r, std::vector<int32_t> b) { vec<vec<int>> v(0); int n = r.size(); int m = b.size(); int lst = -1; int i = 0; int j = 0; while(i+j < n+m) { if(i == n || (j<m && b[j] < r[i])) { if(lst != 0) { lst = 0; v.push_back({}); } v.back().push_back(b[j]); j++; } else { if(lst != 1) { lst = 1; v.push_back({}); } v.back().push_back(r[i]); i++; } } vec<vec<int>> dp(v.size()); dp[0] = vec<int>(v[0].size()+1, INF); dp[0][0] = 0; for(int i = 1; i<v.size(); i++) { dp[i] = vec<int>(v[i].size()+1, INF); int k = v[i-1].size()-1; dp[i][0] = dp[i-1].back(); int asum = 0; int bsum = v[i-1][k]; for(int j = 1; j<=v[i].size(); j++) { auto eval = [&]() { int psz = v[i-1].size()-k; return asum - bsum + max(j - psz, 0ll) * (-v[i-1].back()) + max(psz - j, 0ll) * v[i][0] + dp[i-1][k]; }; asum += v[i][j-1]; k = v[i-1].size(); bsum = 0; while(k > 0) { int cur = eval(); k--; bsum += v[i-1][k]; dp[i][j] = min(dp[i][j], eval()); int nxt = eval(); if(nxt > cur && i > 1 && false) { bsum -= v[i-1][k]; k++; break; } } //dp[i][j] = eval(); //cerr << k << ' ' << dp[i][j] << ' '; } //cerr << '\n'; } return dp.back().back(); }

Compilation message (stderr)

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