結果
問題 |
No.703 ゴミ拾い Easy
|
ユーザー |
![]() |
提出日時 | 2025-03-26 14:42:04 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 124 ms / 1,500 ms |
コード長 | 1,786 bytes |
コンパイル時間 | 3,991 ms |
コンパイル使用メモリ | 282,044 KB |
実行使用メモリ | 12,652 KB |
最終ジャッジ日時 | 2025-03-26 14:42:18 |
合計ジャッジ時間 | 10,075 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 46 |
ソースコード
#include <bits/stdc++.h> using namespace std; template <class T, bool isMax = false> struct CHT_Monotone { // 追加クエリの傾き:単調減少 // 取得クエリのx座標:単調増加 // 最小値を返す // 最大値のとき:a,b -1倍 // (単調増加,単調減少)のとき:a,x -1倍 struct Line { T a, b; T y(T x) { return a * x + b; } }; deque<Line> q; bool noneed(Line a, Line b, Line c) { return (b.b - c.b) * (b.a - a.a) <= (a.b - b.b) * (c.a - b.a); } void add(T a, T b) { Line l = {a, b}; while (q.size() > 1 && noneed(q[q.size() - 2], q[q.size() - 1], l)) { q.pop_back(); } q.push_back(l); } T query(T x) { if (q.empty()) return numeric_limits<T>::max() / 2; while (q.size() > 1 && ((q[0].y(x) > q[1].y(x)) ^ isMax)) { q.pop_front(); } return q[0].y(x); } }; // competitive-verifier: PROBLEM https://yukicoder.me/problems/no/703 //#include "../CHT-Monotone.cpp" using ll = long long; void solve() { int n; cin >> n; vector<ll> a(n), x(n), y(n), dp(n + 1); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> x[i]; for (int i = 0; i < n; i++) cin >> y[i]; dp[0] = 0; /* CHT_Monotone<ll> cht; for (int i = 0; i < n; i++) { cht.add(-2 * x[i], dp[i] + x[i] * x[i] + y[i] * y[i]); dp[i + 1] = a[i] * a[i] + cht.query(a[i]); } */ CHT_Monotone<ll, true> cht; for (int i = 0; i < n; i++) { cht.add(2 * x[i], -dp[i] - x[i] * x[i] - y[i] * y[i]); dp[i + 1] = a[i] * a[i] + -cht.query(a[i]); } cout << dp[n] << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }