結果

問題 No.705 ゴミ拾い Hard
ユーザー CaiiiiiiiiCaiiiiiiii
提出日時 2024-03-26 01:26:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 1,500 ms
コード長 1,094 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 168,036 KB
実行使用メモリ 10,436 KB
最終ジャッジ日時 2024-03-26 01:26:38
合計ジャッジ時間 7,399 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,796 KB
testcase_01 AC 3 ms
9,796 KB
testcase_02 AC 3 ms
9,796 KB
testcase_03 AC 4 ms
9,796 KB
testcase_04 AC 3 ms
9,796 KB
testcase_05 AC 3 ms
9,796 KB
testcase_06 AC 4 ms
9,796 KB
testcase_07 AC 3 ms
9,796 KB
testcase_08 AC 3 ms
9,796 KB
testcase_09 AC 7 ms
9,796 KB
testcase_10 AC 3 ms
9,796 KB
testcase_11 AC 5 ms
9,796 KB
testcase_12 AC 4 ms
9,796 KB
testcase_13 AC 3 ms
9,796 KB
testcase_14 AC 3 ms
9,796 KB
testcase_15 AC 4 ms
9,796 KB
testcase_16 AC 6 ms
9,796 KB
testcase_17 AC 3 ms
9,796 KB
testcase_18 AC 4 ms
9,796 KB
testcase_19 AC 3 ms
9,796 KB
testcase_20 AC 4 ms
9,796 KB
testcase_21 AC 4 ms
9,796 KB
testcase_22 AC 4 ms
9,796 KB
testcase_23 AC 3 ms
9,796 KB
testcase_24 AC 107 ms
10,436 KB
testcase_25 AC 107 ms
10,436 KB
testcase_26 AC 107 ms
10,436 KB
testcase_27 AC 107 ms
10,436 KB
testcase_28 AC 106 ms
10,436 KB
testcase_29 AC 107 ms
10,436 KB
testcase_30 AC 111 ms
10,436 KB
testcase_31 AC 100 ms
10,436 KB
testcase_32 AC 100 ms
10,436 KB
testcase_33 AC 80 ms
10,436 KB
testcase_34 AC 82 ms
10,436 KB
testcase_35 AC 88 ms
10,436 KB
testcase_36 AC 95 ms
10,436 KB
testcase_37 AC 88 ms
10,436 KB
testcase_38 AC 97 ms
10,436 KB
testcase_39 AC 105 ms
10,436 KB
testcase_40 AC 4 ms
9,796 KB
testcase_41 AC 3 ms
9,796 KB
testcase_42 AC 3 ms
9,796 KB
testcase_43 AC 108 ms
10,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long LL;

const int N = 3e5 + 7;

struct dat {
  int l, r, p;
};

dat q[N], *fr, *ba;
int n, a[N], x[N], y[N];
LL f[N];

LL tri(LL x) {
  return x * x * x;
}

LL F(int i, int j) {
  return f[j] + tri(std::abs(a[i] - x[j + 1])) + tri(y[j + 1]);
}

int main() {

  scanf("%d", &n);
  for(int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for(int i = 1; i <= n; ++i)
    scanf("%d", &x[i]);
  for(int i = 1; i <= n; ++i)
    scanf("%d", &y[i]);

  *(fr = ba = q + 1) = {1, n, 0};
  for(int i = 1; i <= n; ++i) {
    f[i] = F(i, fr->p);
    if(++fr->l > fr->r)
      ++fr;
    while(fr <= ba && F(ba->l, i) <= F(ba->l, ba->p))
      --ba;
    if(fr > ba) 
      *++ba = {i + 1, n, i};
    else if(F(ba->r, i) <= F(ba->r, ba->p)) {
      int l = ba->l, r = ba->r;
      while(l + 1 < r) {
	int mid = l + r >> 1;
	if(F(mid, i) <= F(mid, ba->p))
	  r = mid;
	else
	  l = mid;
      }
      ba->r = r - 1;
      *++ba = {r, n, i};
    }
    else if(ba->r != n) {
      ba[1] = {ba->r + 1, n, i};
      ++ba;
    }
  }

  printf("%lld\n", f[n]);
  
  return 0;

}
0