結果
問題 | No.703 ゴミ拾い Easy |
ユーザー |
|
提出日時 | 2018-06-30 18:07:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 1,500 ms |
コード長 | 1,576 bytes |
コンパイル時間 | 1,394 ms |
コンパイル使用メモリ | 163,872 KB |
実行使用メモリ | 11,108 KB |
最終ジャッジ日時 | 2025-01-02 13:57:00 |
合計ジャッジ時間 | 4,016 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 46 |
ソースコード
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("avx") #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define ll long long #define fi first #define se second #define push_back pb #define show(x) cout << #x << " = " << x << "\n" using namespace std; typedef pair<int,int> P; const int MAX_N = 300001; #define getchar getchar_unlocked inline int in() { int n, c; while ((c = getchar()) < '0') if (c == EOF) return -1; n = c - '0'; while ((c = getchar()) >= '0') n = n * 10 + c - '0'; return n; } pair<ll,ll> lines[MAX_N]; bool check(pair<ll,ll> l1, pair<ll,ll> l2, pair<ll,ll> l3){ return (l2.first-l1.first)*(l3.second-l2.second)>=(l2.second-l1.second)*(l3.first-l2.first); } ll f(int i, ll x){ return lines[i].first * x + lines[i].second; } int head = 0, tail = 0; void add(ll a, ll b){ pair<ll,ll> line(a, b); while(tail - head >= 2 && check(lines[tail-2], lines[tail-1], line)){ tail--; } lines[tail++] = line; } ll get(ll x){ while(tail - head >= 2 && f(head, x) >= f(head + 1, x)){ head++; } return f(head, x); } int a[MAX_N],x[MAX_N],y[MAX_N]; int main() { int n = in(); rep(i,n){ a[i] = in(); } rep(i,n){ x[i] = in(); } rep(i,n){ y[i] = in(); } add(-2*x[0],(ll)x[0]*x[0]+(ll)y[0]*y[0]); rep(i,n){ if(i < n-1){ add(-2*x[i+1],get(a[i])+(ll)x[i+1]*x[i+1]+(ll)y[i+1]*y[i+1]+(ll)a[i]*a[i]); }else{ cout << get(a[i])+(ll)a[i]*a[i] << "\n"; return 0; } } } ;