結果
| 問題 | No.705 ゴミ拾い Hard |
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2019-10-19 11:03:51 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 169 ms / 1,500 ms |
| コード長 | 1,621 bytes |
| 記録 | |
| コンパイル時間 | 941 ms |
| コンパイル使用メモリ | 140,216 KB |
| 実行使用メモリ | 17,664 KB |
| 最終ジャッジ日時 | 2026-03-13 19:56:12 |
| 合計ジャッジ時間 | 7,012 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:64,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:53,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
from main.cpp:3:
In member function 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = int; _T2 = long long int]',
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:45:16:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_pair.h:957:15: warning: 'k' may be used uninitialized [-Wmaybe-uninitialized]
957 | first = std::forward<first_type>(__p.first);
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In lambda function:
main.cpp:37:21: note: 'k' was declared here
37 | int k;
| ^
In member function 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__non
ソースコード
#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;
}
chocorusk