結果

問題 No.704 ゴミ拾い Medium
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-28 12:57:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 1,500 ms
コード長 1,109 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 70,356 KB
実行使用メモリ 9,380 KB
最終ジャッジ日時 2023-08-28 13:02:41
合計ジャッジ時間 5,110 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,448 KB
testcase_01 AC 3 ms
6,560 KB
testcase_02 AC 2 ms
6,472 KB
testcase_03 AC 2 ms
6,448 KB
testcase_04 AC 3 ms
6,472 KB
testcase_05 AC 2 ms
6,492 KB
testcase_06 AC 2 ms
6,504 KB
testcase_07 AC 3 ms
6,720 KB
testcase_08 AC 3 ms
6,556 KB
testcase_09 AC 3 ms
6,440 KB
testcase_10 AC 2 ms
6,452 KB
testcase_11 AC 3 ms
6,452 KB
testcase_12 AC 2 ms
6,456 KB
testcase_13 AC 3 ms
6,524 KB
testcase_14 AC 3 ms
6,480 KB
testcase_15 AC 3 ms
6,468 KB
testcase_16 AC 3 ms
6,484 KB
testcase_17 AC 3 ms
6,640 KB
testcase_18 AC 3 ms
6,456 KB
testcase_19 AC 3 ms
6,508 KB
testcase_20 AC 3 ms
6,504 KB
testcase_21 AC 3 ms
6,460 KB
testcase_22 AC 3 ms
6,484 KB
testcase_23 AC 3 ms
6,576 KB
testcase_24 AC 97 ms
9,136 KB
testcase_25 AC 96 ms
9,208 KB
testcase_26 AC 97 ms
9,108 KB
testcase_27 AC 96 ms
9,108 KB
testcase_28 AC 96 ms
9,084 KB
testcase_29 AC 96 ms
9,204 KB
testcase_30 AC 96 ms
9,328 KB
testcase_31 AC 96 ms
9,332 KB
testcase_32 AC 97 ms
9,088 KB
testcase_33 AC 96 ms
9,140 KB
testcase_34 AC 90 ms
9,112 KB
testcase_35 AC 90 ms
9,092 KB
testcase_36 AC 90 ms
9,144 KB
testcase_37 AC 91 ms
9,200 KB
testcase_38 AC 91 ms
9,172 KB
testcase_39 AC 91 ms
9,272 KB
testcase_40 AC 91 ms
9,380 KB
testcase_41 AC 90 ms
9,136 KB
testcase_42 AC 90 ms
9,140 KB
testcase_43 AC 91 ms
9,112 KB
testcase_44 AC 3 ms
6,448 KB
testcase_45 AC 2 ms
6,500 KB
testcase_46 AC 105 ms
9,064 KB
testcase_47 AC 102 ms
9,152 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(100001-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(100001-curA)-curA);
    ans=min(ans,p1.query(curA+1)+curA);
    dp[i+1]=ans;
  }
  cout<<dp[n]<<endl;
}
0