QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355093 | #8058. Binary vs Ternary | foreverlasting# | WA | 1ms | 3668kb | C++20 | 3.0kb | 2024-03-16 12:54:54 | 2024-03-16 12:54:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ld = long double;
using Pair = std::pair<int, ld>;
#define pii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
#define eb emplace_back
#define ppb pop_back
#define inf 1'000'000'000
void solve(const int &Case) {
string s1, s2;
cin >> s1 >> s2;
if (s1 == s2) {
cout << "0\n";
return;
}
if (s1 == "1") {
cout << "-1\n";
return;
}
vector<pii> ans;
int numb=0;
for(auto c:s2)
if(c=='1')
numb++;
{
string s3;int L=s1.size();
for(int i=0;i<L;++i) {
if (s1[i] == '1') s3 += "1";
else
{
int j=i;
for(;j<L&&s1[j]=='0';++j);
int p=s3.size()+1,k=j-i;
if(j==L)
{
ans.eb(p,p+k-1);
ans.eb(p-1,p);
s3+="1";
}
else
{
ans.eb(p,p+k);
s3+="1";
}
i=j;
}
}
s1=s3;
}
while((int)s1.size()<numb)
{
int L=s1.size();
ans.eb(L-1,L);
ans.eb(L-1,L);
ans.eb(L,L+1);
s1+="1";
}
if(numb==1)
{
int L=s1.size();
for(int i=L-1;i;--i) ans.eb(i,i+1);
L=L*2-1;
if(L>(int)s2.size()) ans.eb((int)s2.size(),L);
else
{
while(L<(int)s2.size())
{
ans.eb(1,2);
ans.eb(1,2);
++L;
}
}
}
else {
while ((int) s1.size() > numb) {
int L=s1.size();
ans.eb(L-1,L);
ans.eb(L-2,L-1);
ans.eb(L-1,L+2);
ans.eb(L-2,L-1);
s1.ppb();
}
s1=" "+s1;
s2=" "+s2;
int n=s1.size(),m=s2.size();
for(;n>1;--n,--m,s1.ppb())
{
if(s2[m]=='1') continue;
while(s2[m]=='0') {
ans.eb(n - 1, n);
ans.eb(n - 1, n);
--m;
}
}
if(m!=1)
{
ans.eb(1,2);
ans.eb(1,2);
ans.eb(2,3);
ans.eb(1,2);
if(m==2)
{
ans.eb(2,3);
}
else
{
m-=2;
while(m>1)
{
ans.eb(1,2);
ans.eb(1,2);
--m;
}
}
}
}
cout<<ans.size()<<'\n';
for(auto [l,r]:ans) cout<<l<<' '<<r<<'\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int T = 1;
std::cin >> T;
for (int Case = 1; Case <= T; Case++)solve(Case);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 13 3 4 5 5 4 5 4 5 3 4 4 7 3 4 3 4 3 4 2 3 2 3 1 2 1 2 6 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: 1ms
memory: 3668kb
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 4 5 3 4 3 4 2 3 3 6 2 3 -1 3 2 5 1 2 2 3 4 2 3 2 3 2 3 3 4 7 2 2 1 2 1 2 1 2 2 3 2 3 2 3 6 3 4 2 3 2 3 1 2 2 5 1 2 11 3 4 4 4 3 4 3 4 2 3 3 6 2 3 2 3 1 2 2 5 1 2 6 3 3 2 3 2 3 1 2 2 5 1 2 -1 7 2 3 4 4 3 4 3 4 2 3 1 2 2 7 11 2 2 1 2 1 2 1 2 2 3 2 3 2 3 3 4 3 4 3 4 4 5 6 2 5 1 2 1 2 1 2 2 3 1 2 4 2 ...
result:
wrong answer S!=T after all operations (test case 13)