QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#678291 | #8058. Binary vs Ternary | TokaiZaopen# | WA | 0ms | 3540kb | C++20 | 1.9kb | 2024-10-26 14:34:16 | 2024-10-26 14:34:18 |
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;
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;
}
}
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 (b != "10")
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
*/
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3540kb
input:
3 1 111 110110 1101010 1111 111111
output:
-1 7 1 2 2 5 1 2 2 4 1 2 2 4 1 2 7 1 2 2 4 1 2 2 4 1 2 2 3 1 2
result:
wrong answer S!=T after all operations (test case 2)