結果

問題 No.860 買い物
ユーザー Jumbo_kprJumbo_kpr
提出日時 2019-08-09 22:40:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,175 bytes
コンパイル時間 860 ms
コンパイル使用メモリ 99,600 KB
実行使用メモリ 7,912 KB
最終ジャッジ日時 2023-09-26 20:54:54
合計ジャッジ時間 2,667 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
//#define int unsigned long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;
const int MAX_N = 1 << 17;
int n;
int dat[2 * MAX_N - 1];//セグ木を持つグローバル配列

//初期化
void init(int n_) {
	n = 1;
	//簡単のため、要素数を2のべき乗に
	while (n < n_)n *= 2;
	//gcdに影響を与えない値で初期化する
	for (int i = 0; i < 2 * n - 1; i++)dat[i] = INF;
}

//k番目の値(0-indexed)をaに更新
void update(int k, int a) {
	k += n - 1;//葉の節点
	dat[k] = a;
	//上りながら更新
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}

//[a,b)のgcdを求める
//そとからは、(a,b,0,0,n)として呼ぶ
int query(int a, int b, int k, int l, int r) {
	//[a,b)と[l,r)が交差していなければ、gcdに影響を与えない値を返す
	//関数定義でgcdの単位元を0としている
	if (r <= a || b <= l)return INF;
	//[a,b)が[l,r)を完全に含んでいれば、この節点の値
	if (a <= l && r <= b)return dat[k];
	//そうでなければ、二つの子のgcd
	else {
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}

int N;
int C[100010], D[100010];
vector<int>top;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	init(N);
	REP(i, N) {
		cin >> C[i] >> D[i];
		update(i, C[i]);
	}
	top.pb(0);
	int l = 0;
	int ans = 0;
	FOR(i, 1, N) {
		int leftmin = query(l, i, 0, 0, n);
		if (D[i] + min(leftmin, C[i]) > leftmin + C[i]) {
			top.pb(i);
			l = i;
		}
	}
	top.pb(N);
	REP(i, top.size()-1) {
		pe(top[i]);
		FOR(j, top[i], top[i + 1]) {
			ans += C[j] + D[j];
		}
		ans -= D[top[i]];
		ans += query(top[i], top[i + 1], 0, 0, n);
	}cout << endl;
	print(ans);
}

0