結果

問題 No.1826 Fruits Collecting
ユーザー t_mkt_mk
提出日時 2022-03-17 18:22:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,589 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 188,228 KB
実行使用メモリ 46,376 KB
最終ジャッジ日時 2024-04-09 03:23:56
合計ジャッジ時間 19,484 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 6 ms
19,576 KB
testcase_26 AC 7 ms
19,648 KB
testcase_27 AC 7 ms
19,568 KB
testcase_28 AC 7 ms
19,724 KB
testcase_29 AC 6 ms
19,560 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 6 ms
19,728 KB
testcase_44 AC 7 ms
19,584 KB
testcase_45 AC 7 ms
19,560 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<double,double,int>;
ll INF = 1LL << 60;
int LEN = 1 << 20;
vector<ll> seg(2*LEN,0);
void add(int ind,int 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+1);
  dp[0] = 0;
  for(int i = 1;i <= n;i++){
    int x,y,v;
    tie(x,y,v) = items[i-1];
    if(x < 0 || y < 0)continue;
    dp[i] = maxim(0,y+1) + v;
    add(y,dp[i]);
  }
  ll ans = 0;
  rep(i,n+1){
    ans = max<ll>(ans,dp[i]);
  }
  cout << ans << endl;
}
0