社区讨论
30分求助
P7912[CSP-J 2021] 小熊的果篮参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lo175cme
- 此快照首次捕获于
- 2023/10/22 16:18 2 年前
- 此快照最后确认于
- 2023/11/02 15:56 2 年前
TLE + WA :
CPP#include<bits/stdc++.h>
using namespace std;
int n,L=1;
bool book[2*100000+10];
struct fruit{
int st,len,lx;
bool pj;
int Pid,Pst;
};
int main(){
scanf("%d",&n);
memset(book,1,sizeof(book));
int *a=new int[n+10];
fruit *f=new fruit[n+10];
f[L].st=1,f[L].len=1;
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
if(i==1){f[L].lx=a[i];}
else{
if(a[i]==a[i-1]){
f[L].len++;
}
else{
L++;
f[L].st=i;
f[L].lx=a[i];
f[L].len=1;
}
}
}
bool flag=1;
while(flag){
flag=0;
bool u=1;
int tmp=0;
f[0].lx=-1;
for(int i=1;i<=L;i++){
if(f[i].len!=0){
if(i==1){
tmp=1;
flag=1;
if(f[i].pj){
if(f[i].st>f[i].Pst){
printf("%d ",f[i].Pid+f[i].st-f[i].Pst-1);
}
else{
printf("%d ",f[i].st);
}continue;
}
printf("%d ",f[i].st++);
f[i].len--;
}
else{
if(f[i].lx!=f[tmp].lx){
if(u){
u=0;
flag=1;
tmp=i;
f[i].len--;
}
else{
tmp=i;
f[i].len--;
}
}
else{
f[tmp].len+=f[i].len;
f[i].len=0;
f[tmp].pj=1;
f[tmp].Pid=f[i].st;
f[tmp].Pst=f[tmp].st;
continue;
}
if(f[i].pj){
if(f[i].st>f[i].Pst){
printf("%d ",f[i].Pid+f[i].st-f[i].Pst-1);
}
else{
printf("%d ",f[i].st++);
}continue;
}
printf("%d ",f[i].st++);
}
}
}puts("");
}
return 0;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...