Submission #145390

#TimeUsernameProblemLanguageResultExecution timeMemory
145390MinnakhmetovWiring (IOI17_wiring)C++14
20 / 100
39 ms6300 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define all(aaa) aaa.begin(), aaa.end() const ll INF = 1e18; const int N = 205; ll dp[N][N]; void upd(ll &a, ll b) { a = min(a, b); } ll min_total_length(vector<int> r, vector<int> b) { int n = r.size(), m = b.size(); if (r[n - 1] < b[0]) { ll ans = 0; if (n < m) { for (int i = 0; i < n; i++) ans += b[i] - r[i]; for (int i = n; i < m; i++) ans += b[i] - r[n - 1]; } else { for (int i = 0; i < m; i++) ans += b[i] - r[i]; for (int i = m; i < n; i++) ans += b[0] - r[i]; } return ans; } else { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ll val = dp[i][j] + abs(r[i] - b[j]); upd(dp[i + 1][j], val); upd(dp[i][j + 1], val); upd(dp[i + 1][j + 1], val); } } 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...