結果

問題 No.703 ゴミ拾い Easy
ユーザー snrnsidysnrnsidy
提出日時 2023-05-05 11:33:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 1,500 ms
コード長 3,792 bytes
コンパイル時間 3,312 ms
コンパイル使用メモリ 358,060 KB
実行使用メモリ 12,980 KB
最終ジャッジ日時 2024-05-02 08:35:44
合計ジャッジ時間 8,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,080 KB
testcase_01 AC 5 ms
11,612 KB
testcase_02 AC 4 ms
11,224 KB
testcase_03 AC 4 ms
10,720 KB
testcase_04 AC 4 ms
10,972 KB
testcase_05 AC 4 ms
10,456 KB
testcase_06 AC 4 ms
9,948 KB
testcase_07 AC 4 ms
10,460 KB
testcase_08 AC 4 ms
10,464 KB
testcase_09 AC 3 ms
10,588 KB
testcase_10 AC 5 ms
10,968 KB
testcase_11 AC 4 ms
10,332 KB
testcase_12 AC 3 ms
10,076 KB
testcase_13 AC 4 ms
10,588 KB
testcase_14 AC 5 ms
10,220 KB
testcase_15 AC 4 ms
10,860 KB
testcase_16 AC 5 ms
11,116 KB
testcase_17 AC 4 ms
11,500 KB
testcase_18 AC 5 ms
10,472 KB
testcase_19 AC 4 ms
10,216 KB
testcase_20 AC 4 ms
11,364 KB
testcase_21 AC 5 ms
10,988 KB
testcase_22 AC 5 ms
9,960 KB
testcase_23 AC 4 ms
10,216 KB
testcase_24 AC 81 ms
12,768 KB
testcase_25 AC 82 ms
12,896 KB
testcase_26 AC 81 ms
12,896 KB
testcase_27 AC 81 ms
12,912 KB
testcase_28 AC 81 ms
12,836 KB
testcase_29 AC 82 ms
12,768 KB
testcase_30 AC 81 ms
12,896 KB
testcase_31 AC 83 ms
12,900 KB
testcase_32 AC 82 ms
12,900 KB
testcase_33 AC 82 ms
12,888 KB
testcase_34 AC 72 ms
12,716 KB
testcase_35 AC 72 ms
12,892 KB
testcase_36 AC 72 ms
12,900 KB
testcase_37 AC 71 ms
12,844 KB
testcase_38 AC 74 ms
12,764 KB
testcase_39 AC 72 ms
12,892 KB
testcase_40 AC 73 ms
12,768 KB
testcase_41 AC 72 ms
12,860 KB
testcase_42 AC 72 ms
12,896 KB
testcase_43 AC 71 ms
12,980 KB
testcase_44 AC 4 ms
11,612 KB
testcase_45 AC 5 ms
11,100 KB
testcase_46 AC 83 ms
12,704 KB
testcase_47 AC 83 ms
12,824 KB
testcase_48 AC 5 ms
11,492 KB
testcase_49 AC 4 ms
10,344 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In member function 'void CHT::add(int, lint)',
    inlined from 'int main()' at main.cpp:119:9:
main.cpp:81:44: warning: 'cht.CHT::p' is used uninitialized [-Wuninitialized]
   81 |                         while (v.size() >= p + 2 && chk(v[v.size() - 2], v.back(), pi(x, y))) {
      |                                            ^
main.cpp: In function 'int main()':
main.cpp:114:13: note: 'cht' declared here
  114 |         CHT cht;
      |             ^~~

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")	
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping") 
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma") 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") 
//#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long lint;
typedef long double llf;
typedef pair<lint, lint> pi;

struct line
{
	long long int a, b;
};

class CHT 
{
	public:
		vector<pi> v;
		int p;
		lint query(lint x) {
			if (v.empty()) return 1e18;
			while (p + 1 < v.size() && v[p].first * x + v[p].second > v[p + 1].first * x + v[p + 1].second) p++;
			return v[p].first * x + v[p].second;
		}
		bool chk(pi a, pi b, pi c) {
			return 1ll * (b.first - a.first) * (b.second - c.second) < (c.first - b.first) * (a.second - b.second);
		}
		void add(int x, lint y) {
			if (!v.empty() && v.back().first == x) {
				if (v.back().second < y) return;
				v.pop_back();
			}
			while (v.size() >= p + 2 && chk(v[v.size() - 2], v.back(), pi(x, y))) {
				v.pop_back();
			}
			v.emplace_back(x, y);
		}
		void clear()
		{
			v.clear();
		}
};

long long int dp[300005];
long long int a[300005];
long long int x[300005];
long long int y[300005];
int n;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;

	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=1;i<=n;i++) cin >> x[i];
	for(int i=1;i<=n;i++) cin >> y[i];
	fill(dp, dp + 300005, 1e18);
	dp[0] = 0;	

	//dp[i] = min(0<=j<i) dp[j] + a[i]^2 - 2*x[j+1]*a[i] + x[j+1]^2 + y[j+1]^2
	// A[i] = -2*x[i] , B[j] = a[j+1] , C[j] = dp[j] + x[j+1]^2 + y[j+1]^2, D[i] = a[i]^2

	CHT cht;
	line ins;
	ins.a = -x[1];
	ins.b = dp[0] + x[1]*x[1] + y[1]*y[1];
	//tree.insert(-1e12,1e12,x[1],dp[0] + x[1]*x[1] + y[1]*y[1]);
	cht.add(ins.a,ins.b);
	for (int i = 1; i <= n; i++)
	{
		//cout << cht.query2(B*i) + (B * ((i * (i + 1)) / 2)) - (A * i) << '\n';
		dp[i] = cht.query(2*a[i]) + a[i]*a[i];
		cht.add(-x[i+1],dp[i] + x[i+1]*x[i+1] + y[i+1]*y[i+1]);
		//tree.insert(-1e12,1e12,x[i+1],dp[i] + x[i+1]*x[i+1] + y[i+1]*y[i+1]);
	}

	cout << dp[n] << '\n';

	return 0;
}
0