Submission #1079870

#TimeUsernameProblemLanguageResultExecution timeMemory
1079870juicyWiring (IOI17_wiring)C++17
7 / 100
42 ms13480 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, inf = 1e9; int c[N], cnt[N]; long long dp[N], pf[N]; long long qry(int l, int r) { return pf[r] - pf[l]; } long long min_total_length(vector<int> r, vector<int> b) { vector<array<int, 2>> cands; for (int i = 0; i < r.size(); ++i) { cands.push_back({r[i], 0}); } for (int i = 0; i < b.size(); ++i) { cands.push_back({b[i], 1}); } sort(cands.begin(), cands.end()); int n = cands.size(); for (int i = 0; i < n; ) { int j = i; while (j < n && cands[j][1] == cands[i][1]) { ++j; } for (int k = i; k < j; ++k) { c[k + 1] = min(i ? cands[k][0] - cands[i - 1][0] : inf, j < n ? cands[j][0] - cands[k][0] : inf); } i = j; } for (int i = 0; i < n; ++i) { pf[i + 1] = pf[i] + cands[i][0]; } for (int i = 1; i <= n; ++i) { dp[i] = dp[i - 1] + c[i]; cnt[i] = (i > 1 && cands[i - 1][1] == cands[i - 2][1]) ? cnt[i - 1] + 1 : 1; if (cnt[i] <= cnt[i - cnt[i]]) { dp[i] = min(dp[i], dp[i - 2 * cnt[i]] + qry(i - cnt[i], i) - qry(i - 2 * cnt[i], i - cnt[i])); } } return dp[n]; }

Compilation message (stderr)

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