結果

問題 No.705 ゴミ拾い Hard
ユーザー tubuanntubuann
提出日時 2019-06-28 11:19:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 469 ms / 1,500 ms
コード長 3,244 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 143,376 KB
実行使用メモリ 13,228 KB
最終ジャッジ日時 2023-09-14 21:16:38
合計ジャッジ時間 9,638 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 269 ms
13,228 KB
testcase_25 AC 258 ms
13,096 KB
testcase_26 AC 261 ms
13,224 KB
testcase_27 AC 262 ms
13,216 KB
testcase_28 AC 262 ms
13,160 KB
testcase_29 AC 264 ms
13,096 KB
testcase_30 AC 274 ms
13,220 KB
testcase_31 AC 378 ms
13,208 KB
testcase_32 AC 368 ms
13,148 KB
testcase_33 AC 439 ms
13,104 KB
testcase_34 AC 435 ms
13,208 KB
testcase_35 AC 446 ms
13,224 KB
testcase_36 AC 450 ms
13,228 KB
testcase_37 AC 451 ms
13,212 KB
testcase_38 AC 444 ms
13,152 KB
testcase_39 AC 271 ms
13,208 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 469 ms
13,144 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;}


namespace Monotone_Minima{
    //argmin(cul(i,*))<=argmin(cul(j,*)) for(i<j)
    //を満たすn行m列の行列で、各行の最小値を求め、そのindexを返す。
    template<typename T>
    vector<int> argmin(function<T(int,int)> cul,int n,int m,function<bool(T,T)> comp=less<T>()){
        vector<int> ret(n,-1);
        int i=2;
        while(i<n){i<<=1;}
        while(i>>=1){
            for(int j=0;j<n;j+=i){
                if(ret[j]!=-1){continue;}
                int l=(j-i>=0 && ret[j-i]!=-1?ret[j-i]:0),r=(j+i<n && ret[j+i]!=-1?ret[j+i]+1:m);
                T a=cul(j,l);
                ret[j]=l;
                for(int k=l+1;k<r;k++){
                    if(comp(cul(j,k),a)){
                        a=cul(j,k);
                        ret[j]=k;
                    }
                }
            }
        }
        return ret;
    }
    
    //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(),function<bool(T,T)> comp=less<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;
            auto fnc=[&](int a,int b){return ret[k+b]+cul(i+a,k+b);};
            vector<int> am=argmin<T>(fnc,min(j,n-i),j,comp);
            for(int s=0;s<j && i+s<n;s++){
                T a=fnc(s,am[s]);
                if(comp(a,ret[i+s])){ret[i+s]=a;}
            }
        }
        return ret;
    }
}

using namespace Monotone_Minima;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    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:abs((A[i]-X[j])*(A[i]-X[j])*(A[i]-X[j]))+abs(Y[j]*Y[j]*Y[j]);};
    vector<ll> ans=divide_and_conquer<ll>(cul,n+1,0);
    cout<<ans.back()<<endl;
    
    return 0;
}

0