結果

問題 No.703 ゴミ拾い Easy
コンテスト
ユーザー V_Melville
提出日時 2025-11-21 17:16:19
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 90 ms / 1,500 ms
コード長 1,110 bytes
コンパイル時間 2,778 ms
コンパイル使用メモリ 284,832 KB
実行使用メモリ 10,348 KB
最終ジャッジ日時 2025-11-21 17:16:28
合計ジャッジ時間 8,592 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

struct CHT {
    deque<P> d;
    void add(ll a, ll b) {
        while (d.size() >= 2) {
            auto [a1, b1] = d[d.size()-1];
            auto [a0, b0] = d[d.size()-2];
            if ((b0-b1)*(a-a1) < (b1-b)*(a1-a0)) break;
            d.pop_back();
        }
        d.emplace_back(a, b);
    }
    ll get(ll x) {
        while (d.size() >= 2) {
            auto [a0, b0] = d[0];
            auto [a1, b1] = d[1];
            if (a0*x+b0 < a1*x+b1) break;
            d.pop_front();
        }
        auto [a, b] = d[0];
        return a*x+b;
    }
};

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<ll> a(n), x(n), y(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> x[i];
    rep(i, n) cin >> y[i];
    
    ll ans = 0;
    CHT cht;
    rep(i, n) {
        cht.add(-2*x[i], ans+x[i]*x[i]+y[i]*y[i]);
        ans = cht.get(a[i]) + a[i]*a[i];
    }
    
    cout << ans << '\n';
    
    return 0;
}
0