結果

問題 No.777 再帰的ケーキ
ユーザー tarakojo1019tarakojo1019
提出日時 2021-01-18 19:12:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,317 bytes
コンパイル時間 4,935 ms
コンパイル使用メモリ 136,668 KB
実行使用メモリ 24,392 KB
最終ジャッジ日時 2023-08-21 02:17:46
合計ジャッジ時間 7,161 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
7,184 KB
testcase_02 AC 4 ms
7,076 KB
testcase_03 WA -
testcase_04 AC 4 ms
7,096 KB
testcase_05 AC 4 ms
7,080 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 4 ms
7,128 KB
testcase_09 AC 4 ms
7,320 KB
testcase_10 AC 4 ms
7,136 KB
testcase_11 AC 4 ms
7,276 KB
testcase_12 AC 4 ms
7,184 KB
testcase_13 AC 4 ms
7,268 KB
testcase_14 AC 4 ms
7,092 KB
testcase_15 AC 4 ms
7,156 KB
testcase_16 AC 4 ms
7,156 KB
testcase_17 AC 4 ms
7,092 KB
testcase_18 AC 4 ms
7,176 KB
testcase_19 WA -
testcase_20 AC 4 ms
7,320 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 5 ms
7,120 KB
testcase_24 AC 4 ms
7,156 KB
testcase_25 AC 6 ms
7,528 KB
testcase_26 AC 6 ms
7,632 KB
testcase_27 AC 5 ms
7,092 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 493 ms
24,168 KB
testcase_31 AC 498 ms
24,188 KB
testcase_32 AC 251 ms
24,156 KB
testcase_33 AC 62 ms
10,528 KB
testcase_34 AC 90 ms
11,892 KB
testcase_35 AC 290 ms
17,884 KB
testcase_36 AC 245 ms
24,152 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve()’ 内:
main.cpp:143:22: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  143 |                 auto [a, b, c] = abc[i];
      |                      ^

ソースコード

diff #

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<numeric>
#include<cstring>
#include<random>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

template<typename T, typename F>
class SegmentTree {
private:
	T e;
	F op;
	ll n;
	vector<T> dat;
public:
	SegmentTree(F f, T _e, vector<T> v) :op(f), e(_e) {
		int _n = v.size();
		n = 1;
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, e);
		REP(i, _n)dat[n + i - 1] = v[i];
		for (int i = n - 2; i >= 0; i--)dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	SegmentTree(F f, T _e, int _n) :op(f), e(_e) {
		n = 1;
		while (n < _n)n *= 2;
		dat.resize(2 * n - 1, e);
		for (int i = n - 2; i >= 0; i--)dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
	}
	void update(int i, T x) {
		i += n - 1;
		dat[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}
	T query(int l, int r) {
		//[l,r)でのクエリ処理
		T left = e, right = e;
		l += n - 1; r += n - 1;
		while (l < r) {
			if ((l & 1) == 0)left = op(left, dat[l]);
			if ((r & 1) == 0)right = op(dat[r - 1], right);
			l = l / 2;
			r = (r - 1) / 2;
		}
		return op(left, right);
	}
};


void solve() {
	ll n;
	cin >> n;
	vec<tuple<ll, ll, ll>> abc(n);
	map<ll, ll> mp;
	REP(i, n) {
		ll a, b, c;
		cin >> a >> b >> c;
		abc[i] = { a,-b,c };
		mp[b]++;
	}
	sort(all(abc));

	ll con = 0;
	for (auto& i : mp) {
		i.second = con;
		con++;
	}

	auto op = [](ll a, ll b) {return max(a, b); };
	SegmentTree<ll, decltype(op)> seg(op, 0, 202020);

	REP(i, n) {
		auto [a, b, c] = abc[i];
		ll m = seg.query(0, mp[-b]);
		if (mp[-b] < m + c)seg.update(mp[-b], m + c);
	}

	cout << seg.query(0, con) << en;

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	solve();
	//ll t;cin>>t;REP(i,t) solve();

	return 0;
}
0