제출 #416512

#제출 시각아이디문제언어결과실행 시간메모리
416512yanire전선 연결 (IOI17_wiring)C++11
7 / 100
130 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()) template<class T> ostream& operator<<(ostream& os, vector<T> v) { if(v.empty()) return os << "[]"; os << '[' << v[0]; fin(i,1,sz(v)) os << ',' << v[i]; return os << ']'; } ii bop(stdvec& a, int x) { if(x<a[0]) return {0,0}; if(x>a.back()) return {sz(a)-1,sz(a)-1}; int idx = lower_bound(all(a),x)-a.begin(); return {idx-1,idx}; } int dist(stdvec& a, int x) { ii ops = bop(a,x); return min(abs(a[ops.x]-x),abs(a[ops.y]-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...