- 魔法气球
请hack以下代码,正反两遍模拟
- @ 2026-3-27 11:03:59
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=5e5+7;
int n,x[N],mx=0;
struct node{
int d;
node *nxt,*pre;
node(){d=-1;pre=nullptr;nxt=nullptr;}
node(int t){d=t;pre=nullptr;nxt=nullptr;}
}*head,*tail,*p;
signed main(){
// freopen("ex.in","r",stdin);
// freopen("ex.ans","w",stdout);
// system("fc ex.out ex.ans");
// return 0;
tail=head=new node;
cin>>n;
for(int i=1;i<=n;i++)cin>>x[i],p=new node(x[i]),tail->nxt=p,p->pre=tail,tail=p;
p=head->nxt;
while(p->nxt!=nullptr){
mx=max(mx,p->d);
if(p!=head&&p->pre->d==p->d){
p=p->pre;
p->d++;
p->nxt=p->nxt->nxt,p->nxt->pre=p;
mx=max(mx,p->d);
continue;
}
p=p->nxt;
}
tail=head=new node;
for(int i=n;i>=1;i--)p=new node(x[i]),tail->nxt=p,p->pre=tail,tail=p;
p=head;
while(p->nxt!=nullptr){
mx=max(mx,p->d);
if(p!=head&&p->pre->d==p->d){
p=p->pre;
p->d++;
p->nxt=p->nxt->nxt,p->nxt->pre=p;
mx=max(mx,p->d);
continue;
}
p=p->nxt;
}
cout<<mx<<'\n';
return 0;
}
2 条评论
-
Null_in_null LV 6 @ 2026-3-27 11:15:45申请添加数据 input: 24 2 1 2 9 8 7 6 6 6 7 8 9 9 8 7 5 5 6 7 8 9 2 1 2 output: 11
-
@ 2026-3-27 11:13:25luogu找到hack
24 2 1 2 9 8 7 6 6 6 7 8 9 9 8 7 5 5 6 7 8 9 2 1 2
- 1
信息
- ID
- 302
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- (无)
- 递交数
- 55
- 已通过
- 15
- 上传者