結果

問題 No.704 ゴミ拾い Medium
ユーザー ats5515ats5515
提出日時 2018-06-15 23:26:20
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,925 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 110,820 KB
実行使用メモリ 23,716 KB
最終ジャッジ日時 2023-09-13 05:21:48
合計ジャッジ時間 9,195 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,508 KB
testcase_01 AC 2 ms
5,516 KB
testcase_02 AC 2 ms
5,504 KB
testcase_03 AC 2 ms
5,508 KB
testcase_04 AC 2 ms
5,516 KB
testcase_05 AC 2 ms
5,516 KB
testcase_06 AC 2 ms
5,460 KB
testcase_07 AC 2 ms
5,568 KB
testcase_08 AC 2 ms
5,512 KB
testcase_09 AC 2 ms
5,460 KB
testcase_10 AC 2 ms
5,504 KB
testcase_11 AC 2 ms
5,500 KB
testcase_12 AC 2 ms
5,452 KB
testcase_13 AC 2 ms
5,588 KB
testcase_14 AC 2 ms
5,740 KB
testcase_15 AC 2 ms
5,704 KB
testcase_16 AC 3 ms
5,524 KB
testcase_17 AC 3 ms
5,624 KB
testcase_18 AC 2 ms
5,568 KB
testcase_19 AC 3 ms
5,500 KB
testcase_20 AC 2 ms
5,520 KB
testcase_21 AC 2 ms
5,656 KB
testcase_22 AC 2 ms
5,512 KB
testcase_23 AC 3 ms
5,508 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 AC 2 ms
5,588 KB
testcase_45 AC 2 ms
5,456 KB
testcase_46 RE -
testcase_47 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <utility>
using namespace std;
#define int long long
int MOD = 1000000007;
template<typename T>

struct segtree {
	const int inf = (int)1 << 60;
	int N;
	int dat[700000];
	segtree() {}
	segtree(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = inf;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return inf;
		if (a <= l and r <= b) return dat[k];
		int m = (l + r) / 2;
		return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> X(N);
	vector<int> Y(N);
	vector<int> dp(N + 1, 0);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i]++;
	}
	for (int i = 0; i < N; i++) {
		cin >> X[i];
		X[i]++;
	}
	for (int i = 0; i < N; i++) {
		cin >> Y[i];
		//Y[i]++;
	}
	segtree<int> sg1(N);
	segtree<int> sg2(N);
	dp[0] = 0;
	
	sg1.update(0, dp[0] - X[0] + Y[0]);
	sg2.update(0, dp[0] + X[0] + Y[0]);
	X.push_back(1 << 30);
	//sg1.update()
	for (int i = 1; i <= N; i++) {
		int t = lower_bound(X.begin(), X.end(), A[i - 1]) - X.begin();
		int a;
		if (i <= t) {
			a = sg1.query(0, i) + A[i - 1];
		}
		else {
			a = sg1.query(0, t) + A[i - 1];
			a = min(a, sg2.query(t, i) - A[i - 1]);
		}
		dp[i] = a;
		if (i < N) {
			sg1.update(i, dp[i] - X[i] + Y[i]);
			sg2.update(i, dp[i] + X[i] + Y[i]);
		}
	}
	cout << dp[N] << endl;
}
0