Submission #296787

#TimeUsernameProblemLanguageResultExecution timeMemory
296787DanerZeinWiring (IOI17_wiring)C++14
20 / 100
35 ms3960 KiB
#include "wiring.h" #include <bits/stdc++.h> #define MAX 1000000000000000000 using namespace std; typedef long long ll; ll dp[210][210]; long long min_total_length(std::vector<int> r, std::vector<int> b) { int n,m; n=r.size(); m=b.size(); int j; if(n<=200 and m<=200){ dp[0][0]=abs(r[0]-b[0]); for(int i=0;i<n;i++){ if(i==0) j=1; else j=0; for(;j<m;j++){ ll rp=MAX; if(i-1>=0 and j-1>=0){ rp=min(rp,dp[i-1][j-1]); } if(i-1>=0){ rp=min(rp,dp[i-1][j]); } if(j-1>=0){ rp=min(rp,dp[i][j-1]); } dp[i][j]=rp+abs(r[i]-b[j]); } } return dp[n-1][m-1]; } else{ ll res=0; int l=0,ri=b.size()-1; while(true){ res+=abs(r[l]-b[ri]); if(l==r.size()-1 and ri==0) break; if(l!=r.size()-1) l++; if(ri!=0) ri--; } /*if(n>m){ int j=b.size()-1; for(int i=0;i<r.size();i++){ if(j!=0) j--; res+=abs(r[i]-b[j]); } } else{ int j=0; for(int i=b.size()-1;i>=0;i--){ if(j!=r.size()-1) j++; res+=abs(b[i]-r[j]); } }*/ return res; } }

Compilation message (stderr)

wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:38:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |       if(l==r.size()-1 and ri==0) break;
      |          ~^~~~~~~~~~~~
wiring.cpp:39:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |       if(l!=r.size()-1) l++;
      |          ~^~~~~~~~~~~~
#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...