Submission #417779

#TimeUsernameProblemLanguageResultExecution timeMemory
417779HegdahlWiring (IOI17_wiring)C++17
7 / 100
160 ms262148 KiB
#include <bits/stdc++.h> #include "wiring.h" using namespace std; using ll = long long; const ll INF = 1LL<<60; void minset(ll &p, ll v) { if (v < p) p = v; } string fmt(ll x) { if (x == INF) return "-"; return to_string(x); } ll min_total_length(vector<int> r, vector<int> b) { const int n = (int)r.size(), m = (int)b.size(); vector<vector<ll>> dp(n+1, vector<ll>(m+1, INF)); dp[0][0] = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= m; ++j) { if (i < n && j < m) minset(dp[i+1][j+1], dp[i][j] + abs(r[i]-b[j])); if (i && j < m) minset(dp[i][j+1], dp[i][j] + abs(r[i-1]-b[j])); if (j && i < n) minset(dp[i+1][j], dp[i][j] + abs(r[i]-b[j-1])); } } /* for (int i = 0; i <= n; ++i) for (int j = 0; j <= m; ++j) cerr << fmt(dp[i][j]) << " \n"[j==m]; // */ return dp[n][m]; }
#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...