結果

問題 No.703 ゴミ拾い Easy
ユーザー たこしたこし
提出日時 2018-09-27 17:59:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 264 ms / 1,500 ms
コード長 2,197 bytes
コンパイル時間 2,023 ms
コンパイル使用メモリ 150,800 KB
実行使用メモリ 17,856 KB
最終ジャッジ日時 2023-08-30 19:01:41
合計ジャッジ時間 8,739 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
9,500 KB
testcase_01 AC 3 ms
9,456 KB
testcase_02 AC 3 ms
9,444 KB
testcase_03 AC 3 ms
9,460 KB
testcase_04 AC 2 ms
9,452 KB
testcase_05 AC 2 ms
9,512 KB
testcase_06 AC 2 ms
9,572 KB
testcase_07 AC 3 ms
9,500 KB
testcase_08 AC 3 ms
9,532 KB
testcase_09 AC 3 ms
9,516 KB
testcase_10 AC 3 ms
9,632 KB
testcase_11 AC 3 ms
9,444 KB
testcase_12 AC 3 ms
9,460 KB
testcase_13 AC 2 ms
9,500 KB
testcase_14 AC 3 ms
9,640 KB
testcase_15 AC 3 ms
9,464 KB
testcase_16 AC 3 ms
9,488 KB
testcase_17 AC 3 ms
9,576 KB
testcase_18 AC 4 ms
9,568 KB
testcase_19 AC 3 ms
9,544 KB
testcase_20 AC 3 ms
9,668 KB
testcase_21 AC 3 ms
9,468 KB
testcase_22 AC 3 ms
9,684 KB
testcase_23 AC 3 ms
9,520 KB
testcase_24 AC 240 ms
17,640 KB
testcase_25 AC 240 ms
17,712 KB
testcase_26 AC 241 ms
17,684 KB
testcase_27 AC 240 ms
17,664 KB
testcase_28 AC 240 ms
17,688 KB
testcase_29 AC 240 ms
17,640 KB
testcase_30 AC 241 ms
17,696 KB
testcase_31 AC 241 ms
17,856 KB
testcase_32 AC 241 ms
17,680 KB
testcase_33 AC 241 ms
17,660 KB
testcase_34 AC 198 ms
17,640 KB
testcase_35 AC 198 ms
17,688 KB
testcase_36 AC 198 ms
17,844 KB
testcase_37 AC 198 ms
17,844 KB
testcase_38 AC 198 ms
17,624 KB
testcase_39 AC 197 ms
17,744 KB
testcase_40 AC 198 ms
17,676 KB
testcase_41 AC 199 ms
17,692 KB
testcase_42 AC 198 ms
17,708 KB
testcase_43 AC 197 ms
17,680 KB
testcase_44 AC 2 ms
9,484 KB
testcase_45 AC 3 ms
9,536 KB
testcase_46 AC 264 ms
17,640 KB
testcase_47 AC 251 ms
17,844 KB
testcase_48 AC 3 ms
9,448 KB
testcase_49 AC 3 ms
9,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <cstdio>
#include <string>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

const int MAX_N = 500005;
const int MAX_K = 500005;

template< class T >
struct ConvexHullTrickAddQueryMonotone
{
  deque< pair< T, T > > L;
  int isdec;
 
  ConvexHullTrickAddQueryMonotone() : isdec(-1) {}
 
  inline T getX(const pair< T, T > &a, const T &x)
  {
    return (a.first * x + a.second);
  }
 
  inline bool check(const pair< T, T > &a, const pair< T, T > &b, const pair< T, T > &c)
  {
    return ((b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first));
  }
 
  inline bool empty() { return (L.empty()); }
 
  void add(T a, T b)
  {
    pair< T, T > line(a, b);
 
    if(!L.empty() && L.back().first == a) {
      line.second = min(line.second, L.back().second);
      L.pop_back();
    }
    while(L.size() >= 2 && check(L[L.size() - 2], L.back(), line)) L.pop_back();
    L.emplace_back(line);
 
  }
 
  T getMinimumQuery(T x)
  {
    int low = -1, high = (int) L.size() - 1;
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if((getX(L[mid], x) >= getX(L[mid + 1], x))) low = mid;
      else high = mid;
    }
    return (getX(L[high], x));
  }
 
  T getMinimumQueryMonotone(T x)
  {
    while(L.size() >= 2 && getX(L[0], x) >= getX(L[1], x)) {
      L.pop_front();
    }
    return (getX(L[0], x));
  }
 
};

int N;
int A[MAX_N];
int X[MAX_N];
int Y[MAX_N];

int dp[MAX_N];

signed main()
{
    cin >> N;
    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];
    }

    ConvexHullTrickAddQueryMonotone<int> cht;

    for(int i = 1; i <= N; i++) {
        cht.add(-2*X[i-1], dp[i-1] + X[i-1]*X[i-1] + Y[i-1]*Y[i-1]);
        dp[i] = cht.getMinimumQueryMonotone(A[i-1]) + A[i-1]*A[i-1];
    }

    cout << dp[N] << endl;

    return 0;
}
0