結果

問題 No.705 ゴミ拾い Hard
ユーザー binapbinap
提出日時 2024-04-10 09:15:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,766 bytes
コンパイル時間 4,680 ms
コンパイル使用メモリ 259,868 KB
実行使用メモリ 18,672 KB
最終ジャッジ日時 2024-04-10 09:16:14
合計ジャッジ時間 16,340 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
6,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 415 ms
18,416 KB
testcase_34 AC 419 ms
18,548 KB
testcase_35 AC 518 ms
18,568 KB
testcase_36 AC 489 ms
18,420 KB
testcase_37 AC 451 ms
18,420 KB
testcase_38 AC 481 ms
18,416 KB
testcase_39 WA -
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 1 ms
6,940 KB
testcase_42 AC 1 ms
6,940 KB
testcase_43 AC 540 ms
18,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}

template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}


// thanks for Luzhiled's memo
// https://ei1333.github.io/luzhiled/snippets/dp/monotone-minima.html
template<typename T, typename Compare = less<T>>
pair<vector<T>, vector<int>> monotone_minima(int H, int W, const function<T(int, int)> &f, const Compare &comp = Compare()) {
	vector<int> idx(H);
	vector<T> res(H);
	function<void(int, int, int, int)> dfs = [&](int top, int bottom, int left, int right) {
		if(top > bottom) return;
		int line = (top + bottom) / 2;
		T ma = 0;
		int mi = -1;
		for(int i = left; i <= right; i++) {
			T cst = f(line, i);
			if(mi == -1 || comp(cst, ma)) {
				ma = cst;
				mi = i;
			}
		}
		idx[line] = mi;
		res[line] = ma;
		dfs(top, line - 1, left, mi);
		dfs(line + 1, bottom, mi, right);
	};
	dfs(0, H - 1, 0, W - 1);
	return make_pair(res, idx);
}

template<typename T, typename Compare = greater<T>>
pair<vector<T>, vector<int>> monotone_maxima(int H, int W, const function<T(int, int)> &f, const Compare &comp = Compare()) {
	return monotone_minima(H, W, f, comp);
}

const long long INF = 2002002002002002002;
// A must be monotone
template<typename T>
vector<T> max_plus_convolution(vector<T> A, vector<T> B){
	function<long long(int, int)> f = [&](int i, int j){
		if(i - j < 0 or i - j >= int(A.size())) return -INF;
		return A[i - j] + B[j];
	};
	auto [idx, dp] = monotone_maxima(B.size() + A.size() - 1, B.size(), f);
	return dp;
}


int main(){
	int n;
	cin >> n;
	vector<long long> a(n);
	vector<long long> x(n);
	vector<long long> y(n);
	cin >> a;
	cin >> x;
	cin >> y;
	auto triple = [&](long long val){
		val = abs(val);
		return val * val * val;
	};
	auto dist = [&](int i, int j){
		assert(j >= i);
		return triple(a[j] - x[i]) + triple(y[i]);
	};
	auto solve = [&](int l, int r, auto solve) -> vector<long long>{
		if(r == l + 1){
			return vector<long long>{0LL, dist(l, l)};
		}
		int mid = (l + r) / 2;
		auto L = solve(l, mid, solve);
		auto R = solve(mid, r, solve);
		vector<long long> res((r - l) + 1, INF);
		rep(i, int(L.size())) chmin(res[i], L[i]);
		rep(i, int(R.size())) chmin(res[(mid - l) + i], L[mid - l] + R[i]);
		function<long long(int, int)> f = [&](int i, int j){
			return L[j] + dist(l + j, (mid + i) - 1);
		};
		auto [E, tmp] = monotone_minima((r - mid + 1), (mid - l), f);
		assert(E.size() == R.size());
		rep(i, int(E.size())) chmin(res[(mid - l) + i], E[i]);
		return res;
	};
	auto E = solve(0, n, solve);
	cout << E[n] << "\n";
//	cout << E;
	return 0;
}
0