今天的ARC B,第一个代码RE,第二个AC,出问题的临界数据是 n≥17,关键是本机没问题,AT costom test 出问题。
#include<bits/stdc++.h>
using namespace std;
int n,cnt=0,ct=0,a[50];
string t,tt;
char s[100005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
cin>>t;
for(int i=0;i<n;i++)tt[i]='0';
for(int i=0;i<n;i++)
{
if(t[i]=='1')a[++ct]=i;
}
for(int i=ct;i>=1;i--)
{
//cout<<a[i]<<"\n";
for(int j=0;j<=a[i];j++)
{
if(tt[j]=='0')
{
tt[j]='1';
cnt++;
s[cnt]='A';
}
}
for(int j=0;j<a[i];j++)
{
if(tt[j]=='1')
{
tt[j]='0';
cnt++;
s[cnt]='B';
}
}
}
cout<<cnt<<"\n";
for(int i=1;i<=cnt;i++)cout<<s[i];
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int n,cnt=0,ct=0,a[50]={0};
string t;
char tt[100005],s[100005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
cin>>t;
for(int i=0;i<n;i++)tt[i]='0';
for(int i=0;i<n;i++)
{
if(t[i]=='1')a[++ct]=i;
}
for(int i=ct;i>=1;i--)
{
//cout<<a[i]<<"\n";
for(int j=0;j<=a[i];j++)
{
if(tt[j]=='0')
{
tt[j]='1';
cnt++;
s[cnt]='A';
}
}
for(int j=0;j<a[i];j++)
{
if(tt[j]=='1')
{
tt[j]='0';
cnt++;
s[cnt]='B';
}
}
}
cout<<cnt<<"\n";
for(int i=1;i<=cnt;i++)cout<<s[i];
return 0;
}