結果

問題 No.777 再帰的ケーキ
ユーザー 👑 horiesinitihoriesiniti
提出日時 2019-01-02 15:12:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 686 ms / 2,000 ms
コード長 2,139 bytes
コンパイル時間 1,247 ms
コンパイル使用メモリ 94,932 KB
実行使用メモリ 39,076 KB
最終ジャッジ日時 2023-08-12 12:19:56
合計ジャッジ時間 7,917 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,656 KB
testcase_01 AC 4 ms
11,568 KB
testcase_02 AC 4 ms
11,568 KB
testcase_03 AC 4 ms
11,584 KB
testcase_04 AC 3 ms
11,600 KB
testcase_05 AC 4 ms
11,604 KB
testcase_06 AC 5 ms
11,576 KB
testcase_07 AC 4 ms
11,592 KB
testcase_08 AC 4 ms
11,704 KB
testcase_09 AC 3 ms
11,556 KB
testcase_10 AC 5 ms
11,520 KB
testcase_11 AC 3 ms
11,812 KB
testcase_12 AC 3 ms
11,584 KB
testcase_13 AC 3 ms
11,580 KB
testcase_14 AC 4 ms
11,504 KB
testcase_15 AC 4 ms
11,648 KB
testcase_16 AC 4 ms
11,524 KB
testcase_17 AC 4 ms
11,580 KB
testcase_18 AC 4 ms
11,524 KB
testcase_19 AC 4 ms
11,600 KB
testcase_20 AC 4 ms
11,708 KB
testcase_21 AC 8 ms
11,856 KB
testcase_22 AC 7 ms
11,892 KB
testcase_23 AC 6 ms
11,912 KB
testcase_24 AC 5 ms
11,784 KB
testcase_25 AC 9 ms
11,892 KB
testcase_26 AC 9 ms
11,800 KB
testcase_27 AC 7 ms
11,928 KB
testcase_28 AC 650 ms
38,400 KB
testcase_29 AC 647 ms
37,812 KB
testcase_30 AC 686 ms
38,120 KB
testcase_31 AC 671 ms
39,076 KB
testcase_32 AC 455 ms
37,924 KB
testcase_33 AC 147 ms
15,872 KB
testcase_34 AC 216 ms
16,036 KB
testcase_35 AC 531 ms
27,764 KB
testcase_36 AC 470 ms
38,024 KB
権限があれば一括ダウンロードができます

ソースコード

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];
const int now1=0;
const 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,long long int l1,long long int r1,long long int l2,long long int r2,int mode){
	if(r1<l2)return 0;
	if(r2<l1)return 0;
	if(l2==r2)return st[mode][p];
	if(l1<=l2 && r2<=r1)return st[mode][p];
	int m=(l2+r2)/2;
	long long int t2=max (search(p*2+1,l1,r1,l2,m,mode),search(p*2+2,l1,r1,(m+1),r2,mode));
	return t2;
}

void update(long long int c ,int p,long long int l1,long long int r1,long long int l2,long long 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));
	long long int p=1;
	for(set<long long int>::iterator it=s1.begin();it!=s1.end();it++){
		ms[(*it)]=p;
		p++;
	}
	for(int i=0;i<n;i++){
		vec[i].y=ms[vec[i].y];
	}
	long long int x=vec[0].x;
	int oldP=0;
	
	
	
	for(int i=0;i<vec.size();i++){
		E e1=vec[i];
		if(x==e1.x){
			long long int c=search(0,0,e1.y-1,0,g2,now1)+e1.c;
			update(c,0,e1.y,e1.y,0,g2,next1);
		}else{
			vector<long long int> vecC;
			for(int j=oldP;j<i;j++){
				E e2=vec[j];
				vecC.push_back(search(0,0,e2.y-1,0,g2,now1)+e2.c);
			}
			for(int j=0;j<vecC.size();j++){
				E e2=vec[j+oldP];
				update(vecC[j],0,e2.y,e2.y,0,g2,now1);
			}
			oldP=i;
			i--;
			x=e1.x;
		}
	}

	cout<<search(0,0,g2,0,g2,next1)<<"\n";
	return 0;
}
0