結果

問題 No.913 木の燃やし方
ユーザー pekempeypekempey
提出日時 2019-10-19 03:57:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,287 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 177,616 KB
実行使用メモリ 16,276 KB
最終ジャッジ日時 2023-09-08 11:34:53
合計ジャッジ時間 13,661 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 253 ms
12,296 KB
testcase_09 AC 242 ms
12,004 KB
testcase_10 AC 241 ms
12,068 KB
testcase_11 WA -
testcase_12 AC 261 ms
12,400 KB
testcase_13 AC 246 ms
12,156 KB
testcase_14 AC 239 ms
12,068 KB
testcase_15 AC 239 ms
11,916 KB
testcase_16 AC 242 ms
12,156 KB
testcase_17 AC 235 ms
12,136 KB
testcase_18 AC 234 ms
12,208 KB
testcase_19 AC 247 ms
16,216 KB
testcase_20 AC 251 ms
12,456 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 231 ms
16,100 KB
testcase_26 AC 258 ms
12,400 KB
testcase_27 AC 250 ms
16,276 KB
testcase_28 AC 251 ms
12,564 KB
testcase_29 AC 249 ms
12,368 KB
testcase_30 WA -
testcase_31 AC 233 ms
15,528 KB
testcase_32 AC 235 ms
15,652 KB
testcase_33 AC 237 ms
15,544 KB
testcase_34 AC 249 ms
12,452 KB
testcase_35 AC 248 ms
12,568 KB
testcase_36 AC 243 ms
12,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define repr2(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

struct point {
  ll x, y;
  point(ll x_ = 0, ll y_ = 0) : x(x_), y(y_) {}
  friend point operator-(point a, point b) {
    return point(a.x - b.x, a.y - b.y);
  }
  friend bool operator<(point a, point b) {
    return a.x != b.x ? a.x < b.x : a.y < b.y;
  }
};

ll cross(point a, point b) {
  return a.x * b.y - a.y * b.x;
}

vector<point> lower_hull(vector<point> ps) {
  const int n = ps.size();
  sort(ps.begin(), ps.end());
  vector<point> a;
  rep(i, ps.size()) {
    while (a.size() >= 2 && cross(a.back() - a.rbegin()[1], ps[i] - a.back()) <= 0) a.pop_back();
    a.push_back(ps[i]);
  }
  return a;
}

ll eval(point a, ll x) {
  return a.x * x + a.y;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // ----- i -----
  //    l      r
  // (r-l)^2 + s[r] - s[l]
  // r^2 + l^2 - 2*l*r + s[r] - s[l]
  // (r^2+s[r]) + (l^2 - s[l]) - 2*l*r
  // 

  int N; cin >> N;
  vector<ll> A(N); rep(i, N) cin >> A[i];
  vector<ll> S(N + 1);
  rep(i, N) S[i + 1] = S[i] + A[i];
  vector<ll> ans(N, 1e18);
  auto dfs = [&](auto dfs, int l, int r) -> void {
    if (r - l == 1) {
      ans[l] = min(ans[l], A[l] + 1);
      return;
    }
    int m = (l + r) / 2;
    dfs(dfs, l, m);
    dfs(dfs, m, r);
    vector<point> L, R;
    rep2(i, l, m + 1) L.emplace_back(i, (ll)i*i - S[i]);
    rep2(i, m, r + 1) R.emplace_back(i, (ll)i*i + S[i]);
    L = lower_hull(L);
    R = lower_hull(R);
    ll mn = 1e18;
    int k = R.size() - 1;
    rep2(i, l, m) {
      while (k - 1 >= 0 && eval(R[k], -2*i) >= eval(R[k - 1], -2*i)) k--;
      mn = min(mn, eval(R[k], -2*i) + ((ll)i*i - S[i]));
      ans[i] = min(ans[i], mn);
    }
    k = 0;
    mn = 1e18;
    repr2(i, m+1, r+1) {
      while (k + 1 < L.size() && eval(L[k], -2*i) >= eval(L[k + 1], -2*i)) k++;
      mn = min(mn, eval(L[k], -2*i) + ((ll)i*i + S[i]));
      ans[i - 1] = min(ans[i - 1], mn);
    }
  };
  dfs(dfs, 0, N);
  rep(i, N) cout << ans[i] << '\n';
}
0