Submission #1014220

#TimeUsernameProblemLanguageResultExecution timeMemory
1014220aykhnWiring (IOI17_wiring)C++17
100 / 100
37 ms15784 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; long long min_total_length(vector<int> r, vector<int> b) { vector<array<long long, 2>> a; int i = 0, j = 0; while (i < r.size() && j < b.size()) { if (r[i] <= b[j]) a.push_back({r[i++], 0}); else a.push_back({b[j++], 1}); } while (i < r.size()) a.push_back({r[i++], 0}); while (j < b.size()) a.push_back({b[j++], 1}); vector<long long> dp(a.size(), 1e18); vector<long long> mn(a.size(), 1e18); long long rl = -1e18, bl = -1e18; for (int i = 0; i < a.size(); i++) { if (a[i][1] == 0) mn[i] = min(mn[i], abs(a[i][0] - bl)), rl = a[i][0]; else mn[i] = min(mn[i], abs(a[i][0] - rl)), bl = a[i][0]; } rl = 1e18, bl = 1e18; for (int i = (int)a.size() - 1; i >= 0; i--) { if (a[i][1] == 0) mn[i] = min(mn[i], abs(a[i][0] - bl)), rl = a[i][0]; else mn[i] = min(mn[i], abs(a[i][0] - rl)), bl = a[i][0]; } vector<int> f(a.size() * 2 + 100, -2); vector<long long> pr(a.size(), 0), pb(a.size(), 0); f[a.size()] = -1; int c = 0; for (int i = 0; i < a.size(); i++) { if (a[i][1] == 0) c++; else c--; pr[i] = (i ? pr[i - 1] : 0); pb[i] = (i ? pb[i - 1] : 0); if (a[i][1] == 0) pr[i] += a[i][0]; else pb[i] += a[i][0]; dp[i] = (i ? dp[i - 1] : 0) + mn[i]; long long cntr = 0, cntb = 0, d = 0; if (f[c + a.size()] != -2) { long long ind = f[c + a.size()], sumr = pr[i], sumb = pb[i]; if (ind >= 0) sumr -= pr[ind], sumb -= pb[ind]; dp[i] = min(dp[i], (ind >= 0 ? dp[ind] : 0) + abs(sumr - sumb)); } f[c + a.size()] = i; } return dp[(int)a.size() - 1]; }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:10:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  while (i < r.size() && j < b.size())
      |         ~~^~~~~~~~~~
wiring.cpp:10:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  while (i < r.size() && j < b.size())
      |                         ~~^~~~~~~~~~
wiring.cpp:15:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  while (i < r.size()) a.push_back({r[i++], 0});
      |         ~~^~~~~~~~~~
wiring.cpp:16:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  while (j < b.size()) a.push_back({b[j++], 1});
      |         ~~^~~~~~~~~~
wiring.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (int i = 0; i < a.size(); i++)
      |                  ~~^~~~~~~~~~
wiring.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for (int i = 0; i < a.size(); i++)
      |                  ~~^~~~~~~~~~
wiring.cpp:44:13: warning: unused variable 'cntr' [-Wunused-variable]
   44 |   long long cntr = 0, cntb = 0, d = 0;
      |             ^~~~
wiring.cpp:44:23: warning: unused variable 'cntb' [-Wunused-variable]
   44 |   long long cntr = 0, cntb = 0, d = 0;
      |                       ^~~~
wiring.cpp:44:33: warning: unused variable 'd' [-Wunused-variable]
   44 |   long long cntr = 0, cntb = 0, d = 0;
      |                                 ^
#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...