結果

問題 No.705 ゴミ拾い Hard
ユーザー tubuanntubuann
提出日時 2019-06-28 11:37:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,120 bytes
コンパイル時間 3,009 ms
コンパイル使用メモリ 207,352 KB
実行使用メモリ 20,836 KB
最終ジャッジ日時 2023-09-14 21:19:41
合計ジャッジ時間 8,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,148 KB
testcase_01 AC 6 ms
7,016 KB
testcase_02 AC 6 ms
7,020 KB
testcase_03 AC 7 ms
6,956 KB
testcase_04 AC 7 ms
6,948 KB
testcase_05 AC 7 ms
7,096 KB
testcase_06 AC 7 ms
6,952 KB
testcase_07 AC 7 ms
7,008 KB
testcase_08 AC 7 ms
7,068 KB
testcase_09 AC 7 ms
7,060 KB
testcase_10 AC 7 ms
6,964 KB
testcase_11 AC 7 ms
6,964 KB
testcase_12 AC 7 ms
7,064 KB
testcase_13 AC 7 ms
7,076 KB
testcase_14 AC 155 ms
6,964 KB
testcase_15 AC 167 ms
6,980 KB
testcase_16 AC 159 ms
7,196 KB
testcase_17 AC 168 ms
7,092 KB
testcase_18 AC 164 ms
6,956 KB
testcase_19 AC 161 ms
7,020 KB
testcase_20 AC 170 ms
7,084 KB
testcase_21 AC 169 ms
6,968 KB
testcase_22 AC 168 ms
7,128 KB
testcase_23 AC 155 ms
7,072 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define F first
#define S second




    vector<int> am(500000);
    
    //argmin(cul(i,*))<=argmin(cul(j,*)) for(i<j)
    //を満たすn行m列の行列で、各行の最小値を求め、そのindexを返す。
    template<typename T,typename F>
    inline vector<int> argmin(F cul,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=cul(j,l);
                am[j]=l;
                for(int k=l+1;k<r;k++){
                    if(cul(j,k)<a){
                        a=cul(j,k);
                        am[j]=k;
                    }
                }
            }
        }
        return am;
    }
    
    //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,typename F>
    inline vector<T> divide_and_conquer(F cul,int n,vector<T> &ret){
        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);};
            argmin<T,F>(fnc,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;
    }



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