結果

問題 No.777 再帰的ケーキ
ユーザー 👑 horiesinitihoriesiniti
提出日時 2019-01-02 15:01:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,026 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 93,024 KB
実行使用メモリ 31,204 KB
最終ジャッジ日時 2023-08-12 10:35:40
合計ジャッジ時間 8,539 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
4,384 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 4 ms
4,384 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 129 ms
10,040 KB
testcase_34 AC 193 ms
10,024 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<<5);
const int g2=(1<<4)-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<n;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{
			for(int j=i-1;j>=oldP;j--){
				E e2=vec[j];
				long long int c=search(0,0,e2.y-1,0,g2,now1)+e2.c;
				update(c,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