結果

問題 No.704 ゴミ拾い Medium
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-28 12:56:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,109 bytes
コンパイル時間 543 ms
コンパイル使用メモリ 69,952 KB
実行使用メモリ 9,108 KB
最終ジャッジ日時 2023-08-28 13:02:14
合計ジャッジ時間 11,675 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 AC 91 ms
9,068 KB
testcase_47 AC 89 ms
9,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

struct MinBIT {
  static const int SIZE = 1 << 17;
  static const int INFINITY = (1 << 30) - 1;
  int bit[SIZE];
  MinBIT() {
    rep(i,SIZE)bit[i]=INFINITY;
  }
  void update(int x, int value) {
    while(x<SIZE){
      bit[x]=min(bit[x],value);
      x+=x&(-x);
    }
  }
  int query(int x) const {
    int y = INFINITY;
    while(x>0){
      y=min(y,bit[x]);
      x&=x-1;
    }
    return y;
  }
};


int a[300001],x[300001],y[300001];
int dp[300001];
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>x[i];
  rep(i,n)cin>>y[i];
  MinBIT m1;
  MinBIT p1;
  rep(i,n){
    // update
    m1.update(300001-x[i],x[i]+y[i]+dp[i]);
    p1.update(1+x[i],-x[i]+y[i]+dp[i]);
    // query
    int ans=1e9;
    int curA=a[i];
    ans=min(ans,m1.query(300001-curA)-curA);
    ans=min(ans,p1.query(curA+1)+curA);
    dp[i+1]=ans;
  }
  cout<<dp[n]<<endl;
}
0