QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#712207 | #8058. Binary vs Ternary | acwing_gza# | WA | 1ms | 3820kb | C++20 | 1.7kb | 2024-11-05 14:55:11 | 2024-11-05 14:55:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef ll i64;
typedef __int128 i128;
constexpr int maxn=5e5+9;
string a,b;
int n,m;
void solve()
{
vector<pii> ans;
cin>>a>>b;
n=a.length();
m=b.length();
if(a==b)
{
puts("0");
return;
}
if(n==1) { puts("-1"); return; }
a="@"+a; b="@"+b;
int tot=0;
int last1=-1,sum1=0;
for(int i=n;i;--i)
{
if(a[i]=='0')
if(last1==-1) ++tot;
else ;
else
{
if(last1!=-1 && last1!=i+1)
ans.push_back({i+1,last1});
last1=i; ++sum1;
}
}
if(last1>1) ans.push_back({1,last1});
// ans.push_back({sum1+1,sum1+tot});
// 111..100...0
for(int i=0;i<tot;++i) ans.push_back({sum1+i,sum1+i+1});
// 111........1
sum1+=tot;
// to length m
while(sum1>m)
{
--sum1;
ans.push_back({1,2});
ans.push_back({2,4});
} // what if sum1<4 a.k.a. sum1==3
// 111 -> 1001 -> 11 thats ok
if(sum1<m)
{
ans.push_back({1,2});
ans.push_back({1,3});
while(sum1<m)
{
++sum1;
ans.push_back({1,3});
}
ans.push_back({2,4});
}
for(int i=m;i;--i)
if(b[i]=='0')
{
ans.push_back({i-1,i});
ans.push_back({i,i+1});
}
printf("%d\n",ans.size());
for(auto[l,r]:ans) printf("%d %d\n",l,r);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 13 3 4 4 5 1 2 1 3 1 3 1 3 2 4 6 7 7 8 4 5 5 6 2 3 3 4 5 1 2 1 3 1 3 1 3 2 4
result:
ok Haitang Suki (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3748kb
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:
6 3 4 4 5 1 2 2 4 1 2 2 4 -1 3 2 5 1 2 2 3 5 2 3 1 2 1 3 1 3 2 4 8 1 2 1 2 1 3 1 3 1 3 2 4 3 4 4 5 6 2 3 3 4 1 2 2 4 1 2 2 4 6 3 4 3 4 1 2 2 4 1 2 2 4 3 2 3 1 2 2 4 -1 8 2 3 3 4 1 2 2 4 1 2 2 4 1 2 2 3 7 1 2 1 2 1 3 1 3 1 3 1 3 2 4 10 1 2 2 3 3 4 4 5 1 2 2 4 2 3 3 4 1 2 2 3 3 1 2 1 2 2 4 8 1 2 1 3 1...
result:
wrong answer (l,r) is invalid (test case 13)