結果

問題 No.703 ゴミ拾い Easy
ユーザー tubuanntubuann
提出日時 2019-06-24 11:44:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,037 bytes
コンパイル時間 1,597 ms
コンパイル使用メモリ 144,180 KB
実行使用メモリ 13,288 KB
最終ジャッジ日時 2023-08-30 23:27:27
合計ジャッジ時間 18,374 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
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 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
    }
    
    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(){
    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])+Y[j]*Y[j];};
    vector<ll> ans=divide_and_conquer<ll>(cul,n+1,0);
    cout<<ans<<endl;
    cout<<ans.back()<<endl;
    
    
    return 0;
}
0