Submission #262156

#TimeUsernameProblemLanguageResultExecution timeMemory
262156youssefbou62Wiring (IOI17_wiring)C++14
7 / 100
42 ms5752 KiB
#include "wiring.h" #include <bits/stdc++.h> #define sz(x) (int)x.size() #define ll long long using namespace std; const int MAXN = 205 ; ll dp[MAXN][MAXN]; void mins(ll& a ,ll b ){ a = min ( a , b ) ; } long long min_total_length(vector<int> r, vector<int> b) { int R = sz(r) , B = sz(b) ; ll ans = 0 ; for(int i = 0 ; i <= R ; i++ )for(int j = 0 ; j <= B ; j++ )dp[i][j] = 1e18; dp[0][0]=0 ; for(int i=0;i<R;i++){ for(int j=0;j<B;j++){ for(int k = 0 ;k<R;k++) mins(dp[i][j+1],dp[i][j]+1LL*abs(b[j]-r[k])); for(int k = 0 ; k < B ; k++ ) mins(dp[i+1][j],dp[i][j]+1LL*abs(b[k]-r[i])); mins(dp[i+1][j+1],dp[i][j]+1LL*abs(r[i]-b[j])); } } return dp[R][B]; } // 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; // }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:17:5: warning: unused variable 'ans' [-Wunused-variable]
   17 |  ll ans = 0 ;
      |     ^~~
#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...