結果

問題 No.703 ゴミ拾い Easy
ユーザー oshiborioshibori
提出日時 2018-06-16 18:33:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 1,500 ms
コード長 2,075 bytes
コンパイル時間 3,214 ms
コンパイル使用メモリ 172,372 KB
実行使用メモリ 12,712 KB
最終ジャッジ日時 2023-08-30 18:58:00
合計ジャッジ時間 6,460 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 94 ms
12,684 KB
testcase_25 AC 93 ms
12,464 KB
testcase_26 AC 94 ms
12,532 KB
testcase_27 AC 94 ms
12,384 KB
testcase_28 AC 94 ms
12,576 KB
testcase_29 AC 94 ms
12,600 KB
testcase_30 AC 94 ms
12,712 KB
testcase_31 AC 93 ms
12,408 KB
testcase_32 AC 93 ms
12,420 KB
testcase_33 AC 93 ms
12,484 KB
testcase_34 AC 83 ms
12,540 KB
testcase_35 AC 83 ms
12,400 KB
testcase_36 AC 82 ms
12,536 KB
testcase_37 AC 82 ms
12,564 KB
testcase_38 AC 82 ms
12,400 KB
testcase_39 AC 83 ms
12,460 KB
testcase_40 AC 83 ms
12,416 KB
testcase_41 AC 82 ms
12,404 KB
testcase_42 AC 82 ms
12,508 KB
testcase_43 AC 82 ms
12,532 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
testcase_46 AC 97 ms
12,464 KB
testcase_47 AC 97 ms
12,560 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

class ConvexHullTrick {
public:
  deque<pair<int, int>> lines;

  bool check(pair<int, int> l1, pair<int, int> l2, pair<int, int> l3) {
    int a1 = l1.first, b1 = l1.second;
    int a2 = l2.first, b2 = l2.second;
    int a3 = l3.first, b3 = l3.second;
    return (a2 - a3) * (b1 - b2) <= (a1 - a2) * (b2 - b3);
  }
  void add(int a, int b) {
    pair<int, int> line(a, b);
    while (lines.size() >= 2 and
           check(lines[lines.size() - 2], lines[lines.size() - 1], line)) {
      lines.pop_back();
    }
    lines.emplace_back(line);
  }
  int f(int j, int x) { return lines[j].first * x + lines[j].second; }

  int query(int x) {
    while(lines.size()>=2 and f(0,x)>=f(1,x)){
      lines.pop_front();
    }
    return f(0,x);
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, 0, N) { cin >> a[i]; }
  vector<int> x(N);
  rep(i, 0, N) { cin >> x[i]; }
  vector<int> y(N);
  rep(i, 0, N) { cin >> y[i]; }

  ConvexHullTrick cht;

  vector<int> dp(N + 1);
  dp[0] = 0;
  rep(i, 1, N + 1) {
    cht.add(-2 * x[i - 1],
            dp[i - 1] + x[i - 1] * x[i - 1] + y[i - 1] * y[i - 1]);

    dp[i] = a[i - 1] * a[i - 1] + cht.query(a[i-1]);
  }
  cout<<dp[N]<<endl;

  return 0;
}
0