結果

問題 No.705 ゴミ拾い Hard
ユーザー yosupot
提出日時 2018-06-15 22:42:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 181 ms / 1,500 ms
コード長 1,597 bytes
コンパイル時間 2,337 ms
コンパイル使用メモリ 198,000 KB
最終ジャッジ日時 2025-01-05 13:53:56
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
const ll INF = 8 * TEN(18);
using P = pair<ll, ll>;
ll dist(const P &a, const P &b) {
ll x = abs(a.first - b.first);
ll y = abs(a.second - b.second);
return x*x*x + y*y*y;
}
int n;
V<P> s, t;
V<ll> dp;
void solve2(int l, int r, int a, int b) {
if (l == r) return;
int md = (l+r)/2;
ll ma = INF; int mi = -1;
for (int i = a; i < b; i++) {
ll cst = dp[i+1] + dist(s[i], t[md]);
if (cst < ma) {
ma = cst;
mi = i;
}
}
dp[md] = min(dp[md], ma);
solve2(l, md, a, mi+1);
solve2(md+1, r, mi, b);
}
void solve(int l, int r) {
if (r-l == 1) {
dp[l] = min(dp[l], dist(s[l], t[l]) + dp[r]);
return;
}
int md = (l+r)/2;
solve(md, r);
solve2(l, md, md, r);
solve(l, md);
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
cin >> n;
s = V<P>(n); t = V<P>(n); dp = V<ll>(n+1, INF); dp[n] = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
s[i] = P(a, 0);
}
for (int i = 0; i < n; i++) {
int a;
cin >> a;
t[i].first = a;
}
for (int i = 0; i < n; i++) {
int a;
cin >> a;
t[i].second = a;
}
solve(0, n);
cout << dp[0] << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1