結果

問題 No.777 再帰的ケーキ
ユーザー 👑 horiesinitihoriesiniti
提出日時 2019-01-02 14:14:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,846 bytes
コンパイル時間 1,289 ms
コンパイル使用メモリ 92,492 KB
実行使用メモリ 39,220 KB
最終ジャッジ日時 2023-08-12 07:37:29
合計ジャッジ時間 8,647 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,556 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 4 ms
11,472 KB
testcase_05 AC 4 ms
11,556 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 4 ms
11,464 KB
testcase_09 WA -
testcase_10 AC 4 ms
11,616 KB
testcase_11 WA -
testcase_12 AC 4 ms
11,592 KB
testcase_13 AC 4 ms
11,608 KB
testcase_14 WA -
testcase_15 AC 4 ms
11,544 KB
testcase_16 AC 4 ms
11,672 KB
testcase_17 AC 4 ms
11,684 KB
testcase_18 AC 5 ms
11,548 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 6 ms
11,748 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 7 ms
11,712 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 233 ms
16,860 KB
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

const int g=(1<<19);
const int g2=(1<<18)-1;
long long int st[2][g];
int now1=0;
int next1=1;

struct E{
	long long int x ,y,c;
	bool operator<(const E& e1)const{
		if (x!=e1.x)return x<e1.x;
		if (y!=e1.y)return y<e1.y;
		return c<e1.c;
	}
};

long long int search(int p,int l1,int r1,int l2,int r2){
	if(r1<l2)return 0;
	if(r2<l1)return 0;
	if(l2==r2)return st[now1][p];
	if(l1<=l2 && r2<=r1)return st[now1][p];
	int m=(l2+r2)/2;
	long long int t2=max (search(p*2+1,l1,r1,l2,m),search(p*2+2,l1,r1,(m+1),r2));
	return t2;
}

void update(long long int c ,int p,int l1,int r1,int l2,int r2,int mode){
	if(r1<l2)return;
	if(r2<l1)return;
	if(l2==r2){
		st[mode][p]=max(st[mode][p],c);
		return ;
	}
	if(l1<=l2 && r2<=r1){
		st[mode][p]=max(st[mode][p],c);
		return ;
	}
	int m=(l2+r2)/2;
	st[mode][p]=max(st[mode][p],c);
	update(c,p*2+1,l1,r1,l2,m,mode);
	update(c,p*2+2,l1,r1,m+1,r2,mode);
	return;
}

int main() {
	// your code goes here
	set<long long int> s1;
	map<long long int,long long int> ms;
	vector<E> vec;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		E e1;
		cin>>e1.x>>e1.y>>e1.c;
		vec.push_back(e1);
		s1.insert(e1.y);
	}
	std::sort(vec.begin(),vec.end());
	memset(st,0,sizeof(st));
	int p=1;
	for(set<long long int>::iterator it=s1.begin();it!=s1.end();it++){
		ms[(*it)]=p;
		p++;
	}
	int x=vec[0].x;
	int oldP=0;
	for(int i=0;i<n;i++){
		E e1=vec[i];
		e1.y=ms[e1.y];
		if(x==e1.x){
			long long int c=search(0,0,e1.y-1,0,g2)+e1.c;
			update(c,0,e1.y,e1.y,0,g2,next1);
		}else{
			for(int j=oldP;j<i;j++){
				E e2=vec[j];
				long long int c=search(0,0,e2.y-1,0,g2)+e2.c;
				update(c,0,e2.y,e2.y,0,g2,now1);
			}
			oldP=i;
			i--;
			x=e1.x;
		}
	}
	cout<<max(st[0][0],st[1][0])<<"\n";
	return 0;
}
0