結果

問題 No.1826 Fruits Collecting
ユーザー kwm_tkwm_t
提出日時 2022-02-03 00:11:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,800 bytes
コンパイル時間 5,859 ms
コンパイル使用メモリ 269,708 KB
実行使用メモリ 13,316 KB
最終ジャッジ日時 2023-09-02 03:02:27
合計ジャッジ時間 9,582 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 53 ms
5,944 KB
testcase_06 AC 89 ms
8,280 KB
testcase_07 AC 62 ms
7,244 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 91 ms
8,124 KB
testcase_10 AC 61 ms
8,492 KB
testcase_11 AC 57 ms
6,156 KB
testcase_12 AC 24 ms
4,536 KB
testcase_13 AC 12 ms
4,376 KB
testcase_14 AC 19 ms
4,376 KB
testcase_15 AC 140 ms
12,716 KB
testcase_16 AC 140 ms
12,784 KB
testcase_17 AC 140 ms
12,432 KB
testcase_18 AC 136 ms
13,316 KB
testcase_19 AC 140 ms
12,328 KB
testcase_20 AC 136 ms
12,520 KB
testcase_21 AC 144 ms
13,192 KB
testcase_22 AC 146 ms
11,816 KB
testcase_23 AC 140 ms
12,004 KB
testcase_24 AC 136 ms
12,324 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 21 ms
4,376 KB
testcase_31 AC 40 ms
4,604 KB
testcase_32 AC 35 ms
5,648 KB
testcase_33 AC 117 ms
12,108 KB
testcase_34 AC 95 ms
8,756 KB
testcase_35 AC 22 ms
4,532 KB
testcase_36 AC 114 ms
11,556 KB
testcase_37 AC 79 ms
8,572 KB
testcase_38 AC 58 ms
7,692 KB
testcase_39 AC 76 ms
10,112 KB
testcase_40 AC 95 ms
11,032 KB
testcase_41 AC 21 ms
4,704 KB
testcase_42 AC 4 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/include/atcoder/segtree:1,
         次から読み込み:  /usr/include/atcoder/all:10,
         次から読み込み:  main.cpp:2:
メンバ関数 ‘void atcoder::segtree<S, op, e>::set(int, S) [with S = long long int; S (* op)(S, S) = op; S (* e)() = e]’ 内,
    inlined from ‘int main()’ at main.cpp:44:9:
/usr/include/atcoder/segtree.hpp:28:11: 警告: ‘pos0’ may be used uninitialized [-Wmaybe-uninitialized]
   28 |         p += size;
      |         ~~^~~~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:33:17: 備考: ‘pos0’ はここで定義されています
   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