結果

問題 No.704 ゴミ拾い Medium
ユーザー ikdikd
提出日時 2018-07-02 17:55:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,318 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 77,816 KB
実行使用メモリ 12,116 KB
最終ジャッジ日時 2023-09-13 16:58:31
合計ジャッジ時間 9,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 325 ms
11,640 KB
testcase_25 AC 343 ms
11,600 KB
testcase_26 AC 330 ms
11,984 KB
testcase_27 WA -
testcase_28 AC 336 ms
11,604 KB
testcase_29 AC 322 ms
12,032 KB
testcase_30 AC 332 ms
12,000 KB
testcase_31 WA -
testcase_32 AC 325 ms
11,696 KB
testcase_33 AC 330 ms
11,652 KB
testcase_34 AC 282 ms
11,632 KB
testcase_35 AC 282 ms
11,700 KB
testcase_36 AC 282 ms
11,688 KB
testcase_37 AC 284 ms
11,700 KB
testcase_38 AC 282 ms
12,116 KB
testcase_39 AC 282 ms
11,600 KB
testcase_40 AC 282 ms
11,960 KB
testcase_41 AC 282 ms
11,640 KB
testcase_42 AC 282 ms
11,604 KB
testcase_43 AC 282 ms
12,012 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 348 ms
12,024 KB
testcase_47 AC 336 ms
11,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

struct SegmentTree{
  int n=1, inf=1e8;
  vector<int> dat;
  SegmentTree(int m){
    while(n<m) n*=2;
    dat.resize(n*2-1, inf);
  }
  void update(int i, int x){
    i+=n-1;
    dat[i]=x;
    while(i>0){
      i=(i-1)/2;
      dat[i]=min(dat[i*2+1], dat[i*2+2]);
    }
  }
  int getmin(int ql, int qr){
    return getmin(ql, qr, 0, 0, n);
  }
  int getmin(int ql, int qr, int i, int il, int ir){
    if(qr<=il || ir<=ql) return inf;
    if(ql<=il && ir<=qr) return dat[i];
    int m=(ir+il)/2;
    int vl=getmin(ql, qr, i*2+1, il, m),
        vr=getmin(ql, qr, i*2+2, m, ir);
    return min(vl, vr);
  }
};

void chmin(int &l, int r){if(l>r)l=r;}

int main(){

  int n; cin>> n;
  vector<int> a(n+1);
  rep(i, n) cin>> a[i+1];
  vector<int> x(n+1);
  rep(i, n) cin>> x[i+1];
  vector<int> y(n+1);
  rep(i, n) cin>> y[i+1];

  const int inf=1e8;
  SegmentTree segt(n);

  vector<int> dp(n+1, inf);
  dp[0]=0;
  for(int i=1, j=1; i<=n; i++){
    segt.update(i-1, x[i]+y[i]+dp[i-1]);
    while(j<=i && x[j]<=a[i]){
      segt.update(j-1, -x[j]+y[j]+dp[j-1]);
      j++;
    }
    chmin(dp[i], segt.getmin(0, j)+a[i]);
    chmin(dp[i], segt.getmin(j, i)-a[i]);
  }
  cout<< dp[n]<< endl;

  return 0;
}
0