제출 #990425

#제출 시각아이디문제언어결과실행 시간메모리
990425StefanSebezWiring (IOI17_wiring)C++14
13 / 100
15 ms2004 KiB
#include "wiring.h" #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define ll long long #define pb push_back const ll inf=1e9; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n=r.size(),m=b.size(); ll res=0; bool subtask2=false;if(r.back()<b[0]) subtask2=true; if(subtask2){ for(int i=n-1,j=m-1;i>=0 || j>=0;){ if(i==-1 && j>0){ while(j>=0){ res+=b[j]-r[n-1]; j--; } break; } else if(i>0 && j==-1){ while(i>=0){ res+=b[0]-r[i]; i--; } break; } else{ res+=b[j]-r[i]; j--; i--; } } } else{ if(n>m){ swap(n,m); swap(r,b); } int A[n+10],B[m+10]; for(int i=0;i<n;i++) A[i+1]=r[i]; for(int i=0;i<m;i++) B[i+1]=b[i]; ll dp[m+1][n+1]; for(ll i=1,cost=0;i<=m;i++){ cost+=abs(A[1]-B[i]); dp[i][1]=cost; } dp[0][1]=inf; for(int j=2;j<=n;j++){ for(int i=1;i<=m;i++){ dp[i][j]=inf; for(ll k=i-1,cost=0;k>=0;k--){ cost+=abs(A[j]-B[k+1]); dp[i][j]=min(dp[i][j],dp[k][j-1]+cost); } } } /*for(int i=0;i<=m;i++){ printf("%i: ",i); for(int j=1;j<=n;j++){ printf("%lld ",dp[i][j]); } printf("\n"); }*/ res=dp[m][n]; } return res; }
#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...