Submission #968487

#TimeUsernameProblemLanguageResultExecution timeMemory
968487nguyentunglamWiring (IOI17_wiring)C++17
7 / 100
232 ms21648 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; const int N = 1010; long long dp[N][N]; int a[N], b[N]; long long min_total_length(std::vector<int> R, std::vector<int> B) { int n = R.size(), m = B.size(); for(int i = 1; i <= n; i++) a[i] = R[i - 1]; for(int i = 1; i <= m; i++) b[i] = B[i - 1]; memset(dp, 61, sizeof(dp)); dp[0][0] = 0; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) { dp[i][j] = min({dp[i - 1][j - 1], dp[i][j - 1], dp[i - 1][j]}) + abs(a[i] - b[j]); } return dp[n][m]; } #ifdef ngu int main() { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); int n, m; assert(2 == scanf("%d %d", &n, &m)); vector<int> r(n), b(m); for(int i = 0; i < n; i++) assert(1 == scanf("%d", &r[i])); for(int i = 0; i < m; i++) assert(1 == scanf("%d", &b[i])); long long res = min_total_length(r, b); printf("%lld\n", res); return 0; } #endif // ngu
#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...