結果

問題 No.703 ゴミ拾い Easy
ユーザー tatananonanotatananonano
提出日時 2023-03-01 17:35:25
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 127 ms / 1,500 ms
コード長 8,827 bytes
コンパイル時間 7,348 ms
コンパイル使用メモリ 272,412 KB
実行使用メモリ 33,272 KB
最終ジャッジ日時 2023-10-14 21:46:36
合計ジャッジ時間 12,867 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,356 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 123 ms
32,840 KB
testcase_25 AC 123 ms
33,164 KB
testcase_26 AC 122 ms
32,876 KB
testcase_27 AC 122 ms
33,116 KB
testcase_28 AC 121 ms
32,880 KB
testcase_29 AC 124 ms
33,072 KB
testcase_30 AC 125 ms
32,972 KB
testcase_31 AC 123 ms
32,968 KB
testcase_32 AC 122 ms
32,832 KB
testcase_33 AC 123 ms
32,908 KB
testcase_34 AC 111 ms
33,016 KB
testcase_35 AC 109 ms
32,832 KB
testcase_36 AC 109 ms
32,908 KB
testcase_37 AC 109 ms
32,964 KB
testcase_38 AC 110 ms
33,012 KB
testcase_39 AC 110 ms
32,880 KB
testcase_40 AC 108 ms
33,164 KB
testcase_41 AC 110 ms
33,024 KB
testcase_42 AC 109 ms
33,016 KB
testcase_43 AC 109 ms
33,064 KB
testcase_44 AC 2 ms
4,348 KB
testcase_45 AC 2 ms
4,352 KB
testcase_46 AC 127 ms
33,272 KB
testcase_47 AC 124 ms
33,092 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 3 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <deque>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <set>
#include <map>
#include <ctime>
#include <stack>
#include <functional>
#include <cstdio>
#include <string>
#include <iostream>
#include <limits>
#include <stdexcept>
#include <numeric>
#include <fstream>
#include <chrono>
#include <utility>
#include <cassert>
#include <random>
#include <time.h>
#include <bitset>
using namespace std;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep0(a) for (ll _ = 0; _ < ll(a); ++_)
#define rep1(i, n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i, s, n, d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1,rep0)(__VA_ARGS__)
#define rrep0(a) for (ll _ = (a)-1; _ >= ll(0); -- _)
#define rrep1(i, n) for (ll i = ll(n)-1; i >= 0; i--)
#define rrep2(i, n, t) for (ll i = ll(n)-1; i >= (ll)t; i--)
#define rrep3(i, n, t, d) for (ll i = ll(n)-1; i >= (ll)t; i-=d)
#define drep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1,rrep0)(__VA_ARGS__)
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
typedef double D;
typedef pair<ll,ll> P;
typedef map<ll,ll> M;
// /*
#include <atcoder/all>
using namespace atcoder;
//using namespace internal;
using mint =modint998244353;
//using mint =modint1000000007;
//using mint=static_modint<4649>;
#define ip(x) atcoder::internal::is_prime_constexpr(x)
istream &operator>>(istream &is, mint &a) { int v; cin >> v; a = v; return is; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.val(); }
auto v_pow(ll n,ll base){vector<mint> v(n,1);rep(i,n-1){v[i+1]*=base*v[i];}return v;}
// */
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class S, class T>
istream &operator>>(istream &is, pair<S, T> &p) { return is >> p.first >> p.second; }
template<class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << '{' << p.first << ", " << p.second << '}'; }
template<class S, class T, class U>
istream &operator>>(istream &is, tuple<S, T, U> &t) { return is >> get<0>(t) >> get<1>(t) >> get<2>(t); }
template<class S, class T, class U>
ostream &operator<<(ostream &os, const tuple<S, T, U> &t) {return os << '{' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << '}';}
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Game(n) cout << ((n) ? "First" : "Second"  ) << endl
template <typename F>
ll binary_search(F check,ll ok,ll ng,bool border= true) {
/*binary_search(bool_func,okな値,ngな値)*///しっかり区間内に...
if(border) assert(check(ok));
while(abs(ok-ng)>1){
auto x=(ng+ok)/2;
tie(ok,ng)=(check(x)?make_pair(x, ng):make_pair(ok, x));
}
return ok;
}
template <typename F>
double binary_search_real(F check,double ok,double ng,ll iter = 100) {
rep(iter) {
double x=(ok+ng)/2;
tie(ok,ng)=(check(x)?make_pair(x,ng):make_pair(ok,x));
}
return (ok+ng)/2;
}
void tatananonano() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(10);
}
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__)
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;IN(__VA_ARGS__)
#define LDL(...) LD __VA_ARGS__;IN(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
vector<vector<vector<type>>> name( \
  h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
        b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))
