結果

問題 No.1826 Fruits Collecting
ユーザー t_mkt_mk
提出日時 2022-03-17 18:30:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 825 ms / 2,000 ms
コード長 1,546 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 187,720 KB
実行使用メモリ 44,032 KB
最終ジャッジ日時 2024-04-09 03:31:04
合計ジャッジ時間 18,126 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
19,740 KB
testcase_01 AC 9 ms
19,692 KB
testcase_02 AC 9 ms
19,916 KB
testcase_03 AC 11 ms
19,980 KB
testcase_04 AC 8 ms
19,692 KB
testcase_05 AC 269 ms
29,320 KB
testcase_06 AC 468 ms
35,696 KB
testcase_07 AC 329 ms
31,024 KB
testcase_08 AC 32 ms
20,924 KB
testcase_09 AC 465 ms
35,664 KB
testcase_10 AC 302 ms
30,704 KB
testcase_11 AC 294 ms
30,160 KB
testcase_12 AC 106 ms
24,084 KB
testcase_13 AC 51 ms
21,932 KB
testcase_14 AC 81 ms
23,036 KB
testcase_15 AC 768 ms
43,904 KB
testcase_16 AC 767 ms
43,772 KB
testcase_17 AC 780 ms
43,904 KB
testcase_18 AC 773 ms
43,772 KB
testcase_19 AC 825 ms
43,900 KB
testcase_20 AC 771 ms
43,776 KB
testcase_21 AC 782 ms
43,772 KB
testcase_22 AC 780 ms
43,904 KB
testcase_23 AC 769 ms
43,904 KB
testcase_24 AC 766 ms
44,032 KB
testcase_25 AC 7 ms
19,748 KB
testcase_26 AC 7 ms
19,752 KB
testcase_27 AC 7 ms
19,724 KB
testcase_28 AC 7 ms
19,744 KB
testcase_29 AC 8 ms
19,640 KB
testcase_30 AC 139 ms
25,020 KB
testcase_31 AC 297 ms
30,436 KB
testcase_32 AC 130 ms
24,772 KB
testcase_33 AC 493 ms
36,120 KB
testcase_34 AC 395 ms
33,836 KB
testcase_35 AC 85 ms
23,252 KB
testcase_36 AC 486 ms
35,832 KB
testcase_37 AC 311 ms
32,852 KB
testcase_38 AC 210 ms
28,888 KB
testcase_39 AC 258 ms
29,676 KB
testcase_40 AC 334 ms
32,292 KB
testcase_41 AC 74 ms
22,416 KB
testcase_42 AC 16 ms
19,968 KB
testcase_43 AC 7 ms
19,720 KB
testcase_44 AC 7 ms
19,720 KB
testcase_45 AC 7 ms
19,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (n);i++)
using ll = long long;
using P =pair<int,int>;
using T = tuple<int,int,int>;
ll INF = 1LL << 60;
int LEN = 1 << 20;
vector<ll> seg(2*LEN,0);
void add(int ind,ll val){
  ind += LEN;
  seg[ind] = max<ll>(val,seg[ind]);
  while(ind > 0){
    ind /= 2;
    seg[ind] = max<ll>(seg[ind*2],seg[ind*2 + 1]);
  }
}
ll maxim(int l,int r){
  l += LEN;
  r += LEN;
  ll ans = 0;
  while(l < r){
    if(l & 1 )ans = max<ll>(ans,seg[l++]);
    l /= 2;
    if(r & 1)ans = max<ll>(ans,seg[--r]);
    r /= 2;
  }
  return ans;
}
int main(){
  int n;
  cin >> n;
  vector<T> items(n);
  vector<int> X,Y;
  rep(i,n){
    int t,x,v;
    cin >> t >> x >> v;
    int x2 = (t-x);
    int y2 = (t+x);
    X.push_back(x2);
    Y.push_back(y2);
    items[i] = make_tuple(x2,y2,v);
  }
  sort(X.begin(),X.end());
  sort(Y.begin(),Y.end());
  map<int,int> mpX,mpY;
  rep(i,n){
    mpX[X[i]] = lower_bound(X.begin(),X.end(),X[i]) - X.begin() + 1;
    mpY[Y[i]] = lower_bound(Y.begin(),Y.end(),Y[i]) - Y.begin() + 1;
    if(X[i] < 0)mpX[X[i]] = -1;
    if(Y[i] < 0)mpY[Y[i]] = -1;
  }
  rep(i,n){
    int x,y,v;
    tie(x,y,v) = items[i];
    x = mpX[x];
    y = mpY[y];
    items[i] = make_tuple(x,y,v);
  }
  sort(items.begin(),items.end());
  vector<ll> dp(n);
  rep(i,n){
    int x,y,v;
    tie(x,y,v) = items[i];
    if(x < 0 || y < 0)continue;
    dp[i] = maxim(0,y+1) + v;
    add(y,dp[i]);
  }
  ll ans = 0;
  rep(i,n){
    ans = max<ll>(ans,dp[i]);
  }
  cout << ans << endl;
}
0