結果

問題 No.777 再帰的ケーキ
ユーザー chocorusk
提出日時 2018-12-24 00:26:40
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 540 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 1,196 ms
コンパイル使用メモリ 96,140 KB
実行使用メモリ 28,468 KB
最終ジャッジ日時 2024-09-25 10:51:38
合計ジャッジ時間 6,402 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> Pi;
ll bit[200001]; int n1;
ll mx[200001];
ll max(int i){
	ll s=0;
	while(i>0){
		s=max(s, bit[i]);
		i-=(i&(-i));
	}
	return s;
}
void update(int i, ll x){
  if(mx[i]>=x) return;
  mx[i]=x;
	while(i<=n1){
		bit[i]=max(bit[i], x);
		i+=(i&(-i));
	}
}
int main()
{
	int n; cin>>n;
  ll a[200000], b[200000], c[200000];
  Pi p[200000];
  for(int i=0; i<n; i++){
    cin>>a[i]>>b[i]>>c[i];
    p[i]=Pi(P(a[i], b[i]), c[i]);
  }
  sort(p, p+n, [](Pi x, Pi y){ if(x.first.first!=y.first.first) return x.first.first<y.first.first; else return x.first.second>y.first.second;});
  map<ll, int> mp;
  for(int i=0; i<n; i++){
    mp[p[i].first.second]=0;
  }
  int m=1;
  for(auto& q:mp){
    q.second=m;
    m++;
  }
  m--;
  n1=m;
  for(int i=0; i<n; i++){
    int t=mp[p[i].first.second];
    update(t, max(t-1)+p[i].second);
  }
  cout<<max(m)<<endl;
	return 0;
}
0