Submission #1062730

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
10627302024-08-17 10:09:32deeraWiring (IOI17_wiring)C++14
7 / 100
18 ms4044 KiB
#include <bits/stdc++.h>
using namespace std;
int d(int x, int y) {return abs(x - y);}
long long min_total_length(vector<int> r, vector<int> b) {
int n = r.size(), m = b.size();
if (b.back() < r.front()) {
long long a = 0;
for(int i: r) a += r.back() - i;
for(int i: b) a += i - b.front();
return a + (b.front() - r.back()) * max(n, m);
}
if (n <= 200 && m <= 200) {
int dp[201][201];
dp[0][0] = d(r[0], b[0]);
for(int i = 1; i < n; i++) dp[i][0] = dp[i-1][0] + d(r[i], b[0]);
for(int i = 1; i < m; i++) dp[0][i] = dp[0][i-1] + d(r[0], b[i]);
for(int i = 1; i < n; i++)
for(int j = 1; j < m; j++)
dp[i][j] = min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]}) + d(r[i], b[j]);
return dp[n - 1][m - 1];
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
   26 | }
      | ^
#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...