結果

問題 No.704 ゴミ拾い Medium
ユーザー nxterunxteru
提出日時 2018-11-10 22:01:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 1,500 ms
コード長 959 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 167,728 KB
実行使用メモリ 29,504 KB
最終ジャッジ日時 2023-08-16 15:22:51
合計ジャッジ時間 9,013 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
28,128 KB
testcase_01 AC 8 ms
28,016 KB
testcase_02 AC 8 ms
28,132 KB
testcase_03 AC 9 ms
28,016 KB
testcase_04 AC 8 ms
28,140 KB
testcase_05 AC 8 ms
28,064 KB
testcase_06 AC 8 ms
28,124 KB
testcase_07 AC 8 ms
28,084 KB
testcase_08 AC 9 ms
28,016 KB
testcase_09 AC 8 ms
28,324 KB
testcase_10 AC 8 ms
28,124 KB
testcase_11 AC 8 ms
28,308 KB
testcase_12 AC 9 ms
28,064 KB
testcase_13 AC 9 ms
28,068 KB
testcase_14 AC 9 ms
28,080 KB
testcase_15 AC 9 ms
28,136 KB
testcase_16 AC 9 ms
28,132 KB
testcase_17 AC 9 ms
28,120 KB
testcase_18 AC 9 ms
28,184 KB
testcase_19 AC 9 ms
28,060 KB
testcase_20 AC 9 ms
28,064 KB
testcase_21 AC 9 ms
28,056 KB
testcase_22 AC 9 ms
28,076 KB
testcase_23 AC 10 ms
28,164 KB
testcase_24 AC 191 ms
29,244 KB
testcase_25 AC 231 ms
29,504 KB
testcase_26 AC 208 ms
29,256 KB
testcase_27 AC 202 ms
29,200 KB
testcase_28 AC 218 ms
29,224 KB
testcase_29 AC 191 ms
29,244 KB
testcase_30 AC 204 ms
29,368 KB
testcase_31 AC 220 ms
29,244 KB
testcase_32 AC 197 ms
29,176 KB
testcase_33 AC 206 ms
29,244 KB
testcase_34 AC 192 ms
29,200 KB
testcase_35 AC 187 ms
29,448 KB
testcase_36 AC 193 ms
29,296 KB
testcase_37 AC 194 ms
29,272 KB
testcase_38 AC 190 ms
29,260 KB
testcase_39 AC 191 ms
29,332 KB
testcase_40 AC 191 ms
29,204 KB
testcase_41 AC 192 ms
29,180 KB
testcase_42 AC 186 ms
29,444 KB
testcase_43 AC 188 ms
29,240 KB
testcase_44 AC 8 ms
28,016 KB
testcase_45 AC 9 ms
28,252 KB
testcase_46 AC 214 ms
29,260 KB
testcase_47 AC 225 ms
29,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 100000000000000000
struct SEG{
	ll seg[1<<20];
	SEG(void){
		for(int i=0;i<1<<20;i++)seg[i]=INF;
	}
	void up(int a,ll x){
		a+=(1<<19)-1;
		seg[a]=x;
		while(a>0){
			a=(a-1)/2;
			seg[a]=min(seg[a*2+1],seg[a*2+2]);
		}
	}
	ll que(int a,int b,int l,int r,int k){
		if(b<l||r<a)return INF;
		if(a<=l&&r<=b)return seg[k];
		return min(que(a,b,l,(l+r-1)/2,k*2+1),que(a,b,(l+r+1)/2,r,k*2+2));
	}
};
ll n,x[300005],y[300005],a[300005],dp[300005];
SEG m,p;
int main(void){
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)scanf("%lld",a+i);
    for(int i=1;i<=n;i++)scanf("%lld",x+i);
    for(int i=1;i<=n;i++)scanf("%lld",y+i);
    for(int i=1;i<=n;i++){
		m.up(i,dp[i-1]-x[i]+y[i]);
		p.up(i,dp[i-1]+x[i]+y[i]);
		int o=lower_bound(x,x+n+1,a[i])-x;
		dp[i]=m.que(1,min(i,o-1),0,(1<<19)-1,0)+a[i];
		if(o<=i)dp[i]=min(dp[i],p.que(o,i,0,(1<<19)-1,0)-a[i]);
	}
	printf("%lld\n",dp[n]);
}
0