結果

問題 No.705 ゴミ拾い Hard
ユーザー chocoruskchocorusk
提出日時 2019-10-19 11:03:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 358 ms / 1,500 ms
コード長 1,621 bytes
コンパイル時間 1,365 ms
コンパイル使用メモリ 119,996 KB
実行使用メモリ 17,516 KB
最終ジャッジ日時 2024-06-26 22:29:37
合計ジャッジ時間 8,591 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,928 KB
testcase_01 AC 3 ms
9,804 KB
testcase_02 AC 3 ms
9,932 KB
testcase_03 AC 3 ms
9,928 KB
testcase_04 AC 3 ms
9,804 KB
testcase_05 AC 3 ms
9,932 KB
testcase_06 AC 3 ms
9,804 KB
testcase_07 AC 3 ms
9,932 KB
testcase_08 AC 4 ms
9,804 KB
testcase_09 AC 3 ms
9,932 KB
testcase_10 AC 3 ms
9,928 KB
testcase_11 AC 3 ms
9,932 KB
testcase_12 AC 3 ms
9,928 KB
testcase_13 AC 3 ms
9,932 KB
testcase_14 AC 4 ms
9,936 KB
testcase_15 AC 3 ms
9,812 KB
testcase_16 AC 4 ms
9,808 KB
testcase_17 AC 3 ms
9,936 KB
testcase_18 AC 3 ms
9,932 KB
testcase_19 AC 4 ms
9,932 KB
testcase_20 AC 4 ms
9,932 KB
testcase_21 AC 4 ms
9,804 KB
testcase_22 AC 3 ms
9,936 KB
testcase_23 AC 4 ms
9,936 KB
testcase_24 AC 272 ms
17,260 KB
testcase_25 AC 274 ms
17,260 KB
testcase_26 AC 270 ms
17,388 KB
testcase_27 AC 273 ms
17,300 KB
testcase_28 AC 273 ms
17,384 KB
testcase_29 AC 272 ms
17,392 KB
testcase_30 AC 349 ms
17,388 KB
testcase_31 AC 291 ms
17,384 KB
testcase_32 AC 272 ms
17,392 KB
testcase_33 AC 246 ms
17,264 KB
testcase_34 AC 248 ms
17,260 KB
testcase_35 AC 253 ms
17,260 KB
testcase_36 AC 269 ms
17,264 KB
testcase_37 AC 254 ms
17,256 KB
testcase_38 AC 267 ms
17,364 KB
testcase_39 AC 358 ms
17,516 KB
testcase_40 AC 3 ms
9,804 KB
testcase_41 AC 3 ms
9,932 KB
testcase_42 AC 3 ms
9,932 KB
testcase_43 AC 273 ms
17,252 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In lambda function,
    inlined from 'monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)> [with auto:1 = monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)>]' at main.cpp:47:8,
    inlined from 'monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)> [with auto:1 = monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)>]' at main.cpp:47:8:
main.cpp:47:22: warning: 'k' may be used uninitialized [-Wmaybe-uninitialized]
   47 |                 solve(solve, m+1, u, k, r);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp: In lambda function:
main.cpp:37:21: note: 'k' was declared here
   37 |                 int k;
      |                     ^
In lambda function,
    inlined from 'monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)> [with auto:1 = monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)>]' at main.cpp:46:8,
    inlined from 'monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)> [with auto:1 = monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)>]' at main.cpp:46:8,
    inlined from 'monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)> [with auto:1 = monotone_minima(int, int, const std::function<long long int(int, int)>&)::<lambda(auto:1, int, int, int, int)>]' at main.cpp:47:8:
main.cpp:47:22: warning: 'k' may be used uninitialized [-Wmaybe-uninitialized]
   47 |                 solve(solve, m+1, u, k, r);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp: In lambda function:
main.cpp:37:21: note: 'k' was declared here
   37 |     

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;
int n;
ll a[300030], x[300030], y[300030];
ll dp[300030];
vector<P> monotone_minima(int h, int w, const function<ll(int, int)> &f){
	vector<P> dp(h);
	const ll INF=1e18;
	auto solve=[&](auto solve, int d, int u, int l, int r)->void{
		if(d>u) return;
		int m=(d+u)/2;
		ll mn=INF;
		int k;
		for(int i=l; i<=r; i++){
			ll v=f(m, i);
			if(mn>v){
				mn=v;
				k=i;
			}
		}
		dp[m]=P(k, mn);
		solve(solve, d, m-1, l, k);
		solve(solve, m+1, u, k, r);
	};
	solve(solve, 0, h-1, 0, w-1);
	return dp;
}
void solve(int l, int r){
	if(l>r) return;
	int m=(l+r)/2;
	solve(l, m-1);
	vector<P> dp1=monotone_minima(r-m+1, m-l+1, [&](int i, int j){ return dp[j+l-1]+y[j+l]*y[j+l]*y[j+l]+abs(x[j+l]-a[i+m])*abs(x[j+l]-a[i+m])*abs(x[j+l]-a[i+m]);});
	for(int i=m; i<=r; i++) dp[i]=min(dp[i], dp1[i-m].second);
	solve(m+1, r);
}
int main()
{
	scanf("%d", &n);
	const ll INF=1e18;
	fill(dp, dp+n+1, INF);
	dp[0]=0;
	for(int i=1; i<=n; i++) scanf("%lld", &a[i]);
	for(int i=1; i<=n; i++) scanf("%lld", &x[i]);
	for(int i=1; i<=n; i++) scanf("%lld", &y[i]);
	solve(1, n);
	printf("%lld\n", dp[n]);
    return 0;
}
0