結果
問題 | No.703 ゴミ拾い Easy |
ユーザー | firiexp |
提出日時 | 2020-03-30 20:54:11 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,134 bytes |
コンパイル時間 | 1,225 ms |
コンパイル使用メモリ | 88,580 KB |
最終ジャッジ日時 | 2023-09-05 06:30:11 |
合計ジャッジ時間 | 5,837 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:18:39: エラー: ‘::numeric_limits’ has not been declared 18 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; | ^~~~~~~~~~~~~~ main.cpp:18:55: エラー: expected primary-expression before ‘>’ token 18 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; | ^ main.cpp:18:61: エラー: ‘max()’ の呼び出しに適合する関数がありません 18 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; | ~~~~~^~ 次のファイルから読み込み: /usr/local/gcc7/include/c++/12.2.0/string:50, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/bits/locale_classes.h:40, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/bits/ios_base.h:41, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/ios:42, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/ostream:38, 次から読み込み: /usr/local/gcc7/include/c++/12.2.0/iostream:39, 次から読み込み: main.cpp:1: /usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:254:5: 備考: 候補: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’ 254 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:254:5: 備考: template argument deduction/substitution failed: main.cpp:18:61: 備考: 候補では 2 個の引数が予期されますが、0 個の引数が与えられています 18 | template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208; | ~~~~~^~ /usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:300:5: 備考: 候補: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(co
ソースコード
#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; }