//#define MINT(...) mint __VA_ARGS__;IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &...tail) {scan(head);IN(tail...);}
#define overload2(_1, _2, _3,name, ...) name
#define out1(x) cout<<x<<'\n'
#define out2(x,y) cout<<x<<" "<<y<<'\n'
#define out3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define out4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<'\n'
#define out(...) overload4(__VA_ARGS__,out4,out3,out2,out1)(__VA_ARGS__)
#define print1(x) cout<<x<<'\n'
#define print2(x,n) cout<<fixed<<setprecision(n)<<x<<endl
#define print3(x,n,empty) cout<<fixed<<setprecision(n)<<x<<" "
#define print(...) overload2(__VA_ARGS__,print3,print2,print1)(__VA_ARGS__)
#define bool_print(x,y1,y2) cout<<(x?y1:y2)<<'\n';
#define all(x) (x).begin(),(x).end()
#define MAX(a) *max_element(all(a));
#define MIN(a) *min_element(all(a));
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define len(x) ll(x.size())
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define TFU(s) transform(all(s),begin(s),::toupper);//大文字にする
#define TFL(s) transform(all(s),begin(s),::tolower);//小文字にする
#define replace(s,a,A) replace(s,'a','A')//str(s)のaをAにする
#define ROT(s,i) rotate(s.begin(),s.begin()+i,s.end())//sのi番目から後ろを前にする
#define PQ priority_queue
#define PQD PQ<P,vector<P>,greater<P>>//小さい順
#define PQS PQ<ll,vec,greater<ll>>
#define fi first
#define se second
#define bit(n,k) ((n>>k)&1LL)
#define popcount(n) __builtin_popcountll(n)
template<class T> inline bool chmax(T& a,T b){if(a < b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a > b){a=b;return 1;}return 0;}
template<class T> bool in_rect(T i,T j,T h,T w) {return 0 <= i and i < h and 0 <= j and j < w;}
template<class T> bool IN(T x,T a,T b){return (a<=x and x<b);}
typedef vector<ll> vec;
typedef vector<string> vs;
typedef vector<vec> mat;
const ll mod = 998244353;
//const ll mod = 1000000007;
const auto INF = (1LL<<(60));
template <typename T, typename U>
T ceil(T x, U y) {return (x > 0 ? (x + y - 1) / y : x / y);}
template <typename T, typename U>
T floor(T x, U y) {return (x > 0 ? x / y : (x - y + 1) / y);}



template <typename T=ll>
struct li_chao_tree{
    struct line{
        T a, b;
        line(): a(0), b(INF){}
        line(T a, T b): a(a), b(b){}
        T get(T x){ return a * x + b;}
    };
    ll N;
    vector<T> x;
    vector<line> ST;
    li_chao_tree(){}
    li_chao_tree(const vector<T> &x2){
        x = x2;
        sort(x.begin(), x.end());
        ll N2 = x.size();
        N = 1;
        while (N < N2){ N *= 2;}
        x.resize(N);
        for (int i = N2; i < N; i++){ x[i] = x[N2 - 1];}
        ST = vector<line>(N * 2 - 1);
    }
    void line_add(line L, ll i, ll l, ll r){
        T la = L.get(x[l]);
        T lb = ST[i].get(x[l]);
        T ra = L.get(x[r - 1]);
        T rb = ST[i].get(x[r - 1]);
        if (la >= lb && ra >= rb){ return; }
        else if (la <= lb && ra <= rb){ ST[i] = L; }
        else {
            ll m = (l + r) / 2;
            T ma = L.get(x[m]);
            T mb = ST[i].get(x[m]);
            if (ma < mb){
            swap(L, ST[i]);
            swap(la, lb);
            swap(ra, rb);
        }
        if (la < lb){ line_add(L, i * 2 + 1, l, m); }
        if (ra < rb){ line_add(L, i * 2 + 2, m, r);}
        }
    }
    void line_add(T a, T b){ line_add(line(a, b), 0, 0, N);}
    void segment_add(int L, int R, line S, ll i, ll l, ll r){
        if (r <= L || R <= l){ return;}
        else if (L <= l && r <= R){line_add(S, i, l, r);}
        else {
        ll m = (l + r) / 2;
        segment_add(L, R, S, i * 2 + 1, l, m);
        segment_add(L, R, S, i * 2 + 2, m, r);
        }
    }
    void segment_add(T l, T r, T a, T b){
        ll pl = lower_bound(x.begin(), x.end(), l) - x.begin();
        ll pr = lower_bound(x.begin(), x.end(), r) - x.begin();
        segment_add(pl, pr, line(a, b), 0, 0, N);
    }
    T get(T x2){
        ll p = lower_bound(x.begin(), x.end(), x2) - x.begin();
        p += N - 1;
        T ans = INF;
        ans = min(ans, ST[p].get(x2));
        while (p > 0){
            p = (p - 1) / 2;
            ans = min(ans, ST[p].get(x2));
        }
        return ans;
    }
};

int main(){
tatananonano();
LL(n);
vec a(n);
vec x(n);
vec y(n);
cin>>a;
cin>>x;
cin>>y;
li_chao_tree li(a);
vec dp(n+1,INF);
dp[0]=0;
rep(i,n){
  li.line_add(-2*x[i],x[i]*x[i]+y[i]*y[i]+dp[i]);
  dp[i+1]=li.get(a[i])+a[i]*a[i];
}
cout<<dp[n]<<endl;
}
0