結果

問題 No.705 ゴミ拾い Hard
コンテスト
ユーザー RasShalGul
提出日時 2026-08-24 19:10:41
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 42 ms / 1,500 ms
+ 963µs
コード長 1,368 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,334 ms
コンパイル使用メモリ 353,136 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2026-08-24 19:10:58
合計ジャッジ時間 8,207 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define int long long
using namespace std;
template<typename type>//快读
inline void read(type &x){
	x=0;
	static bool flag(0);
	char ch=getchar();
	while(!isdigit(ch)){
		flag=ch=='-';
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	flag?x=-x:0;
}
template<typename type>//快写
inline void write(type x,bool mode=1){
	x<0?x=-x,putchar('-'):0;
	static short Stack[50],top(0);
	do{
		Stack[++top]=x%10,x/=10;
	}while(x);
	while(top){
		putchar(Stack[top--]|48);
	}
	mode?putchar('\n'):putchar(' ');
}
const int maxn=3e5+5;
int n;
vector<int>a(maxn),x(maxn),y(maxn),idx(maxn),dp(maxn,1e18);
inline int f(int s,int t){
	int X=abs(a[s]-x[t-1]);
	int Y=abs(0-y[t-1]);
	return X*X*X+Y*Y*Y;
}
inline void check(int s,int t){
	if(dp[s]+f(s,t)<dp[t]){
		dp[t]=dp[s]+f(s,t);
		idx[t]=s;
	}
}
inline void solve(int l,int r){
	if(r-l==1){
		return;
	}
	int m=(l+r)>>1;
	for(int i=idx[l];i<=idx[r];i++){
		check(i,m);
	}
	solve(l,m);
	for(int i=l+1;i<=m;i++){
		check(i,r);
	}
	solve(m,r);
}
signed main(){
	//freopen("gabbage.in","r",stdin);
	//freopen("gabbage.out","w",stdout);
	cin >> n;
	for(int i=0;i<n;i++){
		read(a[n-1-i]);
	}
	for(int i=0;i<n;i++){
		read(x[n-1-i]);
	}
	for(int i=0;i<n;i++){
		read(y[n-1-i]);
	}
	dp[0]=0;
	idx[0]=0;
	dp[n]=f(0,n);
	idx[n]=0;
	solve(0,n);
	write(dp[n],1);
	return 0;
}
0