社区讨论
15分求调
P8866[NOIP2022] 喵了个喵参与者 2已保存回复 12
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 12 条
- 当前快照
- 1 份
- 快照标识符
- @m0225ota
- 此快照首次捕获于
- 2024/08/20 14:42 2 年前
- 此快照最后确认于
- 2025/11/05 00:40 4 个月前
代码:
CPP#include<bits/stdc++.h>
using namespace std;
int n,m,k,A[2000005],instk[1001],down[601],up[601];
deque<int>q[10001];
inline string str(int x)
{
string ans="";
while(x)
{
ans=" "+ans;
ans[0]=x%10+'0';
x/=10;
}
return ans;
}
inline void solve()
{
for(int i = 1;i <=1000;i++)instk[i]=0;
scanf("%d %d %d",&n,&m,&k);
for(int i = 1;i <=m;i++)scanf("%d",&A[i]);
int steps=0;string ans="\n";
for(int i = 1;i <=n;i++)while(q[i].size())q[i].pop_front();
for(int asdf = 1;asdf <=m;asdf++)
{
int cur=A[asdf],emptystack,num=0,slv=false;
/*if(asdf!=m&&cur==A[asdf+1])
{
ans+="1 1\n1 1\n";
steps+=2;
asdf++;
continue;
}*/
for(int j = 1;j <=n;j++)
if(!q[j].size())
{
emptystack=j;
num++;
if(num>=2)break;
}
for(int j = 1;j <=n;j++)
if(q[j].size()&&q[j].front()==cur)
{
slv=true;
steps+=2;
ans+="1 "+str(emptystack)+"\n2 "+str(j)+" "+str(emptystack)+"\n";
instk[cur]=0;
q[j].pop_front();
break;
}
else if(q[j].size()&&q[j].back()==cur)
{
steps++;
slv=true;
ans+="1 "+str(j)+"\n";
instk[cur]=0;
q[j].pop_back();
break;
}
else;
if(slv)continue;
if(num>=2)
{
ans+="1 "+str(emptystack)+"\n";
q[emptystack].push_back(cur);
instk[cur]=1;
steps++;
continue;
}
for(int j = 1;j <=n;j++)
if(q[j].size()==1)
{
ans+="1 "+str(j)+"\n";
steps++;
slv=true;
instk[cur]=1;
q[j].push_back(cur);
break;
}
if(slv)continue;
int j;
for(int i = 1;i <=k;i++)down[i]=0,up[i]=0;
for(int i = 1;i <=n;i++)
if(q[i].size())
down[q[i].front()]=i,up[q[i].back()]=i;
for(j = asdf+1;j<=n;j++)if(down[j])break;
bool tag=false;
for(int i = asdf+1;i<j;i++)
if(q[up[A[i]]].front()==A[j])
{
tag=true;
break;
}
if(tag)
{
steps++;
ans+="1 "+str(emptystack)+"\n";
q[emptystack].push_back(cur);
instk[cur]=1;
for(int i = asdf+1;i<j;i++)
{
steps++;
ans+="1 "+str(up[A[i]])+"\n";
instk[q[up[A[i]]].back()]=0;
q[up[A[i]]].pop_back();
}
steps++;
ans+="1 "+str(down[A[j]])+"\n";
instk[q[down[A[j]]].front()]=0;
q[down[A[j]]].pop_front();
}
else
{
steps++;
ans+="1 "+str(down[A[j]])+"\n";
q[down[A[j]]].push_back(A[asdf]);
instk[A[asdf]]=1;
for(int i = asdf+1;i<j;i++)
{
steps++;
ans+="1 "+str(up[A[i]])+"\n";
instk[q[up[A[i]]].back()]=0;
q[up[A[i]]].pop_back();
}
steps+=2;
ans+="1 "+str(emptystack)+"\n2 "+str(emptystack)+" "+str(down[A[j]])+"\n";
instk[q[down[A[j]]].front()]=0;
q[down[A[j]]].pop_front();
}
asdf=j;
}
printf("%d",steps);
for(int i = 0;i <ans.size();i++)putchar(ans[i]);
return;
}
int main()
{
int T;cin>>T;
while(T--)solve();
}
代码复杂度为 ,官方数据中会 T 一个点,但有很多 WA,只过了 ,悬关求调
回复
共 12 条回复,欢迎继续交流。
正在加载回复...