結果

問題 No.1826 Fruits Collecting
ユーザー kwm_t
提出日時 2022-02-03 00:11:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,800 bytes
コンパイル時間 5,225 ms
コンパイル使用メモリ 262,320 KB
最終ジャッジ日時 2025-01-27 18:25:49
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /usr/include/c++/13/cassert:44,
                 from /usr/include/atcoder/segtree.hpp:5,
                 from /usr/include/atcoder/segtree:1,
                 from /usr/include/atcoder/all:10,
                 from main.cpp:2:
In member function ‘void atcoder::segtree<S, op, e>::set(int, S) [with S = long long int; auto op = op; auto e = e]’,
    inlined from ‘int main()’ at main.cpp:44:9:
/usr/include/atcoder/segtree.hpp:41:9: warning: ‘pos0’ may be used uninitialized [-Wmaybe-uninitialized]
   41 |         assert(0 <= p && p < _n);
      |         ^~~~~~
main.cpp: In function ‘int main()’:
main.cpp:33:17: note: ‘pos0’ was declared here
   33 |         int sz, pos0;
      |                 ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<long long,long long>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
long long op(long long a, long long b) { return max(a, b); }
long long e() { return -LINF; }
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<pair<P, long long>>vec;
	vec.push_back({ {0 - 0,0 + 0},0 });
	rep(i, n) {
		int t, x, v; cin >> t >> x >> v;
		if (t - x >= 0)vec.push_back({ {t - x,t + x},v });
	}
	int sz, pos0;
	{
		vector<long long>tmp(vec.size());
		rep(i, vec.size())tmp[i] = vec[i].first.second;
		sort(all(tmp));
		tmp.erase(unique(all(tmp)), tmp.end());
		sz = tmp.size();
		rep(i, vec.size()) vec[i].first.second = lower_bound(all(tmp), vec[i].first.second) - tmp.begin();
		rep(i, tmp.size())if (0 == tmp[i])pos0 = i;
	}
	segtree<long long, op, e>seg(sz);
	seg.set(pos0, 0);
	sort(all(vec));
	rep(i, vec.size()) {
		int idx = vec[i].first.second;
		long long get = seg.prod(0, idx + 1);
		if (-LINF == get)continue;
		seg.set(idx, get + vec[i].second);
	}
	cout << seg.all_prod() << endl;
	return 0;
}
0