QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#739869 | #8058. Binary vs Ternary | UESTC_NLNS# | WA | 0ms | 3628kb | C++20 | 2.3kb | 2024-11-12 23:35:11 | 2024-11-12 23:35:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
};
int T,n,m,n1,n2;
string a,b,one="1";
vector<node> ans;
vector<int> p;
bool havezero(string s)
{
int len=s.size();
for(int i=0;i<len;i++) if(s[i]=='0') return true;
return false;
}
string deletezero(string s)
{
int len=s.size();string res="";
for(int i=0,j;i<len;i++)
{
if(s[i]=='0')
{
for(j=i+1;j<len&&s[j]=='0';j++);
if(j==len)
{
ans.push_back({i,j-1});
ans.push_back({i-1,i});
for(int k=0;k<i;k++) res+="1";
}
else
{
ans.push_back({i,j});
for(int k=0;k<i;k++) res+="1";
for(int k=j;k<len;k++) res+=s[k];
}
return res;
}
}
}
string addone(string s)
{
ans.push_back({0,1});
ans.push_back({0,1});
ans.push_back({1,2});
return s+"1";
}
string delone(string s)
{
ans.push_back({0,1});
ans.push_back({1,3});
s.pop_back();
return s;
}
void addzerotofront()
{
ans.push_back({0,1});
ans.push_back({0,1});
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--)
{
cin>>b>>a;n1=0;
n=a.size();m=b.size();p.clear();ans.clear();
if(a==one&&b==one) {cout<<"0\n";continue;}
else if(a==one||b==one) {cout<<"-1\n";continue;}
for(int i=0,j;i<n;)
{
n1++;
for(i++,j=0;i<n&&a[i]=='0';i++,j++);
p.push_back(j);
}
while(havezero(b)) b=deletezero(b);
m=n2=b.size();
if(n1==1)
{
while(n2>2) b=delone(b),n2--;
if(p[0]==1)
{
ans.push_back({0,1});
ans.push_back({1,2});
}
else
{
ans.push_back({0,1});
for(int i=2;i<p[0];i++) addzerotofront();
}
}
else
{
while(n1>n2) b=addone(b),n2++;
while(n1<n2) b=delone(b),n2--;
for(int i=n1-1;i>=1;i--)
{
if(!p[i]) continue;
ans.push_back({i-1,i});
for(int j=2;j<p[i]+1;j++)
{
ans.push_back({i-1,i});
ans.push_back({i-1,i});
}
ans.push_back({i-1,i});
}
if(p[0])
{
ans.push_back({0,1});
ans.push_back({0,2});
if(p[0]==1) ans.push_back({1,2});
else
{
for(int i=2;i<p[0];i++) addzerotofront();
}
}
}
cout<<ans.size()<<"\n";
for(auto i:ans) cout<<i.x+1<<" "<<i.y+1<<"\n";
}
return 0;
}
/*
3
1
111
110110
1101010
1111
111111
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 9 3 4 5 5 4 5 3 4 3 4 2 3 2 3 1 2 1 2 6 1 2 1 2 2 3 1 2 1 2 2 3
result:
wrong answer S!=T after all operations (test case 2)