結果

問題 No.704 ゴミ拾い Medium
ユーザー chocoruskchocorusk
提出日時 2018-11-09 10:36:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 465 ms / 1,500 ms
コード長 1,347 bytes
コンパイル時間 765 ms
コンパイル使用メモリ 93,368 KB
実行使用メモリ 27,028 KB
最終ジャッジ日時 2023-08-13 10:47:20
合計ジャッジ時間 12,656 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,504 KB
testcase_01 AC 3 ms
9,540 KB
testcase_02 AC 3 ms
9,512 KB
testcase_03 AC 3 ms
9,520 KB
testcase_04 AC 3 ms
9,464 KB
testcase_05 AC 3 ms
9,488 KB
testcase_06 AC 3 ms
9,616 KB
testcase_07 AC 3 ms
9,576 KB
testcase_08 AC 3 ms
9,756 KB
testcase_09 AC 3 ms
9,616 KB
testcase_10 AC 3 ms
9,528 KB
testcase_11 AC 3 ms
9,488 KB
testcase_12 AC 3 ms
9,468 KB
testcase_13 AC 3 ms
9,564 KB
testcase_14 AC 4 ms
9,520 KB
testcase_15 AC 4 ms
9,496 KB
testcase_16 AC 4 ms
9,640 KB
testcase_17 AC 4 ms
9,568 KB
testcase_18 AC 4 ms
9,780 KB
testcase_19 AC 4 ms
9,648 KB
testcase_20 AC 4 ms
9,648 KB
testcase_21 AC 4 ms
9,532 KB
testcase_22 AC 4 ms
9,584 KB
testcase_23 AC 4 ms
9,540 KB
testcase_24 AC 413 ms
26,896 KB
testcase_25 AC 418 ms
27,028 KB
testcase_26 AC 419 ms
26,756 KB
testcase_27 AC 412 ms
26,828 KB
testcase_28 AC 412 ms
26,780 KB
testcase_29 AC 411 ms
26,720 KB
testcase_30 AC 418 ms
26,880 KB
testcase_31 AC 416 ms
27,004 KB
testcase_32 AC 425 ms
26,820 KB
testcase_33 AC 424 ms
26,836 KB
testcase_34 AC 380 ms
26,760 KB
testcase_35 AC 378 ms
26,740 KB
testcase_36 AC 399 ms
26,736 KB
testcase_37 AC 375 ms
26,880 KB
testcase_38 AC 465 ms
26,800 KB
testcase_39 AC 400 ms
26,756 KB
testcase_40 AC 374 ms
26,884 KB
testcase_41 AC 374 ms
26,740 KB
testcase_42 AC 367 ms
26,876 KB
testcase_43 AC 368 ms
26,732 KB
testcase_44 AC 3 ms
9,520 KB
testcase_45 AC 3 ms
9,556 KB
testcase_46 AC 441 ms
26,736 KB
testcase_47 AC 422 ms
26,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const int MAX_N=1<<19;
const ll INF=1e16;
int m;
ll dat[2][2*MAX_N-1];
 
void init(int m_){
	m=1;
	while(m<m_) m*=2;
	for(int i=0; i<2*m-1; i++){
		dat[0][i]=INF;
		dat[1][i]=INF;
	}
}
 
void update(int t, int k, ll a){
	k+=m-1;
	dat[t][k]=a;
	while(k>0){
		k=(k-1)/2;
		dat[t][k]=min(dat[t][k*2+1], dat[t][k*2+2]);
	}
}

ll query(int t, int a, int b, int k, int l, int r){
	if(r<=a || b<=l) return INF;
	if(a<=l && r<=b){
		return dat[t][k];
	}else{
		ll vl=query(t, a, b, k*2+1, l, (l+r)/2);
		ll vr=query(t, a, b, k*2+2, (l+r)/2, r);
		return min(vl, vr);
	}
}

int main()
{
	int n;
	cin>>n;
	ll a[300001], x[300001], y[300001];
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=n; i++) cin>>x[i];
	for(int i=1; i<=n; i++) cin>>y[i];
	ll dp=0;
	int i0=1;
	init(n+1);
	for(int i=1; i<=n; i++){
		while(x[i0]<a[i] && i0<=n) i0++;
		update(0, i, y[i]-x[i]+dp);
		update(1, i, y[i]+x[i]+dp);
		dp=min(a[i]+query(0, 0, i0, 0, 0, m), -a[i]+query(1, i0, n+1, 0, 0, m));
	}
	cout<<dp<<endl;
	return 0;
}
0