QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#450625 | #8058. Binary vs Ternary | ucup-team3282 | WA | 0ms | 3632kb | C++14 | 1.5kb | 2024-06-22 16:27:32 | 2024-06-22 16:27:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn=100;
int T;
string s,t;
bool a[maxn],b[maxn];
int p[maxn];
vector <pair<int,int> > op;
int main(){
ios::sync_with_stdio(0);
cin>>T;
while(T--){
cin>>s>>t;
if(s==t){
cout<<0<<endl;
continue;
}
if(s=="1"||t=="1"){
cout<<-1<<endl;
continue;
}
int n=s.size();
for(int i=1;i<=n;i++)
a[i]=s[i-1]-'0';
int m=t.size();
for(int i=1;i<=m;i++)
b[i]=t[i-1]-'0';
for(int i=1;i<n;i++){
if(a[i+1]==0){
op.push_back({i,i+1});
a[i]=1;
}
}
for(int i=n-2;i>0;i--){
op.push_back({i,i+1});
n++;
}
op.push_back({2,n});
n=2;
int c=0;
for(int i=1;i<=m;i++)
p[i]=0;
for(int i=1;i<=m;i++){
if(b[i]==0){
for(int j=i;;j++){
if(j==m+1||b[j]!=0){
c+=(j-i+1)/2;
p[i]=j-1;
i=j-1;
break;
}
}
}
else
c++;
}
for(int i=1;i+2<=c;i++){
op.push_back({i,i+1});
op.push_back({i,i+1});
op.push_back({i+1,i+2});
a[i+2]=1;
}
n=c;
for(int i=1;i<m;i++){
if(p[i+1]!=0){
int cnt=p[i+1]-(i+1)+1;
if(cnt%2==0){
for(int j=i+cnt/2-1;j>=i;j--)
op.push_back({j,j+1});
}
else{
op.push_back({i+(cnt+1)/2-1,i+(cnt+1)/2});
op.push_back({i+(cnt+1)/2,i+(cnt+1)/2+1});
for(int j=i+(cnt+1)/2-2;j>=i;j--)
op.push_back({j,j+1});
}
}
}
cout<<op.size()<<endl;
for(auto tmp:op){
cout<<tmp.first<<' '<<tmp.second<<endl;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3632kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 28 2 3 5 6 4 5 3 4 2 3 1 2 2 10 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 5 4 5 4 5 5 6 5 6 5 6 6 7 2 3 3 4 4 5 5 6 6 7 7 8 43 2 3 5 6 4 5 3 4 2 3 1 2 2 10 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 5 4 5 4 5 5 6 5 6 5 6 6 7 2 3 3 4 4 5 5 6 6 7 7 8 2 3 1 2 2 6 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 5 4 5 4 5 5 6
result:
wrong answer (l,r) is invalid (test case 3)