Submission #72940

#TimeUsernameProblemLanguageResultExecution timeMemory
72940NavickWiring (IOI17_wiring)C++17
7 / 100
46 ms4796 KiB
#include <bits/stdc++.h> #include "wiring.h" #define F first #define S second #define pii pair <int, int> #define pb push_back using namespace std; typedef long long ll; const int maxN = 210; const ll oo = 1e16; ll dp[maxN][maxN]; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n = r.size(), m = b.size(); dp[0][0] = 0; for (int j=1; j<=m; j++) dp[0][j] = oo; for (int i=1; i<=n; i++) dp[i][0] = oo; for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) { ll curr = 0; dp[i][j] = oo; for (int k=j-1; k>=0; k--) { curr += abs(r[i - 1] - b[k]); dp[i][j] = min(dp[i][j], curr + dp[i - 1][k]); } curr = 0; for (int k=i-1; k>=0; k--) { curr += abs(b[j - 1] - r[k]); dp[i][j] = min(dp[i][j], curr + dp[k][j - 1]); } } 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...