提出 #33645641


ソースコード 拡げる

#include <bits/stdc++.h>

using num = int64_t;
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define INF 0x3f3f3f3f3f3f3f3f

class LiChao {
	vector<ll> m, b;
	int n, sz; ll *x;
#define gx(i) (i < sz ? x[i] : x[sz-1])
	void update(int t, int l, int r, ll nm, ll nb) {
		ll xl = nm * gx(l) + nb, xr = nm * gx(r) + nb;
		ll yl = m[t] * gx(l) + b[t], yr = m[t] * gx(r) + b[t];
        if (yl >= xl && yr >= xr) return;
		if (yl <= xl && yr <= xr) {
			m[t] = nm, b[t] = nb; return;
		}
		int mid = (l + r) / 2;
		update(t<<1, l, mid, nm, nb);
		update(1+(t<<1), mid+1, r, nm, nb);
	}
public:
	LiChao(ll *st, ll *en) : x(st) {
		sz = int(en - st);
		for(n = 1; n < sz; n <<= 1);
		m.assign(2*n, 0); b.assign(2*n, -INF);
	}
	void insert_line(ll nm, ll nb) {
		update(1, 0, n-1, nm, nb);
	}
	ll query(int i) {
		ll ans = -INF;
		for(int t = i+n; t; t >>= 1)
			ans = max(ans, m[t] * x[i] + b[t]);
		return ans;
	}
};

ll xs[1000000];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

    ll N, C;
    cin >> N >> C;
    rep(i, 1, 1000001) xs[i-1] = i;
    LiChao chtTree(xs, xs+1000000);

    ll minCost = 0;
    rep(i, 0, N) {
        ll newLocation;
        cin >> newLocation;
        if (i > 0) {
            minCost = -chtTree.query(newLocation-1)+newLocation*newLocation;
        }
        chtTree.insert_line(2*newLocation, -(minCost+newLocation*newLocation+C));
    }
    cout << minCost << "\n";
}

提出情報

提出日時
問題 Z - Frog 3
ユーザ Noble_Mushtak
言語 C++ (GCC 9.2.1)
得点 100
コード長 1657 Byte
結果 AC
実行時間 109 ms
メモリ 43844 KiB

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 39
セット名 テストケース
All 0_00, 0_01, 0_02, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17, 1_18, 1_19, 1_20, 1_21, 1_22, 1_23, 1_24, 1_25, 1_26, 1_27, 1_28, 1_29, 1_30, 1_31, 1_32, 1_33, 1_34, 1_35
ケース名 結果 実行時間 メモリ
0_00 AC 28 ms 43796 KiB
0_01 AC 34 ms 43784 KiB
0_02 AC 36 ms 43728 KiB
1_00 AC 33 ms 43676 KiB
1_01 AC 31 ms 43788 KiB
1_02 AC 107 ms 43748 KiB
1_03 AC 107 ms 43724 KiB
1_04 AC 109 ms 43760 KiB
1_05 AC 107 ms 43752 KiB
1_06 AC 49 ms 43788 KiB
1_07 AC 102 ms 43788 KiB
1_08 AC 100 ms 43748 KiB
1_09 AC 104 ms 43676 KiB
1_10 AC 102 ms 43836 KiB
1_11 AC 104 ms 43740 KiB
1_12 AC 105 ms 43676 KiB
1_13 AC 104 ms 43748 KiB
1_14 AC 104 ms 43800 KiB
1_15 AC 99 ms 43692 KiB
1_16 AC 88 ms 43724 KiB
1_17 AC 95 ms 43676 KiB
1_18 AC 75 ms 43784 KiB
1_19 AC 50 ms 43784 KiB
1_20 AC 93 ms 43788 KiB
1_21 AC 98 ms 43728 KiB
1_22 AC 77 ms 43808 KiB
1_23 AC 86 ms 43740 KiB
1_24 AC 52 ms 43672 KiB
1_25 AC 90 ms 43780 KiB
1_26 AC 96 ms 43756 KiB
1_27 AC 81 ms 43780 KiB
1_28 AC 95 ms 43804 KiB
1_29 AC 87 ms 43676 KiB
1_30 AC 96 ms 43844 KiB
1_31 AC 78 ms 43676 KiB
1_32 AC 56 ms 43676 KiB
1_33 AC 78 ms 43788 KiB
1_34 AC 67 ms 43672 KiB
1_35 AC 80 ms 43840 KiB