제출 #416488

#제출 시각아이디문제언어결과실행 시간메모리
416488yanire전선 연결 (IOI17_wiring)C++11
0 / 100
150 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; #define sz(a) int((a).size()) int dist(stdvec& a, int x) { if(x<=a[0]) return abs(a[0]-x); if(x>=a.back()) return abs(a.back()-x); int idx = lower_bound(all(a),x)-a.begin(); int ans = abs(x-a[idx]); if(idx+1<sz(a)) chkmin(ans,abs(x-a[idx+1])); return ans; } 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...