QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#438743 | #8058. Binary vs Ternary | stasio6# | WA | 3ms | 3692kb | C++14 | 1.7kb | 2024-06-11 03:38:35 | 2024-06-11 03:38:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i,a,b) for(int i = a; i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FS first
#define SD second
template<class A, class B> void cmx(A& x, B y) {x=max<A>(x, y);}
template<class A, class B> void cmn(A& x, B y) {x=min<A>(x, y);}
typedef pair<int, int> pii;
typedef vector<int> vi;
int _,n,m,a[200],b[200],E,A[200],B[200];
string s,t;
void O(int l,int r){
A[++E]=l,B[E]=r;
int x=0;
for(int i=l;i<=r;i++)
x=3*x+a[i];
int q[9]={},c=0;
while(x)
q[++c]=x%2,x/=2;
if(!c)
q[++c]=0;
reverse(q+1,q+c+1);
for(int i=r+1;i<=n;i++)
a[i-(r-l+1)]=a[i];
n=n-(r-l+1);
for(int i=n;i>=l;i--)
a[i+c]=a[i];
for(int i=1;i<=c;i++)
a[l+i-1]=q[i];
n+=c;
//for(int i=1;i<=n;i++)
// cout<<a[i]<<" \n"[i==n];
}
void Z(){
cin>>s>>t,n=s.size(),m=t.size(),E=0;
if(s==t){
cout<<0<<'\n';
return;
}
if(s.size()==1||t.size()==1){
cout<<-1<<'\n';
return;
}
for(int i=1;i<=n;i++)
a[i]=s[i-1]-'0';
for(int i=1;i<=m;i++)
b[i]=t[i-1]-'0';
for(int i=1;i<=n;i++)
if(!a[i])
O(i-1,i);
O(n-1,n),O(n-1,n);
while(n>2)
O(n-2,n-1),O(n-2,n);
while(n<m)
O(n-1,n),O(n-1,n),O(n-2,n-1);
O(n-1,n);
for(int i=1;i<=m;i++)
if(!b[i])
O(i-1,i),O(i,i+1);
cout<<E<<'\n';
for(int i=1;i<=E;i++)
cout<<A[i]<<' '<<B[i]<<'\n';
}
signed main() {
//cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);
for(cin>>_;_--;)
Z();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3540kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 34 2 3 5 6 5 6 6 7 4 5 5 7 3 4 4 6 2 3 3 5 1 2 2 4 1 2 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 19 3 4 4 5 2 3 3 5 1 2 2 4 1 2 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:
ok Haitang Suki (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3692kb
input:
1000 11100 111 1 11110 10001 10 1011 1111 10 1110 1100 11 11010 11 110 11 1 10001 10110 10 10 11111 10000 1001 10 1 11 10111 11 10 1 100 11 10100 1 10 101 11 1100 110 11 1110 1 1001 1 11111 10 10010 10 11001 110 1010 10011 1110 10100 1001 1001 101 100 1 1001 11 101 11 101 1001 1 1 1011 1 10 10 1011 ...
output:
14 3 4 4 5 4 5 5 6 3 4 4 6 2 3 3 5 1 2 2 4 1 2 1 2 1 2 2 3 -1 14 1 2 2 3 3 4 4 5 5 6 3 4 4 6 2 3 3 5 1 2 2 4 1 2 1 2 2 3 14 1 2 3 4 4 5 2 3 3 5 1 2 2 4 1 2 1 2 1 2 2 3 2 3 2 3 3 4 12 1 2 1 2 2 3 1 2 1 2 1 2 2 3 2 3 2 3 3 4 3 4 4 5 9 2 3 3 4 3 4 4 5 2 3 3 5 1 2 2 4 1 2 11 2 3 4 5 4 5 5 6 3 4 4 6 2 3 ...
result:
wrong answer (l,r) is invalid (test case 12)