QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#678494 | #8058. Binary vs Ternary | TokaiZaopen# | WA | 1ms | 3552kb | C++20 | 2.3kb | 2024-10-26 15:08:14 | 2024-10-26 15:08:41 |
Judging History
answer
#include <bits/stdc++.h>
#define int ll
using ll = long long;
// #define MING_LE
using namespace std;
string a, b;
void solve();
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int __ = 1;
cin >> __;
while (__--)
solve();
return 0;
}
void solve()
{
cin >> a >> b;
if (a == "1")
{
if (b != "1")
cout << "-1\n";
else
cout << "0\n";
return;
}
if (b == "1" && a.size() > 1)
{
cout << "-1\n";
return;
}
vector<pair<int, int>> ans;
while (a != "10")
{
#ifdef MING_LE
cout << a << '\n';
#endif
int st = -1;
for (int i = 0; i < (int)a.size() - 1; i++)
{
if (a[i] == '1' && a[i + 1] == '1')
{
ans.emplace_back(i + 1, i + 2);
a[i + 1] = '0';
a.insert(a.begin() + i + 1, '0');
st = i + 1;
break;
}
}
if (st < 0)
break;
bool flag = 0;
for (int j = st; j < a.size(); j++)
{
if (a[j] == '1')
{
flag = 1;
ans.emplace_back(st + 1, j + 1);
string buffer = a;
a = buffer.substr(0, st) + "1";
if (j + 1 < buffer.size())
a = a + buffer.substr(j + 1, buffer.size() - (j + 1));
break;
}
}
if (!flag)
{
ans.emplace_back(st + 1, a.size());
a = a.substr(0, st) + "0";
}
}
if (a != "10")
ans.emplace_back(2, a.size());
for (int i = b.size() - 1; i >= 2; i--)
{
if (b[i] == '1')
{
ans.emplace_back(1, 2);
ans.emplace_back(1, 2);
ans.emplace_back(1, 3);
ans.emplace_back(2, 3);
}
else
{
ans.emplace_back(1, 2);
ans.emplace_back(1, 2);
}
}
if (b[1] == '1')
ans.emplace_back(1, 2);
cout << ans.size() << '\n';
for (auto it : ans)
cout << it.first << " " << it.second << '\n';
}
/*
3
1
111
110110
1101010
1111
111111
*/
/*
1
110110
1101010
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 21 1 2 2 5 1 2 2 4 1 2 2 4 1 2 1 2 1 2 1 2 1 3 2 3 1 2 1 2 1 2 1 2 1 3 2 3 1 2 1 2 1 2 23 1 2 2 4 1 2 2 4 1 2 2 3 1 2 1 2 1 3 2 3 1 2 1 2 1 3 2 3 1 2 1 2 1 3 2 3 1 2 1 2 1 3 2 3 1 2
result:
ok Haitang Suki (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3552kb
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:
9 1 2 2 4 1 2 2 5 1 2 1 2 1 3 2 3 1 2 -1 1 2 5 12 3 4 4 5 2 4 1 2 1 2 1 3 2 3 1 2 1 2 1 3 2 3 1 2 7 1 2 1 2 1 2 1 2 1 3 2 3 1 2 3 1 2 2 5 1 2 5 1 2 2 5 1 2 2 4 1 2 3 1 2 2 4 1 2 -1 3 3 4 4 6 2 4 13 1 2 1 2 1 3 2 3 1 2 1 2 1 3 2 3 1 2 1 2 1 3 2 3 1 2 7 2 5 1 2 1 2 1 3 2 3 1 2 1 2 -1 14 1 2 2 3 1 2 1 ...
result:
wrong answer S!=T after all operations (test case 3)