結果

問題 No.704 ゴミ拾い Medium
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-28 12:55:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 1,500 ms
コード長 1,109 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 70,488 KB
実行使用メモリ 12,464 KB
最終ジャッジ日時 2023-08-28 13:01:43
合計ジャッジ時間 6,415 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,512 KB
testcase_01 AC 4 ms
9,540 KB
testcase_02 AC 4 ms
9,664 KB
testcase_03 AC 4 ms
9,516 KB
testcase_04 AC 4 ms
9,536 KB
testcase_05 AC 4 ms
9,600 KB
testcase_06 AC 4 ms
9,624 KB
testcase_07 AC 4 ms
9,496 KB
testcase_08 AC 4 ms
9,560 KB
testcase_09 AC 4 ms
9,724 KB
testcase_10 AC 4 ms
9,504 KB
testcase_11 AC 4 ms
9,520 KB
testcase_12 AC 4 ms
9,536 KB
testcase_13 AC 4 ms
9,624 KB
testcase_14 AC 5 ms
9,616 KB
testcase_15 AC 5 ms
9,832 KB
testcase_16 AC 4 ms
9,512 KB
testcase_17 AC 4 ms
9,548 KB
testcase_18 AC 4 ms
9,572 KB
testcase_19 AC 5 ms
9,600 KB
testcase_20 AC 4 ms
9,516 KB
testcase_21 AC 5 ms
9,552 KB
testcase_22 AC 4 ms
9,680 KB
testcase_23 AC 4 ms
9,572 KB
testcase_24 AC 101 ms
12,220 KB
testcase_25 AC 101 ms
12,160 KB
testcase_26 AC 101 ms
12,328 KB
testcase_27 AC 101 ms
12,176 KB
testcase_28 AC 100 ms
12,220 KB
testcase_29 AC 101 ms
12,284 KB
testcase_30 AC 101 ms
12,328 KB
testcase_31 AC 101 ms
12,176 KB
testcase_32 AC 101 ms
12,160 KB
testcase_33 AC 101 ms
12,160 KB
testcase_34 AC 95 ms
12,452 KB
testcase_35 AC 95 ms
12,240 KB
testcase_36 AC 94 ms
12,236 KB
testcase_37 AC 94 ms
12,184 KB
testcase_38 AC 95 ms
12,172 KB
testcase_39 AC 95 ms
12,144 KB
testcase_40 AC 95 ms
12,140 KB
testcase_41 AC 94 ms
12,176 KB
testcase_42 AC 94 ms
12,144 KB
testcase_43 AC 97 ms
12,200 KB
testcase_44 AC 4 ms
9,536 KB
testcase_45 AC 4 ms
9,500 KB
testcase_46 AC 104 ms
12,156 KB
testcase_47 AC 103 ms
12,464 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 << 19;
  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