結果

問題 No.704 ゴミ拾い Medium
ユーザー azbrugbyazbrugby
提出日時 2019-03-16 19:31:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 130 ms / 1,500 ms
コード長 1,684 bytes
コンパイル時間 576 ms
コンパイル使用メモリ 75,620 KB
実行使用メモリ 17,580 KB
最終ジャッジ日時 2023-09-14 15:26:49
合計ジャッジ時間 6,067 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
13,608 KB
testcase_01 AC 5 ms
13,720 KB
testcase_02 AC 4 ms
13,692 KB
testcase_03 AC 4 ms
13,612 KB
testcase_04 AC 4 ms
13,636 KB
testcase_05 AC 4 ms
13,608 KB
testcase_06 AC 4 ms
13,728 KB
testcase_07 AC 5 ms
13,656 KB
testcase_08 AC 4 ms
13,692 KB
testcase_09 AC 4 ms
13,680 KB
testcase_10 AC 4 ms
13,716 KB
testcase_11 AC 4 ms
13,652 KB
testcase_12 AC 5 ms
13,632 KB
testcase_13 AC 4 ms
13,612 KB
testcase_14 AC 5 ms
13,620 KB
testcase_15 AC 5 ms
13,616 KB
testcase_16 AC 5 ms
13,644 KB
testcase_17 AC 4 ms
13,664 KB
testcase_18 AC 5 ms
13,636 KB
testcase_19 AC 4 ms
13,640 KB
testcase_20 AC 5 ms
13,736 KB
testcase_21 AC 5 ms
13,716 KB
testcase_22 AC 4 ms
13,640 KB
testcase_23 AC 5 ms
13,664 KB
testcase_24 AC 120 ms
17,468 KB
testcase_25 AC 130 ms
17,452 KB
testcase_26 AC 125 ms
17,452 KB
testcase_27 AC 123 ms
17,508 KB
testcase_28 AC 127 ms
17,472 KB
testcase_29 AC 120 ms
17,512 KB
testcase_30 AC 125 ms
17,428 KB
testcase_31 AC 127 ms
17,500 KB
testcase_32 AC 122 ms
17,580 KB
testcase_33 AC 124 ms
17,500 KB
testcase_34 AC 112 ms
17,452 KB
testcase_35 AC 111 ms
17,472 KB
testcase_36 AC 111 ms
17,464 KB
testcase_37 AC 111 ms
17,548 KB
testcase_38 AC 111 ms
17,432 KB
testcase_39 AC 111 ms
17,464 KB
testcase_40 AC 112 ms
17,548 KB
testcase_41 AC 112 ms
17,432 KB
testcase_42 AC 111 ms
17,420 KB
testcase_43 AC 111 ms
17,452 KB
testcase_44 AC 5 ms
13,608 KB
testcase_45 AC 5 ms
13,628 KB
testcase_46 AC 127 ms
17,436 KB
testcase_47 AC 125 ms
17,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <cstdio>
#include <cmath>
#include <bitset>
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;

const ll MOD = 1234567, N = 300010, dx[4] = { -1,1,0,0 }, dy[4] = { 0,0,-1,1 }, MIN = -72340172838, MAX = 72340172838;
const int S = 60;
ll mn(ll a, ll b) {
	if (a == -1)return b;
	if (b == -1)return a;
	return min(a, b);
}
static ll gcd(ll v1, ll v2) {
	if (v1 == 0)return v2; if (v2 == 0)return v1; if (v2 > v1)return gcd(v2%v1, v1); return gcd(v1%v2, v2);
}

ll pw(ll v1, ll v2) {
	ll v3 = 1;
	while (v2 > 0) {
		if (v2 % 2)v3 = (v3*v1) % MOD;
		v1 = (v1*v1) % MOD;
		v2 /= 2;
	}
	return v3;
}

ll n, a[N], dp[N],bt1[N],bt2[N],x[N],y[N];

void ad(ll v1, ll v2,ll bt[]) {
	while (v1 < N) {
		bt[v1] = min(bt[v1],v2);
		v1 += v1 & -v1;
	}
}

ll sm(ll v1,ll bt[]) {
	ll v2 = MAX;
	while (v1 > 0) {
		v2 =min(bt[v1],v2);
		v1 -= v1 & -v1;
	}
	return v2;
}

#define scanf_s scanf
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++)scanf_s("%d", a + i);
	for (int i = 1; i <= n; i++)scanf_s("%d", x + i);
	for (int i = 1; i <= n; i++)scanf_s("%d", y + i);
	for (int i = 1; i < N; i++)bt1[i] = bt2[i] = MAX;
	for (int i = 1; i <= n; i++) {
		ll xi = upper_bound(x + 1, x + i + 1, a[i]) - x - 1;
		ad(i, dp[i - 1] - x[i] + y[i], bt1);
		ad(n + 1 - i, dp[i - 1] + x[i] + y[i], bt2);
		dp[i] = MAX;
		ll v1 = sm(xi, bt1), v2 = sm(n + 1 - (xi + 1), bt2);
		dp[i] = mn(dp[i], a[i] + v1);
		dp[i] = mn(dp[i], v2 - a[i]);
	}
	cout << dp[n] << endl;


	return 0;
}
0