Submission #982162

#TimeUsernameProblemLanguageResultExecution timeMemory
982162irmuunWiring (IOI17_wiring)C++17
13 / 100
16 ms1884 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() ll min_total_length(vector<int>r,vector<int>b){ ll ans=0,n=r.size(),m=b.size(); if(r[n-1]<=b[0]){ for(ll i=0;i<n-1;i++){ ans+=(r[i+1]-r[i])*(i+1); } ll cur=0; for(ll i=m-1;i>=1;i--){ ans+=(b[i]-b[i-1])*(++cur); } ans+=(b[0]-r[n-1])*max(n,m); return ans; } ll dp[n+5][m+5]; memset(dp,0,sizeof dp); for(ll i=0;i<=n;i++){ for(ll j=0;j<=m;j++){ if(i==0||j==0){ if(i==0&&j==0) dp[i][j]=0; else dp[i][j]=1e18; continue; } dp[i][j]=min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]})+abs(r[i]-b[j]); } } 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...