結果

問題 No.703 ゴミ拾い Easy
ユーザー lorent_kyoprolorent_kyopro
提出日時 2021-04-06 23:52:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 1,500 ms
コード長 1,569 bytes
コンパイル時間 3,713 ms
コンパイル使用メモリ 80,532 KB
実行使用メモリ 10,352 KB
最終ジャッジ日時 2023-09-02 15:55:34
合計ジャッジ時間 9,780 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,568 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 91 ms
10,244 KB
testcase_25 AC 91 ms
10,124 KB
testcase_26 AC 91 ms
10,180 KB
testcase_27 AC 92 ms
10,252 KB
testcase_28 AC 93 ms
10,096 KB
testcase_29 AC 91 ms
10,192 KB
testcase_30 AC 91 ms
10,108 KB
testcase_31 AC 91 ms
10,168 KB
testcase_32 AC 92 ms
10,236 KB
testcase_33 AC 93 ms
10,136 KB
testcase_34 AC 82 ms
10,352 KB
testcase_35 AC 82 ms
10,188 KB
testcase_36 AC 80 ms
10,204 KB
testcase_37 AC 82 ms
10,104 KB
testcase_38 AC 81 ms
10,028 KB
testcase_39 AC 82 ms
10,188 KB
testcase_40 AC 81 ms
10,108 KB
testcase_41 AC 82 ms
10,184 KB
testcase_42 AC 82 ms
10,176 KB
testcase_43 AC 82 ms
10,156 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 96 ms
10,200 KB
testcase_47 AC 95 ms
10,092 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cstddef>
#include <deque>
#include <iostream>
#include <vector>

__attribute__((constructor))
void fast_io() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

template <class T>
class lines {
public:
    void append(T a, T b) {
        if (lines.empty()) {
            lines.emplace_back(a, b);
            return;
        }
        auto [a1, b1] = lines.back();
        while (lines.size() > 1) {
            auto [a0, b0] = lines[lines.size() - 2];
            if ((a1 - a) * (b1 - b0) < (a0 - a1) * (b - b1)) break;
            lines.pop_back();
            a1 = a0;
            b1 = b0;
        }
        lines.emplace_back(a, b);
    }
 
    T min_at(T x) {
        assert(!lines.empty());
        auto [a0, b0] = lines[0];
        T y0 = a0 * x + b0;
        while (lines.size() > 1) {
            auto [a1, b1] = lines[1];
            T y1 = a1 * x + b1;
            if (y0 < y1) break;
            lines.pop_front();
            a0 = a1;
            b0 = b1;
            y0 = y1;
        }
        return y0;
    }
 
private:
    std::deque<std::pair<T, T>> lines;
};

int main() {
    size_t n;
    std::cin >> n;
    std::vector<long long> a(n), x(n), y(n);
    for (auto& ai : a) std::cin >> ai;
    for (auto& xi : x) std::cin >> xi;
    for (auto& yi : y) std::cin >> yi;

    lines<long long> cht;
    long long dp = 0;
    for (size_t i = 0; i < n; ++i) {
        cht.append(-2 * x[i], x[i] * x[i] + y[i] * y[i] + dp);
        dp = cht.min_at(a[i]) + a[i] * a[i];
    }
    std::cout << dp << '\n';
}
0