結果

問題 No.703 ゴミ拾い Easy
ユーザー azbrugbyazbrugby
提出日時 2019-03-16 18:07:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 108 ms / 1,500 ms
コード長 2,050 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 81,076 KB
実行使用メモリ 12,996 KB
最終ジャッジ日時 2023-08-30 19:04:32
合計ジャッジ時間 5,689 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,520 KB
testcase_01 AC 2 ms
5,432 KB
testcase_02 AC 2 ms
5,556 KB
testcase_03 AC 2 ms
5,468 KB
testcase_04 AC 3 ms
5,592 KB
testcase_05 AC 2 ms
5,544 KB
testcase_06 AC 2 ms
5,508 KB
testcase_07 AC 2 ms
5,592 KB
testcase_08 AC 3 ms
5,544 KB
testcase_09 AC 2 ms
5,512 KB
testcase_10 AC 2 ms
5,768 KB
testcase_11 AC 2 ms
5,440 KB
testcase_12 AC 2 ms
5,748 KB
testcase_13 AC 2 ms
5,748 KB
testcase_14 AC 3 ms
5,460 KB
testcase_15 AC 2 ms
5,636 KB
testcase_16 AC 2 ms
5,452 KB
testcase_17 AC 3 ms
5,608 KB
testcase_18 AC 2 ms
5,464 KB
testcase_19 AC 3 ms
5,508 KB
testcase_20 AC 2 ms
5,620 KB
testcase_21 AC 3 ms
5,544 KB
testcase_22 AC 2 ms
5,528 KB
testcase_23 AC 3 ms
5,608 KB
testcase_24 AC 104 ms
12,792 KB
testcase_25 AC 104 ms
12,752 KB
testcase_26 AC 103 ms
12,936 KB
testcase_27 AC 104 ms
12,824 KB
testcase_28 AC 104 ms
12,840 KB
testcase_29 AC 103 ms
12,844 KB
testcase_30 AC 103 ms
12,760 KB
testcase_31 AC 104 ms
12,824 KB
testcase_32 AC 104 ms
12,748 KB
testcase_33 AC 104 ms
12,800 KB
testcase_34 AC 92 ms
12,928 KB
testcase_35 AC 92 ms
12,940 KB
testcase_36 AC 93 ms
12,764 KB
testcase_37 AC 92 ms
12,864 KB
testcase_38 AC 93 ms
12,996 KB
testcase_39 AC 94 ms
12,936 KB
testcase_40 AC 92 ms
12,840 KB
testcase_41 AC 93 ms
12,916 KB
testcase_42 AC 92 ms
12,792 KB
testcase_43 AC 92 ms
12,872 KB
testcase_44 AC 2 ms
5,536 KB
testcase_45 AC 2 ms
5,504 KB
testcase_46 AC 108 ms
12,840 KB
testcase_47 AC 107 ms
12,796 KB
testcase_48 AC 3 ms
5,704 KB
testcase_49 AC 3 ms
5,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <cstdio>
#include <cmath>
#include <bitset>
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;

const ll MOD = 1234567, N = 300010, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838;
const int S = 60;
ll mn(ll a, ll b) {
	if (a == -1)return b;
	if (b == -1)return a;
	return min(a, b);
}
static ll gcd(ll v1, ll v2) {
	if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2);
}

ll pw(ll v1, ll v2) {
	ll v3 = 1;
	while (v2 > 0) {
		if (v2 % 2)v3 = (v3*v1) % MOD;
		v1 = (v1*v1) % MOD;
		v2 /= 2;
	}
	return v3;
}

ll n, a[N],dp[N];
pos xy[N];

struct ConvexHullTrick {
	std::deque<std::pair<long long, long long> > dq; //(傾き、切片)

	void add(long long a, long long b) {
		std::pair<long long, long long> p0 = std::make_pair(a, b);
		while (dq.size() >= 2) {
			int sz = dq.size();
			std::pair<long long, long long> p1 = dq[sz - 1];
			std::pair<long long, long long> p2 = dq[sz - 2];
			if ((p0.second - p1.second)*(p0.first - p2.first) < (p0.second - p2.second)*(p0.first - p1.first))break;//交点のx座標を比較
			dq.pop_back();
		}
		dq.push_back(p0);
	}

	long long query(long long x) {
		while (dq.size() >= 2) {
			long long v1 = dq[0].first*x + dq[0].second;
			long long v2 = dq[1].first*x + dq[1].second;
			if (v1 <= v2)break;
			dq.pop_front();
		}
		return dq[0].first*x + dq[0].second;
	}

};
ConvexHullTrick cht;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)scanf("%d", a + i);
	for (int i = 1; i <= n; i++)scanf("%d", &xy[i].first);
	for (int i = 1; i <= n; i++)scanf("%d", &xy[i].second);
	for (int i = 1; i <= n; i++) {
		cht.add(-2*xy[i].first, dp[i - 1] + xy[i].first*xy[i].first + xy[i].second*xy[i].second);
		dp[i] = a[i] * a[i] + cht.query(a[i]);
	}
	cout << dp[n] << endl;
	return 0;
}
0