Submission #1043046

#TimeUsernameProblemLanguageResultExecution timeMemory
1043046YassirSalamaWiring (IOI17_wiring)C++17
7 / 100
15 ms6976 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; const int maxn=300; long long dp[maxn][maxn]; long long cost(long long a,long long b){ return max(a,b)-min(a,b); } long long min_total_length(vector<int> r, vector<int> b) { int n=r.size(); int m=b.size(); for(int i=0;i<=n;i++){ for(int j=0;j<=m;j++){ dp[i][j]=1e18; } } dp[0][0]=cost(r[0],b[0]); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(i==0&&j==0) continue; if(i&&j) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+cost(r[i],b[j])); for(int k=0;k<=j;k++){ if(i) dp[i][j]=min(dp[i][j],dp[i-1][j]+cost(r[i],b[k])); } for(int k=0;k<=i;k++){ if(j) dp[i][j]=min(dp[i][j],dp[i][j-1]+cost(r[k],b[j])); } } } return dp[n-1][m-1]; } #ifdef IOI #include "wiring.h" #include <cassert> #include <cstdio> using namespace std; int main() { 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
#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...