제출 #886070

#제출 시각아이디문제언어결과실행 시간메모리
886070qin전선 연결 (IOI17_wiring)C++17
0 / 100
1 ms500 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ssize(x) int(x.size()) #define pn printf("\n") using namespace std; typedef long long ll; typedef pair<int, int> pii; int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1; ll min_total_length(vector<int> r, vector<int> B){ int n = ssize(r), m = ssize(B); //scanf("%d%d", &n, &m); vector<int> a(n+1), b(m+1); vector<vector<ll>> dp(n+1, vector<ll>(m+1, infll)); for(int i = 1; i <= n; ++i) a[i] = r[i-1];//scanf("%d", &a[i]); for(int i = 1; i <= m; ++i) b[i] = B[i-1]; //scanf("%d", &b[i]); dp[1][1] = abs(a[1]-b[1]); for(int i = 1; i <= n; ++i){ for(int j = 1; j <= m; ++j){ if(i != n) dp[i+1][j] = min(dp[i+1][j], dp[i][j]+abs(a[i+1]-b[i])); if(j != m) dp[i][j+1] = min(dp[i][j+1], dp[i][j]+abs(a[i]-b[i+1])); if(i != n && j != m) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j]+abs(a[i+1]-b[i+1])); } } //printf("%lld\n", dp[n][m]); return dp[n][m]; } #ifdef LOCAL int main(){ int T = 1; for(++T; --T; ) //answer(); return 0; } #endif
#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...