結果
| 問題 |
No.703 ゴミ拾い Easy
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-03-21 19:41:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 114 ms / 1,500 ms |
| コード長 | 1,811 bytes |
| コンパイル時間 | 1,765 ms |
| コンパイル使用メモリ | 163,792 KB |
| 実行使用メモリ | 22,396 KB |
| 最終ジャッジ日時 | 2025-03-21 19:41:50 |
| 合計ジャッジ時間 | 7,081 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 46 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define lc(i) ((i) << 1)
#define rc(i) (((i) << 1) | 1)
#define tmid ((tl + tr) >> 1)
typedef long long ll;
const int MAXN = 3e5 + 5, MAXX = 1e5 + 5;
struct line{
ll k, b;
line(ll k_ = 0, ll b_ = 1e18){ k = k_, b = b_; }
inline ll gety(int x){ return k * x + b; }
};
struct LiChaoTree{
line l;
bool flg;
inline ll gety(int x){ return l.gety(x); }
}tree[MAXX << 2];
ll a[MAXN], x[MAXN], y[MAXN], dp[MAXN];
// inline int isx(line a, line b){ return (a.b - b.b) / (b.k - a.k); }
inline bool smaller(line a, line b, int x){ return a.gety(x) < b.gety(x); }
void add(int i, int tl, int tr, line p){
if(!tree[i].flg){
tree[i].l = p;
tree[i].flg = true;
}else if(smaller(p, tree[i].l, tl) && smaller(p, tree[i].l, tr)) tree[i].l = p;
else if(smaller(p, tree[i].l, tl) || smaller(p, tree[i].l, tr)){
if(smaller(p, tree[i].l, tmid)) swap(p, tree[i].l);
if(smaller(p, tree[i].l, tl)) add(lc(i), tl, tmid, p);
else add(rc(i), tmid + 1, tr, p);
}
}
ll query(int i, int tl, int tr, int x){
if(tl == tr) return tree[i].gety(x);
ll ans = tree[i].gety(x);
if(x <= tmid) return min(ans, query(lc(i), tl, tmid, x));
else return min(ans, query(rc(i), tmid + 1, tr, x));
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) cin >> x[i];
for(int i = 1; i <= n; i++) cin >> y[i];
add(1, 1, 100000, {-2 * x[1], x[1] * x[1] + y[1] * y[1]});
for(int i = 1; i <= n; i++){
dp[i] = a[i] * a[i] + query(1, 1, 100000, a[i]);
add(1, 1, 100000, {-2 * x[i + 1], dp[i] + x[i + 1] * x[i + 1] + y[i + 1] * y[i + 1]});
}
cout << dp[n];
return 0;
}
vjudge1