QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707866 | #8058. Binary vs Ternary | Wolam# | WA | 0ms | 3688kb | C++17 | 2.7kb | 2024-11-03 17:54:13 | 2024-11-03 17:54:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > ans;
char a[205],b[205];
int la,lb;
bool cmp()
{
if(la!=lb)
return 0;
for(int i=1;i<=la;i++)
if(a[i]!=b[i])return 0;
return 1;
}
void o(int l,int r)
{
assert(r<=la&&l>=1);
ans.push_back(make_pair(l,r));
}
void del(int x)
{
for(int i=x;i<la;i++)
a[i]=a[i+1];
la--;
}
void ins(int x,char c)
{
for(int i=la;i>=x;i--)
a[i+1]=a[i];
la++;
a[x]=c;
}
void del0_01(int x)
{
o(x,x+1);
del(x);
}
void del1_11(int x)
{
o(x,x+1);
o(x+1,x+3);
del(x);
}
void upd0_10(int x)
{
o(x,x+1);
a[x+1]='1';
}
void ins0_11(int x)
{
o(x,x+1);
o(x,x+2);
o(x+1,x+2);
ins(x+1,'0');
}
void ins0_10(int x)
{
o(x,x+1);
o(x,x+1);
ins(x+1,'0');
}
void ins1_11(int x)
{
o(x,x+1);
o(x,x+1);
o(x+1,x+2);
ins(x+1,'1');
}
void sol()
{
ans.clear();
scanf("%s%s",a+1,b+1);
la=strlen(a+1);
lb=strlen(b+1);
if(cmp())
{
cout<<0<<'\n';
return;
}
else if(la==1||lb==1)
{
cout<<-1<<'\n';
return;
}
int cnt=0;
for(int i=1;i<=lb;i++)
{
if(b[i]=='1')
cnt++;
}
if(a[la]=='0')
{
int l=la;
while(a[l]=='0')l--;
if(l+1!=la)
{
o(l+1,la);
la=l+1;
}
upd0_10(la-1);
}
for(int i=1;i<=la;i++)
{
while(a[la-i+1]=='0')
{
del0_01(la-i+1);
}
}
while(la<cnt+1)
{
ins1_11(1);
}
while(la>cnt+1)
{
del1_11(1);
}
for(int l,r=lb,now=la-1;r>=1;r=l-1,now--)
{
l=r;
while(b[l]=='0')
l--;
int len=r-l;
if(r==lb)
{
if(len==0)
{
del1_11(1);
}
else
{
o(now,now+1);
o(now+1,now+2);
a[now+1]='0';
for(int i=1;i<=len-1;i++)
ins0_10(now);
}
}
else
{
if(len!=0)
{
ins0_11(now);
for(int i=1;i<=len-1;i++)
ins0_10(now);
}
}
}
assert(ans.size()<=512);
assert(cmp());
cout<<ans.size()<<'\n';
for(auto it:ans)
{
cout<<it.first<<" "<<it.second<<'\n';
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
while(t--)
{
sol();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3688kb
input:
3 1 111 110110 1101010 1111 111111
output:
0 0 0
result:
wrong answer S!=T after all operations (test case 1)