結果
| 問題 |
No.703 ゴミ拾い Easy
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-03-30 20:54:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,134 bytes |
| コンパイル時間 | 747 ms |
| コンパイル使用メモリ | 90,432 KB |
| 最終ジャッジ日時 | 2024-11-14 22:14:37 |
| 合計ジャッジ時間 | 2,603 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:18:39: error: '::numeric_limits' has not been declared
18 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
| ^~~~~~~~~~~~~~
main.cpp:18:55: error: expected primary-expression before '>' token
18 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
| ^
main.cpp:18:61: error: no matching function for call to 'max()'
18 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
| ~~~~~^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/string:50,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/locale_classes.h:40,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/ios_base.h:41,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ios:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:38,
from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/iostream:39,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
254 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed:
main.cpp:18:61: note: candidate expects 2 arguments, 0 provided
18 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
| ~~~~~^~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:300:5: note: candidate: 'templat
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template<class T, bool get_max>
class CHT {
using P = pair<T, T>;
deque<P> lines;
public:
CHT() = default;
int sgn(T x) { return x == 0 ? 0 : (x > 0 ? 1 : -1); }
bool check(P l1, P l2, P l3){
if(l1.second == l2.second || l2.second == l3.second){
return sgn(l1.first - l2.first)*sgn(l2.second - l3.second)
>= sgn(l2.first - l3.first)*sgn(l1.second - l2.second);
}else {
return (l1.first - l2.first)*sgn(l2.second - l3.second)/ static_cast<long double>(abs(l1.second - l2.second))
>= (l2.first - l3.first)*sgn(l1.second - l2.second)/ static_cast<long double>(abs(l2.second - l3.second));
}
}
void add_line(T a, T b) { // add ax + b
if(get_max) a = -a, b = -b;
P L(a, b);
if(lines.empty()){
lines.emplace_back(L);
return;
}
if(lines.front().first <= a){
if(lines.front().first == a){
if(lines.front().second <= b) return;
else lines.pop_front();
}
while(lines.size() >= 2 && check(L, lines.front(), lines[1])) lines.pop_front();
lines.emplace_front(L);
}else {
if(lines.back().first == a){
if(lines.back().second <= b) return;
else lines.pop_back();
}
while(lines.size() >= 2 && check(lines[lines.size()-2], lines.back(), L)) lines.pop_back();
lines.emplace_back(L);
}
}
T val(const P &L, const T &x) { return L.first * x + L.second; }
T query(T x){
int l = -1, r = lines.size() - 1;
while(r - l > 1){
int mid = (l+r) >> 1;
if(val(lines[mid], x) >= val(lines[mid+1], x)) l = mid;
else r = mid;
}
return get_max ? -val(lines[r], x) : val(lines[r], x);
}
T query_increase(T x){
while(lines.size() >= 2 && val(lines.front(), x) >= val(lines[1], x)) lines.pop_front();
return get_max ? -val(lines.front(), x) : val(lines.front(), x);
}
T query_decrease(T x){
while(lines.size() >= 2 && val(lines.back(), x) >= val(lines[lines.size() - 2], x)) lines.pop_back();
return get_max ? -val(lines.back(), x) : val(lines.back(), x);
}
};
int main() {
int n;
cin >> n;
vector<ll> a(n), x(n), y(n);
for (auto &&i : a) scanf("%lld", &i);
for (auto &&j : x) scanf("%lld", &j);
for (auto &&k : y) scanf("%lld", &k);
vector<ll> dp(n+1);
CHT<ll, false> G;
for (int i = 0; i < n; ++i) {
G.add_line(2*x[i], x[i]*x[i]+y[i]*y[i]+dp[i]);
dp[i+1] = G.query_decrease(-a[i])+a[i]*a[i];
}
cout << dp.back() << "\n";
return 0;
}