結果

問題 No.705 ゴミ拾い Hard
ユーザー tubuanntubuann
提出日時 2019-06-28 10:55:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,115 bytes
コンパイル時間 1,383 ms
コンパイル使用メモリ 142,568 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2023-09-14 21:13:44
合計ジャッジ時間 12,926 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,484 KB
testcase_17 WA -
testcase_18 AC 3 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 4 ms
4,504 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 434 ms
13,556 KB
testcase_34 AC 433 ms
13,552 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 478 ms
13,548 KB
testcase_38 AC 502 ms
13,484 KB
testcase_39 WA -
testcase_40 AC 2 ms
4,380 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 577 ms
13,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

const int SIZE=300500;

namespace Monotone_Minima{
    vector<int> am(SIZE);
    function<ll(int,int)> fnc;
    
    //argmin(cul(i,*))<=argmin(cul(j,*)) for(i<j)
    //を満たすn行m列の行列で、各行の最小値を求め、そのindexを返す。
    template<typename T>
    void argmin(int n,int m){
        for(int i=0;i<n;i++){am[i]=-1;}
        int i=2;
        while(i<n){i<<=1;}
        while(i>>=1){
            for(int j=0;j<n;j+=i){
                if(am[j]!=-1){continue;}
                int l=(j-i>=0 && am[j-i]!=-1?am[j-i]:0),r=(j+i<n && am[j+i]!=-1?am[j+i]+1:m);
                T a=fnc(j,l);
                am[j]=l;
                for(int k=l+1;k<r;k++){
                    if(fnc(j,k)<a){
                        a=fnc(j,k);
                        am[j]=k;
                    }
                }
            }
        }
    }
    
    //f(i,k)+f(j,l)<=f(i,l)+f(j,k) for(i<=j,k<=l)
    //を満たすn行n列の行列Aに対して、
    //dp[i]=min_{j<i} dp[j]+A_{i,j}
    //を求める。
    template<typename T>
    vector<T> divide_and_conquer(function<T(int,int)> cul,int n,T e=T()){
        vector<T> ret(n,e);
        for(int i=1;i<n;i++){ret[i]=ret[0]+cul(i,0);}
        for(int i=1;i<n;i++){
            int j=i&(-i);
            int k=i-j;
            fnc=[&](int a,int b){return ret[k+b]+cul(i+a,k+b);};
            argmin<T>(min(j,n-i),j);
            for(int s=0;s<j && i+s<n;s++){
                T a=fnc(s,am[s]);
                if(a<ret[i+s]){ret[i+s]=a;}
            }
        }
        return ret;
    }
}

using namespace Monotone_Minima;


int main(){
    ll n;
    cin>>n;
    vector<ll> A(n),X(n),Y(n);
    cin>>A>>X>>Y;
    function<ll(int,int)> cul=[&](int i,int j){i--; return i<j?1e15:(A[i]-X[j])*(A[i]-X[j])*(A[i]-X[j])+Y[j]*Y[j]*Y[j];};
    vector<ll> ans=divide_and_conquer<ll>(cul,n+1,0);
    cout<<ans.back()<<endl;
    
    
    return 0;
}
0