QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#653960 | #8058. Binary vs Ternary | Tggdb# | WA | 0ms | 3636kb | C++20 | 2.3kb | 2024-10-18 20:54:18 | 2024-10-18 20:54:23 |
Judging History
answer
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define inf 0X7fffffff
using namespace std;
const int N=1e4+9;
int read(int &x){
int dat=0,oko=1;char chc=getchar();
while(chc<'0'||chc>'9'){if(chc=='-')oko=-1;chc=getchar();}
while(chc>='0'&&chc<='9'){dat=dat*10+chc-'0';chc=getchar();}
x=dat*oko;return x;
}int T,need,la[N],ra[N],lb[N],rb[N],tota,totb;
int dela,delb,lena,lenb;
string s1,s2;
void solve(){
cin>>s1>>s2;
tota=0,totb=0;
dela=0,delb=0;
lena=0,lenb=0;
int last=0;need=s2.length();
if(s2=="1"&&s1!="1"){
cout<<"-1\n";return;
}if(s2!="1"&&s1=="1"){
cout<<"-1\n";return;
}for(int i=1;i<=s1.length();i++){
if(s1[i-1]=='1'){
lena++;
if(!last)continue;
tota++;
la[tota]=last-dela;
ra[tota]=i-dela;
dela+=i-last;
last=0;
}else if(!last)last=i;
}
if(last&&s1.length()-last>0){
//cout<<"FLKAJ\n";
tota++;
la[tota]=lena+1;
ra[tota]=lena+1+s1.length()-last;
}if(last){
tota++;
la[tota]=lena;
ra[tota]=lena+1;lena++;
}if(lena==1){cout<<"-1\n";return;}
while(lena>need){
tota++;
la[tota]=lena-2;
ra[tota]=lena-1;
tota++;
la[tota]=lena-1;
ra[tota]=lena+1;
lena--;
}//cout<<"lena="<<lena<<"\n";
while(lena<need){
tota++;
la[tota]=lena-1;
ra[tota]=lena;
tota++;
la[tota]=lena-1;
ra[tota]=lena;
tota++;
la[tota]=lena-1;
ra[tota]=lena+1;
tota++;
la[tota]=lena-1;
ra[tota]=lena;
tota++;
la[tota]=lena+1;
ra[tota]=lena+2;
lena++;
}for(int i=s2.length();i>=1;i--){
if(s2[i-1]=='1')continue;
tota++;
la[tota]=i-1;
ra[tota]=i;
//printf("ff %d %d\n",i-1,i);
tota++;
la[tota]=i;
ra[tota]=i+1;
//printf("ff %d %d\n",i,i+1);
}cout<<tota<<"\n";
for(int i=1;i<=tota;i++){
cout<<la[i]<<" "<<ra[i]<<"\n";
}
}
int main(){
cin>>T;
while(T--)solve();
return 0;
}
/*
1
111111
1111
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3636kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 18 3 4 4 5 4 5 4 5 4 6 4 5 6 7 5 6 5 6 5 7 5 6 7 8 6 7 7 8 4 5 5 6 2 3 3 4 10 3 4 3 4 3 5 3 4 5 6 4 5 4 5 4 6 4 5 6 7
result:
wrong answer (l,r) is invalid (test case 2)