Submission #416484

#TimeUsernameProblemLanguageResultExecution timeMemory
416484yanireWiring (IOI17_wiring)C++14
7 / 100
144 ms262148 KiB
#include <bits/stdc++.h> using namespace std; #include "wiring.h" #define fin(i,s,n) for(auto i = s; i < n; ++i) #define fine(i,s,n) for(auto i = s; i <= n; ++i) #define pb push_back #define eb emplace_back #define x first #define y second #define all(x) (x).begin(),(x).end() #define chkmin(a,b) a = min(a,b) #define chkmax(a,b) a = max(a,b) using stdvec = vector<int>; #define int int64_t using ii = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vii = vector<ii>; const int inf = 1e17; int dist(stdvec& a, int x) { int ans = abs(x-a[0]); for(auto& o : a) chkmin(ans,abs(o-x)); return ans; if(x<a[0]) return abs(a[0]-x); if(x>a.back()) return abs(a.back()-x); auto it = lower_bound(all(a),x); return min(abs(*it-x),abs(*(it+1)-x)); } long long min_total_length(stdvec r, stdvec b) { int n = r.size(), m = b.size(); vvi dp(n,vi(m,inf)); dp[0][0] = abs(r[0]-b[0]); fin(i,0,n) { if(i) dp[i][0] = dp[i-1][0]+abs(r[i]-b[0]); fin(j,1,m) { if(i) chkmin(dp[i][j],dp[i-1][j]+dist(b,r[i])); chkmin(dp[i][j],dp[i][j-1]+dist(r,b[j])); if(i) chkmin(dp[i][j],dp[i-1][j-1]+abs(r[i]-b[j])); } } return dp[n-1][m-1]; }
#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...