結果
| 問題 |
No.777 再帰的ケーキ
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2019-01-02 15:01:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,026 bytes |
| コンパイル時間 | 1,146 ms |
| コンパイル使用メモリ | 93,192 KB |
| 実行使用メモリ | 31,064 KB |
| 最終ジャッジ日時 | 2024-11-19 10:53:59 |
| 合計ジャッジ時間 | 7,595 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 WA * 11 |
ソースコード
#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;
}
horiesiniti