結果
| 問題 |
No.777 再帰的ケーキ
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2019-01-02 14:14:07 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,846 bytes |
| コンパイル時間 | 1,252 ms |
| コンパイル使用メモリ | 93,448 KB |
| 実行使用メモリ | 39,204 KB |
| 最終ジャッジ日時 | 2024-11-19 06:31:47 |
| 合計ジャッジ時間 | 8,330 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 3 |
| other | AC * 13 WA * 20 |
ソースコード
#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;
}
horiesiniti